33
# Make sure we always return an array.
34
if val[0].is_a?(AST::ASTArray)
35
if val[0].children.empty?
41
result = aryfy(val[0])
31
program: statements_and_declarations
50
| statements statement {
52
if val[0].instance_of?(AST::ASTArray)
34
statements_and_declarations: statement_or_declaration {
35
result = ast AST::ASTArray, :children => (val[0] ? [val[0]] : [])
37
| statements_and_declarations statement_or_declaration {
53
39
val[0].push(val[1])
56
result = ast AST::ASTArray, :children => [val[0],val[1]]
58
elsif obj = (val[0] || val[1])
44
# statements is like statements_and_declarations, but it doesn't allow
45
# nested definitions, classes, or nodes.
46
statements: statements_and_declarations {
48
if stmt.is_a?(AST::TopLevelConstruct)
49
error "Classes, definitions, and nodes may only appear at toplevel or inside other classes", \
50
:line => stmt.context[:line], :file => stmt.context[:file]
64
56
# The main list of valid statements
57
statement_or_declaration: resource
89
81
edge: IN_EDGE | OUT_EDGE | IN_EDGE_SUB | OUT_EDGE_SUB
91
83
fstatement: NAME LPAREN funcvalues RPAREN {
93
84
result = ast AST::Function,
94
85
:name => val[0][:value],
95
86
:line => val[0][:line],
97
88
:ftype => :statement
99
90
| NAME LPAREN funcvalues COMMA RPAREN {
101
91
result = ast AST::Function,
102
92
:name => val[0][:value],
103
93
:line => val[0][:line],
105
95
:ftype => :statement
106
96
} | NAME LPAREN RPAREN {
107
97
result = ast AST::Function,
111
101
:ftype => :statement
113
103
| NAME funcvalues {
115
104
result = ast AST::Function,
116
105
:name => val[0][:value],
117
106
:line => val[0][:line],
107
:arguments => val[1],
119
108
:ftype => :statement
122
funcvalues: namestring
111
funcvalues: namestring { result = aryfy(val[0]) }
112
| resourceref { result = aryfy(val[0]) }
124
113
| funcvalues COMMA namestring {
125
result = aryfy(val[0], val[2])
126
result.line = @lexer.line
127
result.file = @lexer.file
129
117
| funcvalues COMMA resourceref {
130
unless val[0].is_a?(AST::ASTArray)
131
val[0] = aryfy(val[0])
139
122
# This is *almost* an rvalue, but I couldn't get a full
153
136
resource: classname LBRACE resourceinstances endsemi RBRACE {
154
137
@lexer.commentpop
156
array = [array] if array.instance_of?(AST::ResourceInstance)
157
result = ast AST::ASTArray
159
# this iterates across each specified resourceinstance
160
array.each { |instance|
161
raise Puppet::Dev, "Got something that isn't an instance" unless instance.instance_of?(AST::ResourceInstance)
162
# now, i need to somehow differentiate between those things with
163
# arrays in their names, and normal things
168
:title => instance[0],
170
:parameters => instance[1])
138
result = ast(AST::Resource, :type => val[0], :instances => val[2])
172
139
} | classname LBRACE params endcomma RBRACE {
173
140
# This is a deprecated syntax.
174
141
error "All resource specifications require names"
305
266
resourceinst: resourcename COLON params endcomma {
306
result = ast AST::ResourceInstance, :children => [val[0],val[2]]
267
result = ast AST::ResourceInstance, :title => val[0], :parameters => val[2]
309
resourceinstances: resourceinst
270
resourceinstances: resourceinst { result = aryfy(val[0]) }
310
271
| resourceinstances SEMIC resourceinst {
311
if val[0].instance_of?(AST::ResourceInstance)
312
result = ast AST::ASTArray, :children => [val[0],val[2]]
314
272
val[0].push val[2]
319
276
endsemi: # nothing
385
338
result = ast AST::ASTArray
387
| anyparam { result = val[0] }
340
| anyparam { result = aryfy(val[0]) }
388
341
| anyparams COMMA anyparam {
389
if val[0].instance_of?(AST::ASTArray)
390
342
val[0].push(val[2])
393
result = ast AST::ASTArray, :children => [val[0],val[2]]
398
| rvalues comma rvalue {
399
if val[0].instance_of?(AST::ASTArray)
400
result = val[0].push(val[2])
402
result = ast AST::ASTArray, :children => [val[0],val[2]]
346
rvalues: rvalue { result = aryfy(val[0]) }
347
| rvalues comma rvalue { result = val[0].push(val[2]) }
406
349
simplervalue: quotedtext
573
515
casestatement: CASE rvalue LBRACE caseopts RBRACE {
574
516
@lexer.commentpop
576
options = ast AST::ASTArray, :children => [val[3]] unless options.instance_of?(AST::ASTArray)
577
result = ast AST::CaseStatement, :test => val[1], :options => options
517
result = ast AST::CaseStatement, :test => val[1], :options => val[3]
520
caseopts: caseopt { result = aryfy(val[0]) }
581
521
| caseopts caseopt {
582
if val[0].instance_of?(AST::ASTArray)
583
522
val[0].push val[1]
586
result = ast AST::ASTArray, :children => [val[0], val[1]]
590
526
caseopt: casevalues COLON LBRACE statements RBRACE {
661
result = AST::ASTArray.new(:children => [])
664
596
# Disable definition inheritance for now. 8/27/06, luke
665
597
#definition: DEFINE NAME argumentlist parent LBRACE statements RBRACE {
666
598
definition: DEFINE classname argumentlist LBRACE statements RBRACE {
667
599
@lexer.commentpop
668
newdefine classname(val[1]), :arguments => val[2], :code => val[4], :line => val[0][:line]
600
result = Puppet::Parser::AST::Definition.new(classname(val[1]),
601
ast_context(true).merge(:arguments => val[2], :code => val[4],
602
:line => val[0][:line]))
669
603
@lexer.indefine = false
672
605
#} | DEFINE NAME argumentlist parent LBRACE RBRACE {
673
606
} | DEFINE classname argumentlist LBRACE RBRACE {
674
607
@lexer.commentpop
675
newdefine classname(val[1]), :arguments => val[2], :line => val[0][:line]
608
result = Puppet::Parser::AST::Definition.new(classname(val[1]),
609
ast_context(true).merge(:arguments => val[2], :line => val[0][:line]))
676
610
@lexer.indefine = false
680
613
#hostclass: CLASS NAME argumentlist parent LBRACE statements RBRACE {
681
hostclass: CLASS classname argumentlist classparent LBRACE statements RBRACE {
614
hostclass: CLASS classname argumentlist classparent LBRACE statements_and_declarations RBRACE {
682
615
@lexer.commentpop
683
616
# Our class gets defined in the parent namespace, not our own.
685
newclass classname(val[1]), :arguments => val[2], :parent => val[3], :code => val[5], :line => val[0][:line]
618
result = Puppet::Parser::AST::Hostclass.new(classname(val[1]),
619
ast_context(true).merge(:arguments => val[2], :parent => val[3],
620
:code => val[5], :line => val[0][:line]))
687
621
} | CLASS classname argumentlist classparent LBRACE RBRACE {
688
622
@lexer.commentpop
689
623
# Our class gets defined in the parent namespace, not our own.
691
newclass classname(val[1]), :arguments => val[2], :parent => val[3], :line => val[0][:line]
625
result = Puppet::Parser::AST::Hostclass.new(classname(val[1]),
626
ast_context(true).merge(:arguments => val[2], :parent => val[3],
627
:line => val[0][:line]))
695
630
nodedef: NODE hostnames nodeparent LBRACE statements RBRACE {
696
631
@lexer.commentpop
697
newnode val[1], :parent => val[2], :code => val[4], :line => val[0][:line]
632
result = Puppet::Parser::AST::Node.new(val[1],
633
ast_context(true).merge(:parent => val[2], :code => val[4],
634
:line => val[0][:line]))
699
635
} | NODE hostnames nodeparent LBRACE RBRACE {
700
636
@lexer.commentpop
701
newnode val[1], :parent => val[2], :line => val[0][:line]
637
result = Puppet::Parser::AST::Node.new(val[1], ast_context(true).merge(:parent => val[2], :line => val[0][:line]))
705
640
classref: CLASSREF { result = val[0][:value] }
779
715
result = ast AST::Variable, :value => val[0][:value], :line => val[0][:line]
782
array: LBRACK rvalues RBRACK {
783
if val[1].instance_of?(AST::ASTArray)
786
result = ast AST::ASTArray, :children => [val[1]]
789
| LBRACK rvalues COMMA RBRACK {
790
if val[1].instance_of?(AST::ASTArray)
793
result = ast AST::ASTArray, :children => [val[1]]
796
result = ast AST::ASTArray
718
array: LBRACK rvalues RBRACK { result = val[1] }
719
| LBRACK rvalues COMMA RBRACK { result = val[1] }
720
| LBRACK RBRACK { result = ast AST::ASTArray }