Working on documentation comment issue.

pull/185/head
Ben Sobel 2020-07-25 07:48:44 +07:00
parent 7926143186
commit 30bef5c351
6 changed files with 81836 additions and 69800 deletions

@ -68,6 +68,8 @@ module.exports = grammar({
extras: $ => [
$.comment,
$.documentation_comment,
// $.multiline_comment,
/\s/
],
@ -168,7 +170,7 @@ module.exports = grammar({
repeat($.part_directive),
repeat($.part_of_directive),
// The precedence here is to make sure that this rule is matched before any of the _statement rules are matched for testing.
repeat(prec.dynamic(20, seq(optional($._metadata), $._top_level_definition))),
repeat(prec.dynamic(22, seq(optional($._metadata), $._top_level_definition))),
//for testing:
repeat($._statement)
),
@ -235,7 +237,7 @@ module.exports = grammar({
),
seq(
optional($._late_builtin),
choice($._type, 'var'),
choice($._type, $.inferred_type),
$.initialized_identifier_list,
$._semicolon
)
@ -2477,10 +2479,7 @@ module.exports = grammar({
DART_PREC.BUILTIN,
'const',
),
_final_builtin: $ => prec(
DART_PREC.BUILTIN,
'final',
),
_final_builtin: $ => token('final'),
_late_builtin: $ => prec(
DART_PREC.BUILTIN,
'late',
@ -2531,16 +2530,49 @@ module.exports = grammar({
identifier: $ => /[a-zA-Z_$][\w$]*/,
identifier_dollar_escaped: $ => /([a-zA-Z_]|(\\\$))([\w]\\\$)*/,
//TODO: add support for triple-slash comments as a special category.
// Trying to add support for nested multiline comments.
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
comment: $ => token(choice(
seq('//', /.*/),
seq(
'/*',
/[^*]*\*+([^/*][^*]*\*+)*/,
'/'
)
seq('//', /[^/].*/),
// seq(
// '/*',
// /[^*]*\*+([^/*][^*]*\*+)*/,
// '/'
// )
)),
//added nesting comments.
documentation_comment: $ => token(
choice(
seq('///', /.*/),
// seq(
// '/**',
// repeat(
// choice(
// /[^*]*\*+([^/*][^*]*\*+)*/,
// // $.comment
// // ,
// /.*/,
// $._multiline_comment,
// $.documentation_comment
// )
// ),
// '*/'
// )
)
),
// multiline_comment: $ => seq(
// $._multiline_comment_begin,
// repeat(
// choice(
// $._multiline_comment_core,
// $.multiline_comment
// )
// ),
// $._multiline_comment_end
// ),
// _multiline_comment_end: $ => token('*/'),
// _multiline_comment_begin: $ => token('/*'),
// _multiline_comment_core: $ => /([^\/*]*|\/[^*]|\*[^\/])+/,
}
});

@ -54,7 +54,7 @@
"type": "REPEAT",
"content": {
"type": "PREC_DYNAMIC",
"value": 20,
"value": 22,
"content": {
"type": "SEQ",
"members": [
@ -318,8 +318,8 @@
"name": "_type"
},
{
"type": "STRING",
"value": "var"
"type": "SYMBOL",
"name": "inferred_type"
}
]
},
@ -9507,8 +9507,7 @@
}
},
"_final_builtin": {
"type": "PREC",
"value": 0,
"type": "TOKEN",
"content": {
"type": "STRING",
"value": "final"
@ -9602,29 +9601,80 @@
},
{
"type": "PATTERN",
"value": ".*"
"value": "[^/].*"
}
]
},
}
]
}
},
"documentation_comment": {
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "/*"
"value": "///"
},
{
"type": "PATTERN",
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
"value": ".*"
}
]
}
]
}
},
"multiline_comment": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_multiline_comment_begin"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_multiline_comment_core"
},
{
"type": "STRING",
"value": "/"
"type": "SYMBOL",
"name": "multiline_comment"
}
]
}
]
},
{
"type": "SYMBOL",
"name": "_multiline_comment_end"
}
]
},
"_multiline_comment_end": {
"type": "TOKEN",
"content": {
"type": "STRING",
"value": "*/"
}
},
"_multiline_comment_begin": {
"type": "TOKEN",
"content": {
"type": "STRING",
"value": "/*"
}
},
"_multiline_comment_core": {
"type": "PATTERN",
"value": "([^\\/*]*|\\/[^*]|\\*[^\\/])+"
}
},
"extras": [
@ -9632,6 +9682,14 @@
"type": "SYMBOL",
"name": "comment"
},
{
"type": "SYMBOL",
"name": "documentation_comment"
},
{
"type": "SYMBOL",
"name": "multiline_comment"
},
{
"type": "PATTERN",
"value": "\\s"

@ -7154,6 +7154,21 @@
]
}
},
{
"type": "multiline_comment",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "multiline_comment",
"named": true
}
]
}
},
{
"type": "multiplicative_expression",
"named": true,
@ -8263,6 +8278,10 @@
"type": "import_or_export",
"named": true
},
{
"type": "inferred_type",
"named": true
},
{
"type": "initialized_identifier_list",
"named": true
@ -11315,10 +11334,6 @@
"type": "false",
"named": false
},
{
"type": "final",
"named": false
},
{
"type": "finally",
"named": false

File diff suppressed because it is too large Load Diff

@ -8,7 +8,7 @@ comment
---
(program (comment) (comment) (comment))
(program (comment) (multiline_comment) (multiline_comment))
======================
comments and literals
@ -25,7 +25,7 @@ comments and literals
======================
documentation comment
documentation comment 1
======================
/**
@ -37,4 +37,29 @@ documentation comment
---
(program (comment) (comment) (comment))
======================
documentation comment 2
======================
/**
* Is [:true:] if this comment is a documentation comment.
*
* That is, that the comment is either enclosed in [: /** ... */ :] or starts
*/
---
======================
documentation comment 3
======================
/*
* Is [:true:] if this comment is a documentation comment.
*
* That is, that the comment is either enclosed in /* var ... */ var or starts
*/
---

@ -356,7 +356,7 @@ var x = 0;
---
(program
(program (inferred_type)
(initialized_identifier_list (initialized_identifier (identifier) (decimal_integer_literal))))
@ -541,7 +541,7 @@ if (blah) {
---
(program
(local_variable_declaration (initialized_variable_definition (type_identifier) (type_identifier) (identifier) (identifier) (selector
(type_identifier) (type_identifier) (static_final_declaration_list (static_final_declaration (identifier) (identifier) (selector
(assignable_selector (unconditional_assignable_selector (identifier)))) (selector (argument_part (arguments)))))
(local_variable_declaration (initialized_variable_definition (type_identifier) (type_identifier) (identifier)))
(if_statement (parenthesized_expression (identifier))