Skip to content

Commit 561da3b

Browse files
authored
Merge pull request #112 from keynmol/scala2-fixes
Vararg class params and operator identifiers
2 parents d6b7af2 + 71e8ac0 commit 561da3b

File tree

3 files changed

+80
-13
lines changed

3 files changed

+80
-13
lines changed

corpus/definitions.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,3 +858,67 @@ class B {
858858
(class_parameter
859859
(identifier)
860860
(type_identifier)))))))
861+
862+
863+
864+
===================================
865+
Operator identifiers
866+
===================================
867+
868+
type ::[+Ab] = scala.collection.immutable.::[Ab]
869+
val :: = scala.collection.immutable.::
870+
871+
val +: = scala.collection.+:
872+
val :+ = scala.collection.:+
873+
874+
val test = id.##
875+
876+
---
877+
878+
(compilation_unit
879+
(type_definition
880+
(type_identifier)
881+
(type_parameters
882+
(covariant_type_parameter
883+
(identifier)))
884+
(infix_type
885+
(stable_type_identifier
886+
(stable_identifier
887+
(identifier)
888+
(identifier))
889+
(type_identifier))
890+
(operator_identifier)
891+
(generic_type
892+
(type_identifier
893+
(MISSING _plainid))
894+
(type_arguments
895+
(type_identifier)))))
896+
(val_definition
897+
(operator_identifier)
898+
(postfix_expression
899+
(field_expression
900+
(field_expression
901+
(identifier)
902+
(identifier))
903+
(identifier))
904+
(operator_identifier)))
905+
(val_definition
906+
(operator_identifier)
907+
(postfix_expression
908+
(field_expression
909+
(identifier)
910+
(identifier))
911+
(operator_identifier)))
912+
(val_definition
913+
(operator_identifier)
914+
(postfix_expression
915+
(field_expression
916+
(identifier)
917+
(identifier))
918+
(operator_identifier)))
919+
(val_definition
920+
(identifier)
921+
(postfix_expression
922+
(identifier)
923+
(operator_identifier))))
924+

grammar.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ module.exports = grammar({
5555
$._pattern,
5656
$._semicolon,
5757
$._definition,
58-
$._type_identifier,
5958
$._param_type,
59+
$._identifier,
6060
$.literal,
6161
],
6262

@@ -278,7 +278,7 @@ module.exports = grammar({
278278
),
279279

280280
_type_parameter: $ => seq(
281-
field('name', choice($.wildcard, $.identifier)),
281+
field('name', choice($.wildcard, $._identifier)),
282282
field('type_parameters', optional($.type_parameters)),
283283
field('bound', optional($.upper_bound)),
284284
field('bound', optional($.lower_bound)),
@@ -445,7 +445,7 @@ module.exports = grammar({
445445

446446
// Created for memory-usage optimization during codegen.
447447
_function_constructor: $ => prec.left(PREC.control, seq(
448-
field('name', choice($.identifier, $.operator_identifier)),
448+
field('name', $._identifier),
449449
field('type_parameters', optional($.type_parameters)),
450450
field('parameters', repeat($.parameters)),
451451
optional(seq(':', field('return_type', $._type))),
@@ -556,6 +556,7 @@ module.exports = grammar({
556556
optional(choice('val', 'var')),
557557
field('name', $.identifier),
558558
optional(seq(':', field('type', $._type))),
559+
optional('*'),
559560
optional(seq('=', field('default_value', $.expression)))
560561
),
561562

@@ -634,7 +635,7 @@ module.exports = grammar({
634635

635636
infix_type: $ => prec.left(PREC.infix, seq(
636637
field('left', choice($.compound_type, $.infix_type, $._annotated_type)),
637-
field('operator', choice($.identifier, $.operator_identifier)),
638+
field('operator', $._identifier),
638639
field('right', choice($.compound_type, $.infix_type, $._annotated_type))
639640
)),
640641

@@ -698,13 +699,13 @@ module.exports = grammar({
698699
'*',
699700
),
700701

701-
_type_identifier: $ => alias($.identifier, $.type_identifier),
702+
_type_identifier: $ => alias($._identifier, $.type_identifier),
702703

703704
// ---------------------------------------------------------------
704705
// Patterns
705706

706707
_pattern: $ => choice(
707-
$.identifier,
708+
$._identifier,
708709
$.stable_identifier,
709710
$.capture_pattern,
710711
$.tuple_pattern,
@@ -726,7 +727,7 @@ module.exports = grammar({
726727

727728
infix_pattern: $ => prec.left(PREC.infix, seq(
728729
field('left', $._pattern),
729-
field('operator', choice($.identifier, $.operator_identifier)),
730+
field('operator', $._identifier),
730731
field('right', $._pattern),
731732
)),
732733

@@ -938,7 +939,7 @@ module.exports = grammar({
938939
$.prefix_expression,
939940
$._simple_expression,
940941
)),
941-
field('operator', choice($.identifier, $.operator_identifier)),
942+
field('operator', $._identifier),
942943
field('right', choice(
943944
$.prefix_expression,
944945
$._simple_expression,
@@ -954,7 +955,7 @@ module.exports = grammar({
954955
$.prefix_expression,
955956
$._simple_expression,
956957
),
957-
choice($.identifier, $.operator_identifier),
958+
$._identifier,
958959
)),
959960

960961
/**
@@ -1030,9 +1031,11 @@ module.exports = grammar({
10301031

10311032
symbol_literal: $ => '__no_longer_used',
10321033

1033-
// TODO: Include operators.
10341034
_plainid: $ => /[a-zA-Z_\\$][\w\\$]*/,
10351035
_backquoted_id: $=> /`[^\n`]+`/,
1036+
1037+
_identifier: $ => choice($.identifier, $.operator_identifier),
1038+
10361039
identifier: $ => choice(
10371040
$._plainid,
10381041
$._backquoted_id,
@@ -1045,7 +1048,7 @@ module.exports = grammar({
10451048

10461049
wildcard: $ => '_',
10471050

1048-
operator_identifier: $ => /[^\s\w\(\)\[\]\{\}'"`\.;,]+/,
1051+
operator_identifier: $ => /[!#%&*+-\/:<=>?@'^\|~]+/,
10491052

10501053
_non_null_literal: $ =>
10511054
choice(

script/smoke_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
# This is an integration test to generally check the quality of parsing.
44

5-
SCALA_SCALA_LIBRARY_EXPECTED=95
5+
SCALA_SCALA_LIBRARY_EXPECTED=98
66
SCALA_SCALA_COMPILER_EXPECTED=63
7-
DOTTY_COMPILER_EXPECTED=60
7+
DOTTY_COMPILER_EXPECTED=63
88

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

0 commit comments

Comments
 (0)