Fix ! parsing in automator scripts

This commit is contained in:
SpectralFlame 2023-07-19 19:34:36 -05:00 committed by cyip92
parent a56ebc7762
commit 8a69c2bc32
4 changed files with 10 additions and 5 deletions

View File

@ -98,9 +98,10 @@ CodeMirror.defineSimpleMode("automato", {
{ regex: /(antimatter|infinity|time)(?=[\s,|]|$)/ui, token: "number" },
{ regex: /(active|passive|idle)(?=[\s,|]|$)/ui, token: "number" },
{ regex: /(light|dark)(?=[\s,|]|$)/ui, token: "number" },
{ regex: /([1-9][0-9]+)(?=[\s,|-]|$)/ui, token: "number" },
{ regex: /([1-9][0-9]+)(?=[\s,!|-]|$)/ui, token: "number" },
{ regex: /[a-zA-Z_][a-zA-Z_0-9]*/u, token: "variable", next: "commandDone" },
{ regex: /([1-9]|1[0-2])$/ui, token: "number" },
{ regex: /!$/ui, token: "variable-2" },
{ regex: /([1-9]|1[0-2])(?=!|$)/ui, token: "number" },
],
studiesLoad: [
commentRule,

View File

@ -322,7 +322,8 @@ class Validator extends BaseVisitor {
ctx.$cached = {
normal: studiesOut,
image: this.rawText.substr(positionRange.startOffset, positionRange.endOffset - positionRange.startOffset + 1),
ec: 0
ec: 0,
startEC: false,
};
if (ctx.ECNumber) {
if (ctx.ECNumber.isInsertedInRecovery) {
@ -336,6 +337,7 @@ class Validator extends BaseVisitor {
}
ctx.$cached.ec = ecNumber;
}
if (ctx.Exclamation) ctx.$cached.startEC = true;
return ctx.$cached;
}

View File

@ -354,12 +354,13 @@ const RCurly = createToken({ name: "RCurly", pattern: /[ \t]*}/ });
const Comma = createToken({ name: "Comma", pattern: /,/ });
const Pipe = createToken({ name: "Pipe", pattern: /\|/, label: "|" });
const Dash = createToken({ name: "Dash", pattern: /-/, label: "-" });
const Exclamation = createToken({ name: "Exclamation", pattern: /!/, label: "!" });
// The order here is the order the lexer looks for tokens in.
export const automatorTokens = [
HSpace, StringLiteral, StringLiteralSingleQuote, Comment, EOL,
ComparisonOperator, ...tokenLists.ComparisonOperator,
LCurly, RCurly, Comma, EqualSign, Pipe, Dash,
LCurly, RCurly, Comma, EqualSign, Pipe, Dash, Exclamation,
BlackHoleStr, NumberLiteral,
AutomatorCurrency, ...tokenLists.AutomatorCurrency,
ECLiteral,

View File

@ -89,10 +89,11 @@ class AutomatorParser extends Parser {
$.RULE("studyList", () => {
$.AT_LEAST_ONE(() => $.SUBRULE($.studyListEntry));
// Support the |3 export format for EC number
// Support the |3 export format for EC number and optionally the ending exclamation point
$.OPTION(() => {
$.CONSUME(T.Pipe);
$.CONSUME1(T.NumberLiteral, { LABEL: "ECNumber" });
$.OPTION1(() => $.CONSUME(T.Exclamation));
});
}, { resyncEnabled: false });