~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to lib/puppet/external/nagios/grammar.ry

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
rule
7
7
decls: decl { return val[0] if val[0] }
8
 
        | decls decl {
9
 
                if val[1].nil?
10
 
                        result = val[0]
11
 
                else
12
 
                        if val[0].nil?
13
 
                                result = val[1]
14
 
                        else
15
 
                                result = [ val[0], val[1] ].flatten
16
 
                        end
17
 
                end
18
 
        }
19
 
        ;
 
8
    | decls decl {
 
9
        if val[1].nil?
 
10
            result = val[0]
 
11
        else
 
12
            if val[0].nil?
 
13
                result = val[1]
 
14
            else
 
15
                result = [ val[0], val[1] ].flatten
 
16
            end
 
17
        end
 
18
    }
 
19
    ;
20
20
 
21
21
decl: object { result = [val[0]] }
22
 
        | RETURN { result = nil }
23
 
        | comment
24
 
        ;
25
 
        
 
22
    | RETURN { result = nil }
 
23
    | comment
 
24
    ;
 
25
 
26
26
comment: COMMENT RETURN { result = nil }
27
 
        ;
 
27
    ;
28
28
 
29
29
object: DEFINE NAME LCURLY RETURN vars RCURLY {
30
 
                result = Nagios::Base.create(val[1],val[4])
31
 
        }
32
 
        ;
 
30
        result = Nagios::Base.create(val[1],val[4])
 
31
    }
 
32
    ;
33
33
 
34
34
vars: var
35
 
        | vars var {
36
 
                val[1].each {|p,v|
37
 
                        val[0][p] = v
38
 
                }
39
 
                result = val[0]
40
 
        }
41
 
        ;
 
35
    | vars var {
 
36
        val[1].each {|p,v|
 
37
            val[0][p] = v
 
38
        }
 
39
        result = val[0]
 
40
    }
 
41
    ;
42
42
 
43
43
var: PARAM VALUE icomment returns { result = {val[0],val[1]} }
44
 
        ;
 
44
    ;
45
45
 
46
46
returns:      RETURN
47
47
            | returns RETURN
48
48
            ;
49
49
 
50
50
icomment: # nothing
51
 
        | INLINECOMMENT
52
 
        ;
 
51
    | INLINECOMMENT
 
52
    ;
53
53
 
54
54
end
55
55
 
58
58
class ::Nagios::Parser::SyntaxError < RuntimeError; end
59
59
 
60
60
def parse(src)
61
 
        @src = src
62
 
 
63
 
        # state variables
64
 
        @invar = false
65
 
        @inobject = false
66
 
        @done = false
67
 
 
68
 
        @line = 0
69
 
        @yydebug = true
 
61
    @src = src
 
62
 
 
63
    # state variables
 
64
    @invar = false
 
65
    @inobject = false
 
66
    @done = false
 
67
 
 
68
    @line = 0
 
69
    @yydebug = true
70
70
 
71
71
    do_parse
72
72
end
73
73
 
74
74
# The lexer.  Very simple.
75
75
def token
76
 
        @src.sub!(/\A\n/,'')
77
 
        if $&
78
 
                @line += 1
79
 
                return [ :RETURN, "\n" ]
80
 
        end
81
 
 
82
 
        if @done
83
 
                return nil
84
 
        end
85
 
        yytext = String.new
86
 
 
87
 
 
88
 
        # remove comments from this line
89
 
        @src.sub!(/\A[ \t]*;.*\n/,"\n")
90
 
        if $&
91
 
                return [:INLINECOMMENT, ""]
92
 
        end
93
 
 
94
 
        @src.sub!(/\A#.*\n/,"\n")
95
 
        if $&
96
 
                return [:COMMENT, ""]
97
 
        end
98
 
 
99
 
        @src.sub!(/#.*/,'')
100
 
 
101
 
        if @src.length == 0
102
 
                @done = true
103
 
                return [false, '$']
104
 
        end
105
 
 
106
 
        if @invar
107
 
                @src.sub!(/\A[ \t]+/,'')
108
 
                @src.sub!(/\A([^;\n]+)(\n|;)/,'\2')
109
 
                if $1
110
 
                        yytext += $1
111
 
                end
112
 
                @invar = false
113
 
                return [:VALUE, yytext]
114
 
        else
115
 
                @src.sub!(/\A[\t ]*(\S+)([\t ]*|$)/,'')
 
76
    @src.sub!(/\A\n/,'')
 
77
    if $&
 
78
        @line += 1
 
79
        return [ :RETURN, "\n" ]
 
80
    end
 
81
 
 
82
    if @done
 
83
        return nil
 
84
    end
 
85
    yytext = String.new
 
86
 
 
87
 
 
88
    # remove comments from this line
 
89
    @src.sub!(/\A[ \t]*;.*\n/,"\n")
 
90
    if $&
 
91
        return [:INLINECOMMENT, ""]
 
92
    end
 
93
 
 
94
    @src.sub!(/\A#.*\n/,"\n")
 
95
    if $&
 
96
        return [:COMMENT, ""]
 
97
    end
 
98
 
 
99
    @src.sub!(/#.*/,'')
 
100
 
 
101
    if @src.length == 0
 
102
        @done = true
 
103
        return [false, '$']
 
104
    end
 
105
 
 
106
    if @invar
 
107
        @src.sub!(/\A[ \t]+/,'')
 
108
        @src.sub!(/\A([^;\n]+)(\n|;)/,'\2')
 
109
        if $1
 
110
            yytext += $1
 
111
        end
 
112
        @invar = false
 
113
        return [:VALUE, yytext]
 
114
    else
 
115
        @src.sub!(/\A[\t ]*(\S+)([\t ]*|$)/,'')
116
116
        if $1
117
117
            yytext = $1
118
118
            case yytext
152
152
                end
153
153
            end
154
154
        end
155
 
        end
 
155
    end
156
156
end
157
157
 
158
158
def next_token
159
 
        token
 
159
    token
160
160
end
161
161
 
162
162
def yydebug
168
168
end
169
169
 
170
170
def on_error(token, value, vstack )
171
 
        msg = ""
172
 
        unless value.nil?
173
 
                msg = "line #{@line}: syntax error at '#{value}'"
174
 
        else
175
 
                msg = "line #{@line}: syntax error at '#{token}'"
176
 
        end
177
 
        unless @src.size > 0
178
 
                msg = "line #{@line}: Unexpected end of file"
179
 
        end
180
 
        if token == '$end'.intern
181
 
                puts "okay, this is silly"
182
 
        else
183
 
                raise ::Nagios::Parser::SyntaxError, msg
184
 
        end
 
171
    msg = ""
 
172
    unless value.nil?
 
173
        msg = "line #{@line}: syntax error at '#{value}'"
 
174
    else
 
175
        msg = "line #{@line}: syntax error at '#{token}'"
 
176
    end
 
177
    unless @src.size > 0
 
178
        msg = "line #{@line}: Unexpected end of file"
 
179
    end
 
180
    if token == '$end'.intern
 
181
        puts "okay, this is silly"
 
182
    else
 
183
        raise ::Nagios::Parser::SyntaxError, msg
 
184
    end
185
185
end