Skip to content

Commit fe6ff49

Browse files
committed
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.
1 parent c110fba commit fe6ff49

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

corpus/definitions.txt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def → = ???
5858

5959
val test = id.##
6060

61+
val x = y
62+
/////////
63+
// avoid matching slashes as operator
64+
/////////
65+
6166
---
6267

6368
(compilation_unit
@@ -66,21 +71,13 @@ val test = id.##
6671
(type_parameters
6772
(covariant_type_parameter
6873
(identifier)))
69-
(infix_type
70-
(stable_type_identifier
71-
(stable_identifier
72-
(identifier)
73-
(identifier))
74+
(generic_type
75+
(stable_type_identifier (stable_identifier (stable_identifier (identifier) (identifier)) (identifier))
7476
(type_identifier))
75-
(operator_identifier)
76-
(generic_type
77-
(type_identifier
78-
(MISSING _alpha_identifier))
79-
(type_arguments
80-
(type_identifier)))))
77+
(type_arguments (type_identifier))))
8178
(val_definition
8279
(operator_identifier)
83-
(postfix_expression
80+
(field_expression
8481
(field_expression
8582
(field_expression
8683
(identifier)
@@ -89,24 +86,28 @@ val test = id.##
8986
(operator_identifier)))
9087
(val_definition
9188
(operator_identifier)
92-
(postfix_expression
89+
(field_expression
9390
(field_expression
9491
(identifier)
9592
(identifier))
9693
(operator_identifier)))
9794
(val_definition
9895
(operator_identifier)
99-
(postfix_expression
96+
(field_expression
10097
(field_expression
10198
(identifier)
10299
(identifier))
103100
(operator_identifier)))
104101
(function_definition (operator_identifier) (operator_identifier))
105102
(val_definition
106103
(identifier)
107-
(postfix_expression
104+
(field_expression
108105
(identifier)
109-
(operator_identifier))))
106+
(operator_identifier)))
107+
(val_definition (identifier) (identifier))
108+
(comment)
109+
(comment)
110+
(comment))
110111

111112
================================
112113
Package

grammar.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,28 @@ module.exports = grammar({
11651165

11661166
wildcard: $ => '_',
11671167

1168-
operator_identifier: $ => /[!#%&*+-\/:<=>?@'^\|~\p{Sm}\p{So}]+/,
1168+
/**
1169+
* Regex patterns created to avoid matching // comments.
1170+
* This could technically match illeagal tokens such as val ?// = 1
1171+
*/
1172+
operator_identifier: $ => token(choice(
1173+
// single opchar
1174+
/[\-!#%&*+\/\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/,
1175+
seq(
1176+
// opchar minus slash
1177+
/[\-!#%&*+\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/,
1178+
// opchar*
1179+
repeat1(/[\-!#%&*+\/\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/),
1180+
),
1181+
seq(
1182+
// opchar
1183+
/[\-!#%&*+\/\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/,
1184+
// opchar minus slash
1185+
/[\-!#%&*+\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/,
1186+
// opchar*
1187+
repeat(/[\-!#%&*+\/\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/),
1188+
),
1189+
)),
11691190

11701191
_non_null_literal: $ =>
11711192
choice(

script/smoke_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
SCALA_SCALA_LIBRARY_EXPECTED=100
66
SCALA_SCALA_COMPILER_EXPECTED=66
7-
DOTTY_COMPILER_EXPECTED=74
7+
DOTTY_COMPILER_EXPECTED=66
88

99
if [ ! -d "$SCALA_SCALA_DIR" ]; then
1010
echo "\$SCALA_SCALA_DIR must be set"

0 commit comments

Comments
 (0)