Note that there are some explanatory texts on larger screens.

plurals
  1. POAntlr v3 comment processing VHDL
    text
    copied!<p>I am facing an ANTLR problem in a VHDL grammar I wrote. VHDL doesn't have true multiline comments, and no pragmas, so tool vendors invented a comment based mechanism to exclude certain parts of the code, something like </p> <pre><code>-- pragma translate_off code to disregard -- pragma translate_on </code></pre> <p>('--' introduces a comment in VHDL) where the actual code for the pragma varies, "synopsys translate off" and "rtl translate_off" are known variants.<br> the part of the ANTLR grammar handling comments is now </p> <pre><code>@lexer::members { private static final Pattern translateOnPattern = Pattern.compile("\\s*--\\s*(rtl_synthesis\\s+on|(pragma|synthesis|synopsys)\\s+translate(\\s|_)on)\\s*"); private static final Pattern translateOffPattern = Pattern.compile("\\s*-- \\s*(rtl_synthesis\\s+off|(pragma|synthesis|synopsys)\\s+translate(\\s|_)off)\\s*"); private boolean translateOn = true; } [...] COMMENT : '--' ( ~( '\n' | '\r' ) )* { $channel = CHANNEL_COMMENT; String content = getText(); Matcher mOn = translateOnPattern.matcher(content); if(mOn.matches()) { translateOn = true; } Matcher mOff = translateOffPattern.matcher(content); if(mOff.matches()) { translateOn = false; } } ; </code></pre> <p>The problem is that my comments go to the hidden channel and while I can recognize these pragmas by processing the comment in a lexer action using regex, I have not found a way to direct all coming tokens to the hidden channel until "-- pragma translate_on". Is that possbile or would you generally use a different approach?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload