diff --git a/corpus/comments.txt b/corpus/comments.txt new file mode 100644 index 000000000..55c9b8ec2 --- /dev/null +++ b/corpus/comments.txt @@ -0,0 +1,33 @@ +================================================================================ +Single line comments +================================================================================ + +// comment 1 +// comment 2 + +-------------------------------------------------------------------------------- + +(compilation_unit + (comment) + (comment)) + +================================================================================ +Block comments +================================================================================ +/**/ +/** comment 1 + * /* comment 2 + * /* / * * /comment 3 */ + // comment 4 + * @param + * */ +*/ + +-------------------------------------------------------------------------------- + +(compilation_unit + (block_comment) + (block_comment + (block_comment + (block_comment) + (comment)))) diff --git a/corpus/expressions.txt b/corpus/expressions.txt index 82acb8680..9a031ae22 100644 --- a/corpus/expressions.txt +++ b/corpus/expressions.txt @@ -76,7 +76,7 @@ class C { (identifier) (operator_identifier) (integer_literal))))) - (comment) + (block_comment) (call_expression (field_expression (identifier) @@ -813,7 +813,7 @@ class C { (identifier) (identifier)) (comment) - (comment) + (block_comment) (identifier))))))) ================================================================================ @@ -895,6 +895,7 @@ class C { def main() { a = b max c d + e + f + a ** b } } @@ -920,6 +921,10 @@ class C { (operator_identifier) (identifier)) (operator_identifier) + (identifier)) + (infix_expression + (identifier) + (operator_identifier) (identifier))))))) ================================================================================ diff --git a/grammar.js b/grammar.js index 4c417aa2b..66b8f9e18 100644 --- a/grammar.js +++ b/grammar.js @@ -27,7 +27,8 @@ module.exports = grammar({ extras: $ => [ /\s/, - $.comment + $.comment, + $.block_comment, ], supertypes: $ => [ @@ -1293,7 +1294,7 @@ module.exports = grammar({ wildcard: $ => '_', /** - * Regex patterns created to avoid matching // comments. + * Regex patterns created to avoid matching // comments and /* comment starts. * This could technically match illeagal tokens such as val ?// = 1 */ operator_identifier: $ => token(choice( @@ -1308,8 +1309,8 @@ module.exports = grammar({ seq( // opchar /[\-!#%&*+\/\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/, - // opchar minus slash - /[\-!#%&*+\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/, + // opchar minus slash and asterisk + /[\-!#%&+\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/, // opchar* repeat(/[\-!#%&*+\/\\:<=>?@\u005e\u007c~\p{Sm}\p{So}]/), ), @@ -1519,14 +1520,14 @@ module.exports = grammar({ repeat1($.guard), ), - comment: $ => token(choice( - seq('//', /.*/), - seq( - '/*', - /[^*]*\*+([^/*][^*]*\*+)*/, - '/' - ) - )) + comment: $ => token(seq('//', /.*/)), + + block_comment: $ => seq( + token('/*'), + repeat(token(/./)), + token('*/') + ), + } }) diff --git a/script/smoke_test.sh b/script/smoke_test.sh index c72980c8e..0a191a3e2 100755 --- a/script/smoke_test.sh +++ b/script/smoke_test.sh @@ -4,7 +4,7 @@ SCALA_SCALA_LIBRARY_EXPECTED=94 SCALA_SCALA_COMPILER_EXPECTED=84 -DOTTY_COMPILER_EXPECTED=80 +DOTTY_COMPILER_EXPECTED=81 SYNTAX_COMPLEXITY_CEILING=2300 if [ ! -d "$SCALA_SCALA_DIR" ]; then