How to match tokens according to both their textual values and types in Grammar-Kit

I am writing a plugin for Logtalk (a Prolog like language). Given the nature of the language, in Grammar-Kit I need to match certain tokens (called "left operators" in my language) according to both their textual values (e.g., keywords) and the types identified by the lexer.

 

For example, I know that the "default left operators" are these literals:

 

known_left_operator_token ::= ( ':-'|'?-'|
'dynamic'|'discontiguous'|'initialization'|'meta_predicate'|'module_transparent'|'multifile'|
'public'|'thread_local'|'thread_initialization'|'volatile'|
'\+'|
'?'|
'+'|'-'|'\'|
'$'|
'@'|
'::'|
'^^'
)

 

But a token should only be identified as a "left operator" if, in addition to have one of these literal values, was identified by the lexer as one of the following types:

 

valid_operator ::= atom_keyword|UNQUOTED_ATOM|SYMBOLIC_ATOM

 

My question is how can I combine the rules so it will match operators that have certain textual values (as in the "known_left_operator_token" rule) and has certain types (as in the "valid_operator" rule).

 

I was trying to write something like:

known_left_operator ::= valid_operator{extends=known_left_operator_token}

but it does not seem to work. I am not sure if "extends" is what I need here since I did not find a clear documentation of it anywhere.

 

Thanks for any clue !

 

 

 

 

 

2 comments

After lots of try and error, this seems to be working:

valid_operator ::= atom_keyword|UNQUOTED_ATOM|SYMBOLIC_ATOM
known_left_operator ::= &valid_operator (
':-'|'?-'|
'dynamic'|'discontiguous'|'initialization'|'meta_predicate'|'module_transparent'|'multifile'|
'public'|'thread_local'|'thread_initialization'|'volatile'|
'\+'|
'?'|
'+'|'-'|'\'|
'$'|
'@'|
'::'|
'^^'
)

 

 

 

0

I just want to thank you for your Logtalk plugin! I use it developing code for SWI-Prolog, and it is very nice to be able to use Intellij. Keep it up ;)

/LEO

 

0

Please sign in to leave a comment.