Re: Sometimes keywords
Eric Ludlam <[email protected]> Wed, 13 Apr 2016 20:17:35 -0400
| Newsgroups | gmane.emacs.semantic |
|---|---|
| Message-ID | <[email protected]> |
On 03/30/2016 09:37 AM, Gracjan Polak wrote: > Hi, > > I'm working on Haskell grammar and there is a language construct when an > identifier is a keyword only in specific context, for example 'family' > is ordinary identifier unless it follows 'type', for example: > > type family X a b = .... (a keyword here) > > let family = Flistones in .... (a variable here) > > How do I create this context sensitivity in Wisent/Semantic? Hi Gracjan, If you are using wisent for your grammar, and the lexer framework for lexical analysis, then things are a bit tricky. The symbol table system in the lexer just blindly converts symbols into keywords if it is a textual match. Likewise, the 'symbol' lexical token is anything that isn't a keyword. I suppose you could create a 'haskell-symbol' rule that is either a regular symbol, or the FAMILY identifier, and then convert FAMILY back into a string "family", but I suspect there may be complications there. If you want to handle this all in the lexer, you could (and this leaves me feeling a little conflicted) make a copy of 'semantic-lex-symbol-or-keyword' and augment it. In your new lex analyzer you would need to: 1) Track the last symbol found. 2) if last symbol is keyword is NOT 'type' then make family (if found) be a symbol. You would then add family as a %keyword in your grammar. I suspect all this extra string value checking would slow things down a bit, but perhaps it will be ok. I don't have any other better ideas or ready-made support for this concept. Eric ------------------------------------------------------------------------------ Find and fix application performance issues faster with Applications Manager Applications Manager provides deep performance insights into multiple tiers of your business applications. It resolves application problems quickly and reduces your MTTR. Get your free trial! https://ad.doubleclick.net/ddm/clk/302982198;130105516;z