~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to lib/puppet/parser/grammar.ra

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
preclow
29
29
 
30
30
rule
31
 
program:    statements {
32
 
  if val[0]
33
 
    # Make sure we always return an array.
34
 
    if val[0].is_a?(AST::ASTArray)
35
 
      if val[0].children.empty?
36
 
        result = nil
37
 
      else
38
 
        result = val[0]
39
 
      end
40
 
    else
41
 
      result = aryfy(val[0])
42
 
    end
43
 
  else
44
 
    result = nil
45
 
  end
46
 
}
 
31
program:    statements_and_declarations
47
32
  | nil
48
33
 
49
 
statements:   statement
50
 
  | statements statement {
51
 
    if val[0] and val[1]
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]] : [])
 
36
  }
 
37
  | statements_and_declarations statement_or_declaration {
 
38
    if val[1]
53
39
      val[0].push(val[1])
54
 
      result = val[0]
55
 
    else
56
 
      result = ast AST::ASTArray, :children => [val[0],val[1]]
57
 
    end
58
 
  elsif obj = (val[0] || val[1])
59
 
    result = obj
60
 
  else result = nil
 
40
    end
 
41
    result = val[0]
 
42
  }
 
43
 
 
44
# statements is like statements_and_declarations, but it doesn't allow
 
45
# nested definitions, classes, or nodes.
 
46
statements: statements_and_declarations {
 
47
  val[0].each do |stmt|
 
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]
 
51
    end
61
52
  end
 
53
  result = val[0]
62
54
}
63
55
 
64
56
# The main list of valid statements
65
 
statement:    resource
 
57
statement_or_declaration:    resource
66
58
  | virtualresource
67
59
  | collection
68
60
  | assignment
89
81
edge: IN_EDGE | OUT_EDGE | IN_EDGE_SUB | OUT_EDGE_SUB
90
82
 
91
83
fstatement:   NAME LPAREN funcvalues RPAREN {
92
 
  args = aryfy(val[2])
93
84
  result = ast AST::Function,
94
85
    :name => val[0][:value],
95
86
    :line => val[0][:line],
96
 
    :arguments => args,
 
87
    :arguments => val[2],
97
88
    :ftype => :statement
98
89
}
99
90
| NAME LPAREN funcvalues COMMA RPAREN {
100
 
  args = aryfy(val[2])
101
91
  result = ast AST::Function,
102
92
    :name => val[0][:value],
103
93
    :line => val[0][:line],
104
 
    :arguments => args,
 
94
    :arguments => val[2],
105
95
    :ftype => :statement
106
96
}            | NAME LPAREN RPAREN {
107
97
  result = ast AST::Function,
111
101
    :ftype => :statement
112
102
}
113
103
  | NAME funcvalues {
114
 
    args = aryfy(val[1])
115
104
    result = ast AST::Function,
116
105
    :name => val[0][:value],
117
106
    :line => val[0][:line],
118
 
    :arguments => args,
 
107
    :arguments => val[1],
119
108
    :ftype => :statement
120
109
}
121
110
 
122
 
funcvalues:       namestring
123
 
  | resourceref
 
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
 
114
    val[0].push(val[2])
 
115
    result = val[0]
128
116
}
129
117
  | funcvalues COMMA resourceref {
130
 
    unless val[0].is_a?(AST::ASTArray)
131
 
    val[0] = aryfy(val[0])
132
 
  end
133
 
 
134
 
  val[0].push(val[2])
135
 
 
136
 
  result = val[0]
 
118
    val[0].push(val[2])
 
119
    result = val[0]
137
120
}
138
121
 
139
122
# This is *almost* an rvalue, but I couldn't get a full
152
135
 
153
136
resource:       classname LBRACE resourceinstances endsemi RBRACE {
154
137
  @lexer.commentpop
155
 
  array = val[2]
156
 
  array = [array] if array.instance_of?(AST::ResourceInstance)
157
 
  result = ast AST::ASTArray
158
 
 
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
164
 
 
165
 
      result.push ast(
166
 
        AST::Resource,
167
 
      :type => val[0],
168
 
      :title => instance[0],
169
 
 
170
 
      :parameters => instance[1])
171
 
  }
 
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"
189
156
virtualresource:  at resource {
190
157
  type = val[0]
191
158
 
192
 
  if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly]
 
159
  if (type == :exported and ! Puppet[:storeconfigs])
193
160
    Puppet.warning addcontext("You cannot collect without storeconfigs being set")
194
161
  end
195
162
 
197
164
 
198
165
  method = type.to_s + "="
199
166
 
200
 
  # Just mark our resources as exported and pass them through.
201
 
  if val[1].instance_of?(AST::ASTArray)
202
 
    val[1].each do |obj|
203
 
      obj.send(method, true)
204
 
    end
205
 
  else
206
 
    val[1].send(method, true)
207
 
  end
 
167
  # Just mark our resource as exported and pass it through.
 
168
  val[1].send(method, true)
208
169
 
209
170
  result = val[1]
210
171
}
227
188
  else
228
189
    args[:form] = val[1]
229
190
  end
230
 
  if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly]
 
191
  if args[:form] == :exported and ! Puppet[:storeconfigs]
231
192
    Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored")
232
193
  end
233
194
  args[:override] = val[3]
247
208
  else
248
209
    args[:form] = val[1]
249
210
  end
250
 
  if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly]
 
211
  if args[:form] == :exported and ! Puppet[:storeconfigs]
251
212
    Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored")
252
213
  end
253
214
  result = ast AST::Collection, args
303
264
  | name
304
265
 
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]
307
268
}
308
269
 
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]]
313
 
  else
