|
I have a grammar that has a couple keywords that are optional. My MSchema wants a bool value - true if the keyword is there, false if the keyword is absent.
(not that I'm even close to my grammar generating M that is compatible with any schema, but that's the goal - though I begin to suspect any meaningful DSL syntax can't be translated directly to a relational schema using mgx.exe)
So I have this token:
@{Classification["Keyword"]} token ReadOnly = "ReadOnly" => true;
And this syntax:
syntax SimpleProperty = scope:Scope ident:Identity? ro:ReadOnly? type:Token name:Token EndStatement => Property { Name = name, Scope =scope, Identity=ident, ReadOnly = ro, Type = type };
Notice that ReadOnly is optional. This sort of renders into M, but not really.
If the keyword is there, the M output is 'true' including the ticks - which is not acceptible.
If the keyword is not there, the M output is null without any ticks, which is ok, but would require that this column allow nulls even though I really just want true/false.
I know I could probably solve this by having two syntax statements - one with the ReadOnly keyword and one without. But that's a really silly solution, because I have more than one optional keyword, so I'd end up with around 8 syntax blocks in my grammar, tons and tons of duplicated code just to handle this one issue.
Clearly this is a common scenario in languages. So I assume there must be a reasonable answer- probably something simple I'm missing. |