Replies: 1 comment 3 replies
-
|
Hey @hallvard, can you share a bit more of your grammar, especially the Based on your examples, I would assume that the |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm writing a textual syntax for a something similar to UML class diagrams. I have builtin/native types and classes that both start with a keyword, which is followed by an optional documentation string, zero or more tagged values and then the name, e.g.
BuiltinType: 'builtin' (documentation = STRING)? (tags += Tag)* name = IDThis parses both
builtin String as java java.lang.String
and
builtin "Native String" String as java java.lang.String
Since the documentation and tags are repeated in both rules, I tried to move them into a fragment rule, i.e.
fragment MetaData: (documentation = STRING)? (tags += Tag)*;BuiltinType: 'builtin' MetaData name = IDNote, this is a bit simplified, there are reasons the name part weren't also moved into the fragment.
But it didn't work, I got errors in my test code. I tried again and again, switching between a fragment and the exact same fragment code included directly. And the error was there when using the fragment, but not when including the fragment's text directly. How can this be, when the documentation says "[fragments] can be understood as being textually inserted where they are referenced".
My only guess is that there is some kind of indirection in the parser that doesn't work, since MetaData can consume nothing.
Beta Was this translation helpful? Give feedback.
All reactions