From fe6ff49ee8718404480bfff46aa23b152d1e81e1 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Fri, 13 Jan 2023 01:36:12 -0500 Subject: [PATCH] Fix operator_identifier Problem ------- 1. Currently `//` ends up matching `operator_identier` 2. There's also a bug in regex. Solution -------- 1. Implement a workaround to avoid `//`. 2. Escape `-`, copying from the identifier regex. --- corpus/definitions.txt | 33 +++++++++++++++++---------------- grammar.js | 23 ++++++++++++++++++++++- script/smoke_test.sh | 2 +- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/corpus/definitions.txt b/corpus/definitions.txt index a66cf30d1..e9d91ea40 100644 --- a/corpus/definitions.txt +++ b/corpus/definitions.txt @@ -58,6 +58,11 @@ def → = ??? val test = id.## +val x = y +///////// +// avoid matching slashes as operator +///////// + --- (compilation_unit @@ -66,21 +71,13 @@ val test = id.## (type_parameters (covariant_type_parameter (identifier))) - (infix_type - (stable_type_identifier - (stable_identifier - (identifier) - (identifier)) + (generic_type + (stable_type_identifier (stable_identifier (stable_identifier (identifier) (identifier)) (identifier)) (type_identifier)) - (operator_identifier) - (generic_type - (type_identifier - (MISSING _alpha_identifier)) - (type_arguments - (type_identifier))))) + (type_arguments (type_identifier)))) (val_definition (operator_identifier) - (postfix_expression + (field_expression (field_expression (field_expression (identifier) @@ -89,14 +86,14 @@ val test = id.## (operator_identifier))) (val_definition (operator_identifier) - (postfix_expression + (field_expression (field_expression (identifier) (identifier)) (operator_identifier))) (val_definition (operator_identifier) - (postfix_expression + (field_expression (field_expression (identifier) (identifier)) @@ -104,9 +101,13 @@ val test = id.## (function_definition (operator_identifier) (operator_identifier)) (val_definition (identifier) - (postfix_expression + (field_expression (identifier) - (operator_identifier)))) + (operator_identifier))) + (val_definition (identifier) (identifier)) + (comment) + (comment) + (comment)) ================================ Package diff --git a/grammar.js b/grammar.js index d548f11a4..741413b32 100644 --- a/grammar.js +++ b/grammar.js @@ -1165,7 +1165,28 @@ module.exports = grammar({ wildcard: $ => '_', - operator_identifier: $ => /[!#%&*+-\/:<=>?@'^\|‘~\p{Sm}\p{So}]+/, + /** + * Regex patterns created to avoid matching // comments. + * This could technically match illeagal tokens such as val ?// = 1 + */ + operator_identifier: $ => token(choice( + // single opchar + /[\-!#%&*+\/\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/, + seq( + // opchar minus slash + /[\-!#%&*+\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/, + // opchar* + repeat1(/[\-!#%&*+\/\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/), + ), + seq( + // opchar + /[\-!#%&*+\/\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/, + // opchar minus slash + /[\-!#%&*+\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/, + // opchar* + repeat(/[\-!#%&*+\/\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/), + ), + )), _non_null_literal: $ => choice( diff --git a/script/smoke_test.sh b/script/smoke_test.sh index 5b372cd49..ae7b72a52 100755 --- a/script/smoke_test.sh +++ b/script/smoke_test.sh @@ -4,7 +4,7 @@ SCALA_SCALA_LIBRARY_EXPECTED=100 SCALA_SCALA_COMPILER_EXPECTED=66 -DOTTY_COMPILER_EXPECTED=74 +DOTTY_COMPILER_EXPECTED=66 if [ ! -d "$SCALA_SCALA_DIR" ]; then echo "\$SCALA_SCALA_DIR must be set"