Skip to content

Commit

Permalink
Make sure that a pattern match does not trump a division symbol.
Browse files Browse the repository at this point in the history
  • Loading branch information
drgrice1 committed Oct 19, 2024
1 parent 3a7130e commit 35b6dc0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 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.8",
"version": "0.0.1-beta.9",
"description": "PG language support for CodeMirror",
"author": "The WeBWorK Project",
"license": "MIT",
Expand Down
13 changes: 5 additions & 8 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,8 @@ export const contextTracker = new ContextTracker<Context>({
}
return context;
} else if (term === patternMatchStart) {
let pos = 0;
let next;
while (isWhitespace((next = input.peek(pos)))) ++pos;
if (next == 47 /* / */) {
if (input.next == 47 /* / */)
return new Context('regex', context, stack.pos, { startDelimiter: 47, quoteLikeType: m });
}
} else if (term === BeginPG) {
let pos = -1;
while (isHWhitespace(input.peek(++pos)));
Expand Down Expand Up @@ -748,9 +744,10 @@ export const quoteLikeOperator = new ExternalTokenizer(

export const regex = new ExternalTokenizer(
(input, stack) => {
if (stack.canShift(patternMatchStart)) {
gobbleWhitespace(input);
if (input.next == 47 /* / */) input.acceptToken(patternMatchStart);
if (stack.canShift(patternMatchStart) && input.next == 47 /* / */) {
const divisionToken = stack.parser.nodeSet.types.find((t) => t.name == '/')?.id;
if (typeof divisionToken === 'number' && !stack.canShift(divisionToken))
input.acceptToken(patternMatchStart);
}

if (!(stack.context instanceof Context) || !stack.context.type.endsWith('regex')) return;
Expand Down
17 changes: 17 additions & 0 deletions test/perl-misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
my $var = { expires => time + 2, valid => 0 };
my $var = Package->method($var);
warn $_ for grep { $_ ne 'a' } @array;
my @array = (pi / 6, pi / 4, pi / 3);
;

==>
Expand Down Expand Up @@ -56,5 +57,21 @@ Program(
),
StatementEnd(";")
),
ExpressionStatement(
Assignment(
VariableDeclaration(my, ArrayVariable),
"=",
List(
"(",
BinaryExpression(Constant(Identifier), "/", Integer),
Comma,
BinaryExpression(Constant(Identifier), "/", Integer),
Comma,
BinaryExpression(Constant(Identifier), "/", Integer),
")"
)
),
StatementEnd(";")
),
EmptyStatement(";")
)

0 comments on commit 35b6dc0

Please sign in to comment.