Skip to content

Commit

Permalink
Merge pull request #123 from stadelmanma/allow-extra-semicolons
Browse files Browse the repository at this point in the history
Allow extra semicolons/empty statements
  • Loading branch information
stadelmanma authored Jan 11, 2025
2 parents c979a86 + 9a2a175 commit 7ee481d
Show file tree
Hide file tree
Showing 6 changed files with 462,632 additions and 456,635 deletions.
24 changes: 4 additions & 20 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,10 @@
// http://www.personal.psu.edu/jhm/f90/statements/intrinsic.html
// http://earth.uni-muenster.de/~joergs/doc/f90/lrm/lrm0083.htm#data_type_declar
//
// Semicolons are treated exactly like newlines and can end any statement
// or be used to chain multiple ones together with the exception of using
// an ampersand to continue a line and comments.
//
// I'll need to figure out how best to add support for statement labels
// since the parser doesn't support the ^ regex token, a using a seq
// might work as long as the label is optional.
//
// The best route to handle line continuation in fortran might be using
// an external scanner. Basically the scanner would create the "end_of_statement"
// tokens, as well as newline tokens and if an ampersand was encounted prior to
// a newline the EOS token would get skipped. The same scanner would then be
// used as needed to support fixed form fortran although line truncation at
// 72 characters would not be supported because it can be configured at
// compile time. Additionally, I can make the line continuation token an
// extra so it gets ignored, for free form a trailing "&" would get labeled
// as the token, for fixed form it would be anything in column 6. Additionally,
// when using the scanner perhaps I could define statement labels as extras
// since they can exist almost anywhere and are only required in a small
// subset of cases.
//
const PREC = {
ASSIGNMENT: -10,
DEFAULT: 0,
Expand Down Expand Up @@ -75,7 +58,7 @@ module.exports = grammar({
$._boz_literal,
$._string_literal,
$._string_literal_kind,
$._end_of_statement,
$._external_end_of_statement,
$._preproc_unary_operator,
],

Expand Down Expand Up @@ -994,7 +977,8 @@ module.exports = grammar({
optional($.statement_label),
$._statements,
$._end_of_statement
)
),
';'
),

_statements: $ => choice(
Expand Down Expand Up @@ -2126,7 +2110,7 @@ module.exports = grammar({

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

_semicolon: $ => ';',
_end_of_statement: $ => choice(';', $._external_end_of_statement),

_newline: $ => '\n',
}
Expand Down
21 changes: 17 additions & 4 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -12585,6 +12585,10 @@
"name": "_end_of_statement"
}
]
},
{
"type": "STRING",
"value": ";"
}
]
},
Expand Down Expand Up @@ -20011,9 +20015,18 @@
]
}
},
"_semicolon": {
"type": "STRING",
"value": ";"
"_end_of_statement": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "SYMBOL",
"name": "_external_end_of_statement"
}
]
},
"_newline": {
"type": "STRING",
Expand Down Expand Up @@ -20136,7 +20149,7 @@
},
{
"type": "SYMBOL",
"name": "_end_of_statement"
"name": "_external_end_of_statement"
},
{
"type": "SYMBOL",
Expand Down
8 changes: 6 additions & 2 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -12756,6 +12756,10 @@
"type": "::",
"named": false
},
{
"type": ";",
"named": false
},
{
"type": "<",
"named": false
Expand Down Expand Up @@ -13330,11 +13334,11 @@
},
{
"type": "none",
"named": false
"named": true
},
{
"type": "none",
"named": true
"named": false
},
{
"type": "nopass",
Expand Down
Loading

0 comments on commit 7ee481d

Please sign in to comment.