Closed nuchi closed 3 years ago
The following workaround seems to get me what I want:
- main = expr;
+ main = expr '\s';
expr = primitive (`+` primitive)*;
primitive = num | `(` expr `)`;
num = '\d+'{constant.numeric};
Sounds like a misunderstanding. The first SBNF snippet, when interpreted in my head, behaves exactly like the screenshot. Not sure why you expect it to illegalize the first paren.
With the way sublime-syntax works, main
and prototype
are special contexts that can never pop. Thus SNBF makes main = expr
equivalent to main = expr*
. I'm not sure if there's something in the language design I can do to make it clearer.
Thus SNBF makes
main = expr
equivalent tomain = expr*
.
Aha! That's what I was missing. Thanks for the clarification — I was expecting the whole document to match a single expr
.
Using sbnf version 0.4.0. EDIT: same on master
Sample highlighting:
Expected result: the first
(
should beinvalid.illegal
. Actual result:(
matches inmain
.compiled output
```yaml %YAML 1.2 --- # http://www.sublimetext.com/docs/syntax.html version: 2 name: test file_extensions: - test scope: source.test contexts: # Rule: expr expr|0: - match: '\+' push: expr|1 - match: '(?=\S)' pop: true # Rule: expr expr|1: - match: '\d+' scope: constant.numeric.test pop: true - match: '\(' set: primitive|0 - match: '\S' scope: invalid.illegal.test pop: true # Rule: main main: - match: '\d+' scope: constant.numeric.test set: expr|0 - match: '\(' set: [expr|0, primitive|0] - match: '\S' scope: invalid.illegal.test # Rule: primitive primitive|0: - match: '\d+' scope: constant.numeric.test set: [primitive|1, expr|0] - match: '\(' set: [primitive|1, expr|0, primitive|0] - match: '\S' scope: invalid.illegal.test pop: true # Rule: primitive primitive|1: - match: '\)' pop: true - match: '\S' scope: invalid.illegal.test pop: true ```The first
1
matches inmain
, and thenexpr|0
is set; the(
matches'(?=\S)'
inexpr|0
which pops the stack (which only containsexpr|0
), resetting back tomain
.I'm only mostly sure that there's a bug here; it's possible I have a misunderstanding somewhere. I'll also note that what I wanted to write was actually something like:
That's because I'm trying to directly translate a yacc source file which contains things like the latter. sbnf overflows the stack if I try it, but compiles my workaround. I hope there's some workaround I can use!
Thanks for taking the report!