Follow restrictions for keywords
For example:
SELECT DISTINCTvar1 FROM ...
There is an ambiguity here because “DISTINCTvar1” can either be parsed as “DISTINCT var1” or as a variable named “DISINCTvar1”.
Similar for:
... WHERE NOTfunc1()
Here,
NOTfunc1
can either be parsed asNOT func1
or as a function namedNOTfunc1
How to add a follow restrictions to avoid such ambiguity?
One way is to specify the keywords as lexical syntax:
context-free syntax Distinct.Distinct = DISTINCT lexical syntax DISTINCT = 'DISTINCT' {case-insensitive} lexical restrictions DISTINCT -/- [a-zA-Z]
signature constructors Distinct : Distinct strategies norm-distinct = ?Distinct(_); !Distinct()
But it is not so nice to have keywords spread out over context-free and lexical syntax. Also, code completion and syntax highlighting in Spoofax rely – to some degree – on keywords being specified as part of context-free syntax.
So I wonder if an annotation in context-free syntax makes sense, something like:
context-free syntax Distinct.Distinct = <DISTINCT> {case-insensitive, require-keywords-to-be-followed-by-LAYOUT}
Or maybe there’s a better solution?
Submitted by Oskar van Rest on 6 March 2018 at 01:55
Issue Log
You can add a follow restriction on the keyword without having to define a sort:
lexical restrictions 'DISTINCT' -/- [a-zA-Z0-9]
In SDF3 templates, you can do this for all keywords in a module:
template options keyword -/- [a-zA-Z0-9]
Great, that’s what I needed :)
I’ve addedkeyword -/- [a-zA-Z0-9]
to every module now.
Log in to post comments