harmonyc 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/code_generator/JavaScript.js +12 -8
- package/compiler/compiler.js +1 -1
- package/package.json +1 -1
- package/parser/lexer.steps.js +9 -0
- package/parser/lexer_rules.js +1 -1
- package/parser/parser.js +1 -1
- package/parser/parser.steps.js +12 -0
|
@@ -60,6 +60,7 @@ export class NodeTest {
|
|
|
60
60
|
}
|
|
61
61
|
errorStep(action, errorMessage) {
|
|
62
62
|
var _a;
|
|
63
|
+
this.declareFeatureVariables([action]);
|
|
63
64
|
this.tf.print(`expect(async () => {`);
|
|
64
65
|
this.tf.indent(() => {
|
|
65
66
|
action.toCode(this);
|
|
@@ -67,14 +68,7 @@ export class NodeTest {
|
|
|
67
68
|
this.tf.print(`}).rejects.toThrow(${(_a = errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.toCode(this)) !== null && _a !== void 0 ? _a : ''});`);
|
|
68
69
|
}
|
|
69
70
|
step(action, responses) {
|
|
70
|
-
|
|
71
|
-
const feature = p.feature.name;
|
|
72
|
-
let f = this.featureVars.get(feature);
|
|
73
|
-
if (!f) {
|
|
74
|
-
f = toId(feature, abbrev, this.featureVars);
|
|
75
|
-
this.tf.print(`const ${f} = new ${pascalCase(feature)}Phrases();`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
71
|
+
this.declareFeatureVariables([action, ...responses]);
|
|
78
72
|
if (responses.length === 0) {
|
|
79
73
|
action.toCode(this);
|
|
80
74
|
return;
|
|
@@ -94,6 +88,16 @@ export class NodeTest {
|
|
|
94
88
|
}
|
|
95
89
|
});
|
|
96
90
|
}
|
|
91
|
+
declareFeatureVariables(phrases) {
|
|
92
|
+
for (const p of phrases) {
|
|
93
|
+
const feature = p.feature.name;
|
|
94
|
+
let f = this.featureVars.get(feature);
|
|
95
|
+
if (!f) {
|
|
96
|
+
f = toId(feature, abbrev, this.featureVars);
|
|
97
|
+
this.tf.print(`const ${f} = new ${pascalCase(feature)}Phrases();`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
97
101
|
phrase(p) {
|
|
98
102
|
const phrasefn = this.functionName(p);
|
|
99
103
|
if (!this.phraseFns.has(phrasefn))
|
package/compiler/compiler.js
CHANGED
|
@@ -16,7 +16,7 @@ export async function compileFiles(pattern) {
|
|
|
16
16
|
console.log(`Compiled ${fns.length} file${fns.length === 1 ? '' : 's'}.`);
|
|
17
17
|
const generated = features.filter((f) => f.phrasesFileAction === 'generated');
|
|
18
18
|
if (generated.length) {
|
|
19
|
-
console.log(`Generated ${generated.length}
|
|
19
|
+
console.log(`Generated ${generated.length} phrases file${generated.length === 1 ? '' : 's'}.`);
|
|
20
20
|
}
|
|
21
21
|
return { fns, outFns: features.map((f) => f.outFile.name) };
|
|
22
22
|
}
|
package/package.json
CHANGED
package/parser/lexer_rules.js
CHANGED
|
@@ -34,7 +34,7 @@ const rules = [
|
|
|
34
34
|
[true, /^:(?=\s*(?:\n|$))/g, T.Colon],
|
|
35
35
|
[
|
|
36
36
|
true,
|
|
37
|
-
/^(?!\s|=>|!!|- |\+ |[\[\]"`|]).+?(?=[\[\]"`|]|\n|$|=>|!!|:\s*(?:\n|$)|$)/g,
|
|
37
|
+
/^(?!\s|=>|!!|- |\+ |[\[\]"`|]|:\s*(?:\n|$)).+?(?=[\[\]"`|]|\n|$|=>|!!|:\s*(?:\n|$)|$)/g,
|
|
38
38
|
T.Words,
|
|
39
39
|
],
|
|
40
40
|
[true, /^-/g, T.Minus],
|
package/parser/parser.js
CHANGED
|
@@ -25,7 +25,7 @@ export const RESPONSE = apply(PHRASE, ([parts, docstring]) => {
|
|
|
25
25
|
export const ARROW = kmid(seq(opt_sc(NEWLINES), SPACES), tok(T.ResponseArrow), SPACES);
|
|
26
26
|
export const RESPONSE_ITEM = kright(ARROW, RESPONSE);
|
|
27
27
|
export const STEP = apply(seq(ACTION, rep_sc(RESPONSE_ITEM)), ([action, responses]) => new Step(action, responses).setFork(true));
|
|
28
|
-
export const LABEL = apply(kleft(list_sc(PART, SPACES), tok(T.Colon)), (words) => new Label(words.map((w) => w.toString()).join(' ')));
|
|
28
|
+
export const LABEL = apply(kleft(list_sc(PART, SPACES), seq(tok(T.Colon), SPACES)), (words) => new Label(words.map((w) => w.toString()).join(' ')));
|
|
29
29
|
export const SECTION = apply(LABEL, (text) => new Section(text));
|
|
30
30
|
export const BRANCH = alt_sc(SECTION, STEP); // section first, to make sure there is no colon after step
|
|
31
31
|
export const DENTS = apply(opt_sc(seq(SPACES, alt_sc(tok(T.Plus), tok(T.Minus)), tok(T.Space))), (lineHead) => {
|