Skip to content

Commit

Permalink
Make the semicolon queryable (#135)
Browse files Browse the repository at this point in the history
* make semicolon queryable

* regenerate parser

* add tests

* use SEMICOLON instead of repeating the semicolon literal everywhere
  • Loading branch information
resolritter authored Nov 12, 2021
1 parent 8600d7f commit 24b530c
Show file tree
Hide file tree
Showing 5 changed files with 955 additions and 945 deletions.
12 changes: 4 additions & 8 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const PREC = {
call: 20,
}

const SEMICOLON = ';'

module.exports = grammar({
name: 'python',

Expand Down Expand Up @@ -78,12 +80,8 @@ module.exports = grammar({
// Simple statements

_simple_statements: $ => seq(
$._simple_statement,
optional(repeat(seq(
$._semicolon,
$._simple_statement
))),
optional($._semicolon),
sep1($._simple_statement, SEMICOLON),
optional(SEMICOLON),
$._newline
),

Expand Down Expand Up @@ -968,8 +966,6 @@ module.exports = grammar({
)),

comment: $ => token(seq('#', /.*/)),

_semicolon: $ => ';'
}
})

Expand Down
25 changes: 9 additions & 16 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,36 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_simple_statement"
},
{
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_simple_statement"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_semicolon"
"type": "STRING",
"value": ";"
},
{
"type": "SYMBOL",
"name": "_simple_statement"
}
]
}
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_semicolon"
"type": "STRING",
"value": ";"
},
{
"type": "BLANK"
Expand Down Expand Up @@ -4885,10 +4882,6 @@
}
]
}
},
"_semicolon": {
"type": "STRING",
"value": ";"
}
},
"extras": [
Expand Down
4 changes: 4 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -2611,6 +2611,10 @@
"type": ":=",
"named": false
},
{
"type": ";",
"named": false
},
{
"type": "<",
"named": false
Expand Down
Loading

0 comments on commit 24b530c

Please sign in to comment.