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.
pull/481/head
Eugene Yokota 2023-01-13 01:36:12 +07:00
parent c110fbaece
commit fe6ff49ee8
3 changed files with 40 additions and 18 deletions

@ -58,6 +58,11 @@ def → = ???
val test = id.## val test = id.##
val x = y
/////////
// avoid matching slashes as operator
/////////
--- ---
(compilation_unit (compilation_unit
@ -66,21 +71,13 @@ val test = id.##
(type_parameters (type_parameters
(covariant_type_parameter (covariant_type_parameter
(identifier))) (identifier)))
(infix_type (generic_type
(stable_type_identifier (stable_type_identifier (stable_identifier (stable_identifier (identifier) (identifier)) (identifier))
(stable_identifier
(identifier)
(identifier))
(type_identifier)) (type_identifier))
(operator_identifier) (type_arguments (type_identifier))))
(generic_type
(type_identifier
(MISSING _alpha_identifier))
(type_arguments
(type_identifier)))))
(val_definition (val_definition
(operator_identifier) (operator_identifier)
(postfix_expression (field_expression
(field_expression (field_expression
(field_expression (field_expression
(identifier) (identifier)
@ -89,14 +86,14 @@ val test = id.##
(operator_identifier))) (operator_identifier)))
(val_definition (val_definition
(operator_identifier) (operator_identifier)
(postfix_expression (field_expression
(field_expression (field_expression
(identifier) (identifier)
(identifier)) (identifier))
(operator_identifier))) (operator_identifier)))
(val_definition (val_definition
(operator_identifier) (operator_identifier)
(postfix_expression (field_expression
(field_expression (field_expression
(identifier) (identifier)
(identifier)) (identifier))
@ -104,9 +101,13 @@ val test = id.##
(function_definition (operator_identifier) (operator_identifier)) (function_definition (operator_identifier) (operator_identifier))
(val_definition (val_definition
(identifier) (identifier)
(postfix_expression (field_expression
(identifier) (identifier)
(operator_identifier)))) (operator_identifier)))
(val_definition (identifier) (identifier))
(comment)
(comment)
(comment))
================================ ================================
Package Package

@ -1165,7 +1165,28 @@ module.exports = grammar({
wildcard: $ => '_', 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: $ => _non_null_literal: $ =>
choice( choice(

@ -4,7 +4,7 @@
SCALA_SCALA_LIBRARY_EXPECTED=100 SCALA_SCALA_LIBRARY_EXPECTED=100
SCALA_SCALA_COMPILER_EXPECTED=66 SCALA_SCALA_COMPILER_EXPECTED=66
DOTTY_COMPILER_EXPECTED=74 DOTTY_COMPILER_EXPECTED=66
if [ ! -d "$SCALA_SCALA_DIR" ]; then if [ ! -d "$SCALA_SCALA_DIR" ]; then
echo "\$SCALA_SCALA_DIR must be set" echo "\$SCALA_SCALA_DIR must be set"