314
272
    val[0].push val[2]
315
273
    result = val[0]
316
 
  end
317
274
}
318
275
 
319
276
endsemi:      # nothing
358
315
{
359
316
  result = ast AST::ASTArray
360
317
}
361
 
  | param { result = val[0] }
 
318
  | param { result = aryfy(val[0]) }
362
319
  | params COMMA param {
363
 
    if val[0].instance_of?(AST::ASTArray)
364
320
    val[0].push(val[2])
365
321
    result = val[0]
366
 
  else
367
 
    result = ast AST::ASTArray, :children => [val[0],val[2]]
368
 
  end
369
322
}
370
323
 
371
324
param:        NAME FARROW rvalue {
384
337
{
385
338
  result = ast AST::ASTArray
386
339
}
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])
391
343
    result = val[0]
392
 
  else
393
 
    result = ast AST::ASTArray, :children => [val[0],val[2]]
394
 
  end
395
344
}
396
345
 
397
 
rvalues:      rvalue
398
 
  | rvalues comma rvalue {
399
 
    if val[0].instance_of?(AST::ASTArray)
400
 
    result = val[0].push(val[2])
401
 
  else
402
 
    result = ast AST::ASTArray, :children => [val[0],val[2]]
403
 
  end
404
 
}
 
346
rvalues: rvalue               { result = aryfy(val[0]) }
 
347
       | rvalues comma rvalue { result = val[0].push(val[2]) }
405
348
 
406
349
simplervalue:       quotedtext
407
350
  | name
425
368
 
426
369
# We currently require arguments in these functions.
427
370
funcrvalue:   NAME LPAREN funcvalues RPAREN {
428
 
  args = aryfy(val[2])
429
371
  result = ast AST::Function,
430
372
    :name => val[0][:value], :line => val[0][:line],
431
 
    :arguments => args,
 
373
    :arguments => val[2],
432
374
    :ftype => :rvalue
433
375
}           | NAME LPAREN RPAREN {
434
376
  result = ast AST::Function,
572
514
 
573
515
casestatement:  CASE rvalue LBRACE caseopts RBRACE {
574
516
  @lexer.commentpop
575
 
  options = val[3]
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]
578
518
}
579
519
 
580
 
caseopts:     caseopt
 
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]
584
523
    result = val[0]
585
 
  else
586
 
    result = ast AST::ASTArray, :children => [val[0], val[1]]
587
 
  end
588
524
}
589
525
 
590
526
caseopt:        casevalues COLON LBRACE statements RBRACE {
601
537
  )
602
538
}
603
539
 
604
 
casevalues:       selectlhand
 
540
casevalues:       selectlhand { result = aryfy(val[0]) }
605
541
  | casevalues COMMA selectlhand {
606
 
    if val[0].instance_of?(AST::ASTArray)
607
542
    val[0].push(val[2])
608
543
    result = val[0]
609
 
  else
610
 
    result = ast AST::ASTArray, :children => [val[0],val[2]]
611
 
  end
612
544
}
613
545
 
614
546
selector:     selectlhand QMARK svalues {
658
590
    import(file)
659
591
  end
660
592
 
661
 
  result = AST::ASTArray.new(:children => [])
 
593
  result = nil
662
594
}
663
595
 
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
670
 
  result = nil
671
604
 
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
677
 
  result = nil
678
611
}
679
612
 
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.
684
617
  @lexer.namepop
685
 
  newclass classname(val[1]), :arguments => val[2], :parent => val[3], :code => val[5], :line => val[0][:line]
686
 
  result = nil
 
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.
690
624
  @lexer.namepop
691
 
  newclass classname(val[1]), :arguments => val[2], :parent => val[3], :line => val[0][:line]
692
 
  result = nil
 
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]))
693
628
}
694
629
 
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]
698
 
  result = nil
 
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]
702
 
  result = nil
 
637
  result = Puppet::Parser::AST::Node.new(val[1], ast_context(true).merge(:parent => val[2], :line => val[0][:line]))
703
638
}
704
639
 
705
640
classref:       CLASSREF { result = val[0][:value] }
710
645
 
711
646
# Multiple hostnames, as used for node names.  These are all literal
712
647
# strings, not AST objects.
713
 
hostnames:    nodename
 
648
hostnames:    nodename {
 
649
    result = [result]
 
650
}
714
651
  | hostnames COMMA nodename {
715
652
    result = val[0]
716
 
    result = [result] unless result.is_a?(Array)
717
653
    result << val[2]
718
654
}
719
655
 
779
715
  result = ast AST::Variable, :value => val[0][:value], :line => val[0][:line]
780
716
}
781
717
 
782
 
array:        LBRACK rvalues RBRACK {
783
 
  if val[1].instance_of?(AST::ASTArray)
784
 
    result = val[1]
785
 
  else
786
 
    result = ast AST::ASTArray, :children => [val[1]]
787
 
  end
788
 
}
789
 
  | LBRACK rvalues COMMA RBRACK {
790
 
    if val[1].instance_of?(AST::ASTArray)
791
 
    result = val[1]
792
 
  else
793
 
    result = ast AST::ASTArray, :children => [val[1]]
794
 
  end
795
 
}           | LBRACK RBRACK {
796
 
  result = ast AST::ASTArray
797
 
}
 
718
array: LBRACK rvalues       RBRACK { result = val[1] }
 
719
     | LBRACK rvalues COMMA RBRACK { result = val[1] }
 
720
     | LBRACK               RBRACK { result = ast AST::ASTArray }
798
721
 
799
722
comma:        FARROW
800
723
  | COMMA