typedraft
Version:
TypeDraft is a superset of typescript with built-in support for DSL extension and literate programming.
41 lines (40 loc) • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const draft_dsl_match_1 = require("draft-dsl-match");
class InlineContext {
constructor(path) {
this.m_Path = path;
}
get m_ID() {
return Symbol();
}
get m_Code() {
return this.m_Path.node;
}
ToStatements() {
return this.m_Code.body;
}
Resolve(dsl) {
if (dsl.m_Merge) {
this.m_Path.replaceWithMultiple(dsl.Transcribe(this.ToStatements(), this.m_Path));
}
else {
this.m_Code.body = dsl.Transcribe(this.ToStatements(), this.m_Path);
}
}
GetDSLName() {
const statement = this.m_Path.node.body[0];
return draft_dsl_match_1.MatchDSL(statement).with({
expression: {
type: "StringLiteral",
value: draft_dsl_match_1.use("text")
}
}, (_, { text }) => {
const [use, dsl_name] = text.trim().split(" ");
return dsl_name;
}).with(draft_dsl_match_1.__, () => {
return "";
}).run();
}
}
exports.InlineContext = InlineContext;