Skip to content

Commit

Permalink
Add support for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Sandven authored and Hubro committed May 13, 2022
1 parent a9aa7aa commit f1142bf
Show file tree
Hide file tree
Showing 5 changed files with 3,925 additions and 3,321 deletions.
11 changes: 9 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function setting(name) {
module.exports = grammar({
name: "robot",

extras: $ => [],
extras: $ => [$.comment],

rules: {
source_file: $ => seq(
Expand Down Expand Up @@ -320,7 +320,12 @@ module.exports = grammar({
variable_name: $ => /[^{}]+/,

text_chunk: $ => token(seq(
repeat1(choice(
choice(
/[^\s$@&{#]/, // Can't start with a #, since that would be a comment
/[$@&][^{]/,
/[^$@&]\{/,
),
repeat(choice(
/[^\s$@&{]/,
/[$@&][^{]/,
/[^$@&]\{/,
Expand All @@ -335,6 +340,8 @@ module.exports = grammar({
)),
)),

comment: $ => token(seq(optional(/[ \t]+/), "#", /[^\n]+/)),

_separator: $ => token(seq(/[ ]{2}|\t/, optional(/[ \t]+/))),

_whitespace: $ => /[ \t]+/,
Expand Down
58 changes: 52 additions & 6 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -904,10 +904,6 @@
}
]
},
"section_header_extra_text": {
"type": "PATTERN",
"value": "[^\\r\\n]+"
},
"test_case_definition": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -1698,7 +1694,24 @@
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^\\s$@&{#]"
},
{
"type": "PATTERN",
"value": "[$@&][^{]"
},
{
"type": "PATTERN",
"value": "[^$@&]\\{"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -1752,6 +1765,34 @@
]
}
},
"comment": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[ \\t]+"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "#"
},
{
"type": "PATTERN",
"value": "[^\\n]+"
}
]
}
},
"_separator": {
"type": "TOKEN",
"content": {
Expand Down Expand Up @@ -1806,7 +1847,12 @@
]
}
},
"extras": [],
"extras": [
{
"type": "SYMBOL",
"name": "comment"
}
],
"conflicts": [],
"precedences": [],
"externals": [],
Expand Down
4 changes: 4 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@
"type": "@{",
"named": false
},
{
"type": "comment",
"named": true
},
{
"type": "ellipses",
"named": true
Expand Down
Loading

0 comments on commit f1142bf

Please sign in to comment.