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 as NOT func1 or as a function named NOTfunc1

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

On 6 March 2018 at 02:26 Oskar van Rest tagged sdf

On 6 March 2018 at 06:05 Guido Wachsmuth commented:

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]

On 6 March 2018 at 23:13 Oskar van Rest commented:

Great, that’s what I needed :)
I’ve added keyword -/- [a-zA-Z0-9] to every module now.


On 6 March 2018 at 23:13 Oskar van Rest closed this issue.

Log in to post comments