Closed nuchi closed 2 years ago
That's certainly a bug!
Would you accept a contribution to fix this if I manage it? Not sure if I'd be able to, but also I didn't see anything in the repo about whether you accept contributions.
Of course, all contributions are welcome.
I tried working through your code in order to understand how it works, and found it too difficult to wrap my head around, without understanding the underlying theory. So I went and learned a bit about parser construction.
And I, uh, went and started implementing my own syntax constructor. Thought you might be interested in taking a look. https://github.com/nuchi/sublime-from-cfg
FYI for anyone reading along, I'm now self-hosting sbnf.sbnf
and feature-complete. It's written in python. ~I haven't published to pypi yet but it's installable with pip install 'sublime-from-cfg @ git+ssh://git@github.com/nuchi/sublime-from-cfg#egg=sublime-from-cfg'
~ It's installable with pip install sublime-from-cfg
and then sublime-from-cfg /my/syntax/file.sbnf
once it's in your PATH.
The following (adapted from the unit tests in
src/compiler/mod.rs
, scopes changed to be visible in screenshots) works:But the following slight modification doesn't:
Interestingly, in the generated code, increasing the number of
pop
s after thea
andb
checks seems to fix this but I don't know why.generated code
```diff %YAML 1.2 --- # http://www.sublimetext.com/docs/syntax.html version: 2 name: test file_extensions: - test scope: source.test contexts: a|0|main@1: - meta_include_prototype: false - match: 'c' scope: variable.function.test ac.test push: main|1|main@1 b|0|main@1: - meta_include_prototype: false - match: 'c' scope: variable.parameter.test bc.test push: main|2|main@1 # Include context for branch point main@1 include!main@1: - match: '(?=c)' branch_point: main@1 branch: - a|0|main@1 - b|0|main@1 # Rule: main main: - match: 'x' push: main|0 - match: '\S' scope: invalid.illegal.test # Rule: main main|0: - include: include!main@1 - match: '\S' scope: invalid.illegal.test pop: true # Rule: main # For branch point 'main@1' main|1|main@1: - match: 'a' scope: variable.function.test - pop: true + pop: 3 - match: '\S' fail: main@1 # Rule: main # For branch point 'main@1' main|2|main@1: - match: 'b' scope: variable.parameter.test - pop: true + pop: 3 - match: '\S' scope: invalid.illegal.test pop: true ```Again, hoping that this is a misunderstanding on my part and would love to find a workaround if so!