[stringtemplate-interest] 2. Attempt: ANTLR code generation target/Stringtemplate: modifying the C-Runtime I
Terence Parr
parrt at cs.usfca.edu
Wed Nov 23 09:21:17 PST 2011
On Nov 17, 2011, at 11:30 AM, Udo Weik wrote:
> I would be really happy to get an answer...
>
>
> Hello,
>
> I asked my questions in antlr-interest and Jim wrote that
> these are more Stringtemplate-related. So here again.
>
> I startet to modify the C-Runtime and have a first bunch of
> questions. Be sure, more will follow - "Eeek, what a pain!"...
>
> 1. <token> in <action>
> I need the token of an rule in the <action>-section
> /** How to execute an action (when not backtracking) */
> execAction(action) ::= <<
> <if(backtracking)>
> <if(actions.(actionScope).synpredgate)>
> if ( <actions.(actionScope).synpredgate> )
> ...
> <ruleDescriptor.name> and <ruleName> are replaced (what is the
> difference?) but <token> not. Why?
So in the execAction template you want to reference <token>? What do you mean by token in a rule? you can get a tree for the rule in the Rule object:
/** The AST representing the whole rule */
public GrammarAST tree;
> 2. Blank lines
> The C-Parser-file of my grammar consits of ~150.000 lines, ~20.000
> lines are blank. As mentioned in another email from me, I can't debug
> more than 65535 lines. The only solution is to reorder the (parser) rules.
> But apart from that severe problem, I looked for a solution to get
> a much more compact code. Some examples, section...
> 1. // Forward declare the locally static matching functions we have generated.
> //
> static
> XYZParser_RULE_return
> RULE (pXYZParser ctx);
>
> 3 lines - the result of
> <rules:{r | static <headerReturnType(ruleDescriptor=r.ruleDescriptor)> <r.ruleDescriptor.name> (p<name> ctx<if(r.ruleDescriptor.parameterScope)>, <endif>
> <r.ruleDescriptor.parameterScope:parameterScope()>);}; separator="\n">
> How can I avoid 2 lines?
> 2. /* ==============================================
> * Parsing rules
> */
> ...
> static XYZParser_RULE_return
> port_RULE(pXYZParser ctx)
>
> 2 lines - the result of
> <rules; separator="\n\n">
> How can I avoid 1 line?
The general rule is that white space at the start and end of templates is consumed, but it leaves the new lines inside the templates themselves. In this case, you can remove one of the \n from \n\n, right?
Ter
More information about the stringtemplate-interest
mailing list