From 35b6dc0962004083b3fbb2af504c3b9725471d02 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Fri, 18 Oct 2024 22:29:16 -0500 Subject: [PATCH] Make sure that a pattern match does not trump a division symbol. --- package-lock.json | 4 ++-- package.json | 2 +- src/tokens.ts | 13 +++++-------- test/perl-misc.txt | 17 +++++++++++++++++ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7edc3d2..bd7eb98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@openwebwork/codemirror-lang-pg", - "version": "0.0.1-beta.7", + "version": "0.0.1-beta.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@openwebwork/codemirror-lang-pg", - "version": "0.0.1-beta.7", + "version": "0.0.1-beta.9", "license": "MIT", "dependencies": { "@codemirror/language": "^6.10.2", diff --git a/package.json b/package.json index 756c6e9..2a9802f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/tokens.ts b/src/tokens.ts index 57f9450..68e42b2 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -258,12 +258,8 @@ export const contextTracker = new ContextTracker({ } 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))); @@ -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; diff --git a/test/perl-misc.txt b/test/perl-misc.txt index a474223..64ca176 100644 --- a/test/perl-misc.txt +++ b/test/perl-misc.txt @@ -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); ; ==> @@ -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(";") )