Skip to content

Commit

Permalink
Get array indices and hash keys really working in interpolation.
Browse files Browse the repository at this point in the history
Although this may allow more than Perl actually allows for the indices
or keys inside interpolation.  Better that than not getting enough I
think.
  • Loading branch information
drgrice1 committed Dec 3, 2024
1 parent ac3f069 commit 45ac50a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 7 additions & 12 deletions src/pg.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -308,6 +304,9 @@ List { !list "(" !listContents commaSep<expression> ")" }
ArrayRef { "[" commaSep<expression> "]" }
HashRef { ArithOp<"+">? "{" commaSep<expression> "}" }

arrayAccessor { "[" expression "]" }
hashAccessor { "{" ((!bareword Identifier) | expression) "}" }

ScalarDereference { "$" (ScalarDereference | ScalarVariable | PGVariable | "{" expression "}") }
ArrayDereference { "@" (ScalarDereference | ScalarVariable | PGVariable | "{" expression "}") }
HashDereference { "%" (ScalarDereference | ScalarVariable | PGVariable | "{" expression "}") }
Expand Down Expand Up @@ -430,18 +429,14 @@ semicolon { StatementEnd | automaticSemicolon }
afterInterpolation?
!arrayMember
(ArrowOperator !arrowOperator)?
"["
maybeParens<ArithOp<"-">? Integer | Float | ScalarVariable | PGVariable | quotedString>
"]"
arrayAccessor
}
HashAccessVariable {
(ScalarVariable | PGVariable | ArrayAccessVariable | HashAccessVariable)
afterInterpolation?
!hashMember
(ArrowOperator !arrowOperator)?
"{"
(!bareword Identifier | maybeParens<ScalarVariable | PGVariable | quotedString>)
"}"
hashAccessor
}

PodStatement { PodDirective PodContent PodCut }
Expand Down
2 changes: 1 addition & 1 deletion test/perl-heredocs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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, "]"),
Expand Down
24 changes: 15 additions & 9 deletions test/perl-quote-and-quote-like-operators.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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, "]")
),
Expand All @@ -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, "]"),
Expand All @@ -51,7 +57,7 @@ Program(
InterpolatedStringContent,
ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", ScalarVariable, "]"),
InterpolatedStringContent,
ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", "(", ScalarVariable, ")", "]")
ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", List("(", ScalarVariable, ")"), "]")
),
StatementEnd(";")
),
Expand All @@ -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(";")
),
Expand All @@ -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(";")
),
Expand Down Expand Up @@ -243,7 +249,7 @@ Program(
qq,
QuoteLikeStartDelimiter,
InterpolatedStringContent,
ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", ArithOp, Integer, "]"),
ArrayAccessVariable(ScalarVariable, ArrowOperator, "[", UnaryExpression(ArithOp, Integer), "]"),
QuoteLikeEndDelimiter
),
StatementEnd(";")
Expand Down

0 comments on commit 45ac50a

Please sign in to comment.