Pārlūkot izejas kodu

Handle multi-line comments with asterisks at the end

pull/8/head
Max Brunsfeld pirms 8 gadiem
vecāks
revīzija
31c966ece2
4 mainītis faili ar 34 papildinājumiem un 22 dzēšanām
  1. +22
    -0
      corpus/statements.txt
  2. +5
    -7
      grammar.js
  3. +3
    -15
      src/grammar.json
  4. +4
    -0
      src/parser.c

+ 22
- 0
corpus/statements.txt Parādīt failu

@ -109,3 +109,25 @@ recur:
(identifier)
(call_expression (field_expression (identifier) (field_identifier)) (argument_list)))))
(if_statement (identifier) (goto_statement (statement_identifier))))))
============================================
Comments with asterisks
============================================
/*************************
* odd number of asterisks
*************************/
int a;
/**************************
* even number of asterisks
**************************/
int b;
---
(translation_unit
(comment)
(declaration (type_identifier) (identifier))
(comment)
(declaration (type_identifier) (identifier)))

+ 5
- 7
grammar.js Parādīt failu

@ -706,17 +706,15 @@ module.exports = grammar({
')'
),
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
comment: $ => token(choice(
seq(
'//',
/.*/
),
seq('//', /.*/),
seq(
'/*',
repeat(choice(/[^\*]/, /\*[^/]/)),
'*/'
/[^*]*\*+([^/*][^*]*\*+)*/,
'/'
)
))
)),
}
});

+ 3
- 15
src/grammar.json Parādīt failu

@ -3578,24 +3578,12 @@
"value": "/*"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^\\*]"
},
{
"type": "PATTERN",
"value": "\\*[^\\/]"
}
]
}
"type": "PATTERN",
"value": "[^*]*\\*+([^\\/*][^*]*\\*+)*"
},
{
"type": "STRING",
"value": "*/"
"value": "/"
}
]
}

+ 4
- 0
src/parser.c Parādīt failu

@ -2053,6 +2053,8 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
ADVANCE(94);
END_STATE();
case 95:
if (lookahead == '*')
ADVANCE(95);
if (lookahead == '/')
ADVANCE(96);
if (lookahead != 0)
@ -3866,6 +3868,8 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
ACCEPT_TOKEN(sym_preproc_arg);
if (lookahead == '\n')
ADVANCE(94);
if (lookahead == '*')
ADVANCE(287);
if (lookahead == '/')
ADVANCE(96);
if (lookahead == '\\')

Notiek ielāde…
Atcelt
Saglabāt