diff --git a/package-lock.json b/package-lock.json index c7ea0b8..3157082 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@openwebwork/codemirror-lang-pg", - "version": "0.0.1-beta.19", + "version": "0.0.1-beta.20", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@openwebwork/codemirror-lang-pg", - "version": "0.0.1-beta.19", + "version": "0.0.1-beta.20", "license": "MIT", "dependencies": { "@codemirror/language": "^6.10.2", diff --git a/package.json b/package.json index 1ce59e3..d5cc388 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@openwebwork/codemirror-lang-pg", - "version": "0.0.1-beta.19", + "version": "0.0.1-beta.20", "description": "PG language support for CodeMirror", "author": "The WeBWorK Project", "license": "MIT", diff --git a/src/pg.grammar b/src/pg.grammar index 5426464..45460eb 100644 --- a/src/pg.grammar +++ b/src/pg.grammar @@ -123,17 +123,13 @@ expression[@isGroup=Expression] { (ScalarVariable | PGVariable | expression) !arrayMember (ArrowOperator !arrowOperator)? - "[" - expression - "]" + arrayAccessor } | HashAccessVariable { (ScalarVariable | PGVariable | expression) !hashMember (ArrowOperator !arrowOperator)? - "{" - ((!bareword Identifier) | expression) - "}" + hashAccessor } | PatternMatchM | PatternMatch | @@ -308,6 +304,9 @@ List { !list "(" !listContents commaSep ")" } ArrayRef { "[" commaSep "]" } HashRef { ArithOp<"+">? "{" commaSep "}" } +arrayAccessor { "[" expression "]" } +hashAccessor { "{" ((!bareword Identifier) | expression) "}" } + ScalarDereference { "$" (ScalarDereference | ScalarVariable | PGVariable | "{" expression "}") } ArrayDereference { "@" (ScalarDereference | ScalarVariable | PGVariable | "{" expression "}") } HashDereference { "%" (ScalarDereference | ScalarVariable | PGVariable | "{" expression "}") } @@ -430,18 +429,14 @@ semicolon { StatementEnd | automaticSemicolon } afterInterpolation? !arrayMember (ArrowOperator !arrowOperator)? - "[" - maybeParens? Integer | Float | ScalarVariable | PGVariable | quotedString> - "]" + arrayAccessor } HashAccessVariable { (ScalarVariable | PGVariable | ArrayAccessVariable | HashAccessVariable) afterInterpolation? !hashMember (ArrowOperator !arrowOperator)? - "{" - (!bareword Identifier | maybeParens) - "}" + hashAccessor } PodStatement { PodDirective PodContent PodCut } diff --git a/test/perl-heredocs.txt b/test/perl-heredocs.txt index 8116996..11d0026 100644 --- a/test/perl-heredocs.txt +++ b/test/perl-heredocs.txt @@ -94,7 +94,7 @@ Program( InterpolatedStringContent, ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", Integer, "]"), InterpolatedStringContent, - ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", ArithOp, Integer, "]"), + ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", UnaryExpression(ArithOp, Integer), "]"), InterpolatedStringContent, ArrayAccessVariable( ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", Integer, "]"), diff --git a/test/perl-quote-and-quote-like-operators.txt b/test/perl-quote-and-quote-like-operators.txt index e0813b1..e4d9bfb 100644 --- a/test/perl-quote-and-quote-like-operators.txt +++ b/test/perl-quote-and-quote-like-operators.txt @@ -19,9 +19,9 @@ Program( InterpolatedStringContent, ArrayAccessVariable(ScalarVariable, "[", Integer, "]"), InterpolatedStringContent, - ArrayAccessVariable(ScalarVariable, "[", "(", ArithOp, Integer, ")", "]"), + ArrayAccessVariable(ScalarVariable, "[", List("(", UnaryExpression(ArithOp, Integer), ")"), "]"), InterpolatedStringContent, - ArrayAccessVariable(ScalarVariable, "[", "(", ScalarVariable, ")", "]"), + ArrayAccessVariable(ScalarVariable, "[", List("(", ScalarVariable, ")"), "]"), InterpolatedStringContent, ArrayAccessVariable(ScalarVariable, "[", ScalarVariable, "]") ), @@ -32,7 +32,13 @@ Program( InterpolatedStringContent, ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", Integer, "]"), InterpolatedStringContent, - ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", "(", ArithOp, Integer, ")", "]"), + ArrayAccessVariable( + ScalarVariable, + ArrowOperator, + "[", + List("(", UnaryExpression(ArithOp, Integer), ")"), + "]" + ), InterpolatedStringContent, ArrayAccessVariable( ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", Integer, "]"), @@ -51,7 +57,7 @@ Program( InterpolatedStringContent, ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", ScalarVariable, "]"), InterpolatedStringContent, - ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", "(", ScalarVariable, ")", "]") + ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", List("(", ScalarVariable, ")"), "]") ), StatementEnd(";") ), @@ -62,9 +68,9 @@ Program( InterpolatedStringContent, HashAccessVariable(ScalarVariable, "{", ScalarVariable, "}"), InterpolatedStringContent, - HashAccessVariable(ScalarVariable, "{", "(", StringSingleQuoted, ")", "}"), + HashAccessVariable(ScalarVariable, "{", List("(", StringSingleQuoted, ")"), "}"), InterpolatedStringContent, - HashAccessVariable(ScalarVariable, "{", "(", ScalarVariable, ")", "}") + HashAccessVariable(ScalarVariable, "{", List("(", ScalarVariable, ")"), "}") ), StatementEnd(";") ), @@ -90,9 +96,9 @@ Program( InterpolatedStringContent, HashAccessVariable(ScalarVariable, ArrowOperator, "{", ScalarVariable, "}"), InterpolatedStringContent, - HashAccessVariable(ScalarVariable, ArrowOperator, "{", "(", StringSingleQuoted, ")", "}"), + HashAccessVariable(ScalarVariable, ArrowOperator, "{", List("(", StringSingleQuoted, ")"), "}"), InterpolatedStringContent, - HashAccessVariable(ScalarVariable, ArrowOperator, "{", "(", ScalarVariable, ")", "}") + HashAccessVariable(ScalarVariable, ArrowOperator, "{", List("(", ScalarVariable, ")"), "}") ), StatementEnd(";") ), @@ -243,7 +249,7 @@ Program( qq, QuoteLikeStartDelimiter, InterpolatedStringContent, - ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", ArithOp, Integer, "]"), + ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", UnaryExpression(ArithOp, Integer), "]"), QuoteLikeEndDelimiter ), StatementEnd(";")