Skip to content

Commit c687ba7

Browse files
authored
Merge pull request stadelmanma#140 from stadelmanma/split-end-block
Split the aliasing of `end` statements
2 parents d738334 + a5a15a9 commit c687ba7

File tree

5 files changed

+618288
-634619
lines changed

5 files changed

+618288
-634619
lines changed

grammar.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,11 @@ module.exports = grammar({
390390
end_block_data_statement: $ => {
391391
const structType = whiteSpacedKeyword('block', 'data', false)
392392
return prec.right(seq(
393-
alias(choice(
394-
seq(
395-
caseInsensitive('end', false),
396-
optional(structType)),
397-
caseInsensitive('end' + structType, false)),
398-
'end' + structType),
393+
choice(
394+
seq(
395+
alias(caseInsensitive('end', false), 'end'),
396+
optional(alias(structType, 'blockdata'))),
397+
alias(caseInsensitive('end' + structType, false), 'endblockdata')),
399398
optional($._name),
400399
$._end_of_statement))
401400
},
@@ -2259,11 +2258,18 @@ function caseInsensitive (keyword, aliasAsWord = true) {
22592258
}
22602259

22612260
function whiteSpacedKeyword (prefix, suffix, aliasAsWord = true) {
2262-
let result = choice(
2263-
seq(caseInsensitive(prefix, false), caseInsensitive(suffix, false)),
2264-
caseInsensitive(prefix + suffix, false))
2265-
if (aliasAsWord) result = alias(result, prefix + suffix)
2266-
return result
2261+
let prefix_bit = caseInsensitive(prefix, false)
2262+
let suffix_bit = caseInsensitive(suffix, false)
2263+
let both_bits = caseInsensitive(prefix + suffix, false)
2264+
if (aliasAsWord) {
2265+
prefix_bit = alias(prefix_bit, prefix)
2266+
suffix_bit = alias(suffix_bit, suffix)
2267+
both_bits = alias(both_bits, prefix + suffix)
2268+
}
2269+
return choice(
2270+
seq(prefix_bit, suffix_bit),
2271+
both_bits
2272+
)
22672273
}
22682274

22692275
function commaSep (rule) {
@@ -2281,12 +2287,11 @@ function sep1 (rule, separator) {
22812287
// This can be merged with whiteSpacedKeyword, keeping for now.
22822288
function blockStructureEnding ($, structType) {
22832289
const obj = prec.right(seq(
2284-
alias(choice(
2290+
choice(
22852291
seq(
2286-
caseInsensitive('end', false),
2287-
optional(caseInsensitive(structType, false))),
2288-
caseInsensitive('end' + structType, false)),
2289-
'end' + structType),
2292+
alias(caseInsensitive('end', false), 'end'),
2293+
optional(alias(caseInsensitive(structType, false), structType))),
2294+
alias(caseInsensitive('end' + structType, false), 'end' + structType)),
22902295
optional($._name),
22912296
$._end_of_statement
22922297
))

package-lock.json

Lines changed: 2 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)