aboutsummaryrefslogtreecommitdiff
path: root/tool/src/main/resources/org/antlr/codegen/templates/Ruby/ST.stg
blob: 5fe366ba4ed83b2fff9591d85d72fde4f88b352c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
@parserBody.mixins() ::= <<
<@super.mixins()>
<if(rewriteMode)>
include ANTLR3::Template::RewriteBuilder
<else>
include ANTLR3::Template::Builder
<endif>
>>

gatedAction( block ) ::= <<
<if(backtracking)>
if <actions.(actionScope).synpredgate>
  <block>
end
<else>
<block>
<endif>
>>

/** x+=rule when output=template */
ruleRefAndListLabel(rule,label,elementIndex,args,scope) ::= <<
<ruleRef(...)>
<listLabel(elem={<label; format="label">.template}, ...)>
>>

rewriteTemplate(alts) ::= <<
<gatedAction({
<first(alts):rewriteTemplateAltFirst(); anchor>
<rest(alts):{a| els<rewriteTemplateAltRest(a)>}; anchor, separator="\n\n">
<if(rewriteMode)><replaceTextInLine()><endif>
})>
>>

rewriteTemplateAltFirst(a) ::= <<
<if(a.pred)>
if <a.pred>
  # <a.description>
  return_value.template = <a.alt>
<else>
# <a.description>
return_value.template = <a.alt>
<endif>
>>

rewriteTemplateAltRest(a) ::= <<
<if(a.pred)>
if <a.pred>
  # <a.description>
  return_value.template = <a.alt>
<else>
e <! little hack to get if .. elsif .. else block right !>
  # <a.description>
  return_value.template = <a.alt>
end
<endif>
>>

replaceTextInLine() ::= <<
<if(TREE_PARSER)>
@input.token_stream.replace(
  @input.adaptor.token_start_index( return_value.start ),
  @input.adaptor.token_stop_index( return_value.start ),
  return_value.template
)
<else>
@input.replace(
  return_value.start.index,
  @input.look( -1 ).index,
  return_value.template
)
<endif>
>>

rewriteEmptyTemplate(alts) ::= <<
nil
>>

/** Invoke a template with a set of attribute name/value pairs.
 *  Set the value of the rule's template *after* having set
 *  the attributes because the rule's template might be used as
 *  an attribute to build a bigger template; you get a self-embedded
 *  template.
 */
rewriteExternalTemplate(name,args) ::= <<
fetch_template( "<name>" <if(args)>,
  <argumentMap(args)>
<endif>)
>>

/** expr is a string expression that says what template to load */
rewriteIndirectTemplate(expr,args) ::= <<
fetch_template( <expr><if(args)>, <argumentMap(args)><endif> )
>>

/** Invoke an inline template with a set of attribute name/value pairs */
rewriteInlineTemplate(args, template) ::= <<
create_template( "<template>"<if(args)>, <argumentMap(args)><endif> )
>>

/** plain -> {foo} action */
rewriteAction(action) ::= <<
<action>
>>

/** An action has %st.attrName=expr; or %{st}.attrName=expr; */
actionSetAttribute(st,attrName,expr) ::= <<
( <st> )[ :<attrName> ] = <expr>
>>

/** Translate %{stringExpr} */
actionStringConstructor(stringExpr) ::= <<
create_template( <stringExpr> )
>>

/*
rulePropertyRef_text(scope, attr) ::= <<
@input.to_s(return_value.start, @input.look(-1))
>>
*/

argumentMap(args) ::= <<
<args:{a|:<a.name> => <a.value>}; separator=",\n">
>>