summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/lexer.rb
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-09-26 23:03:39 +0200
committerJames Turnbull <james@lovedthanlost.net>2008-10-01 01:35:03 +1000
commit4cf9710bd27fdb5f0720f4d8478ef940e7c4ba59 (patch)
treee2db8d91c8e1d45bb9413899ff6566a712264b0a /lib/puppet/parser/lexer.rb
parentcfa230a2d7b0c5e57cc0379785bd2025520f1c35 (diff)
downloadpuppet-4cf9710bd27fdb5f0720f4d8478ef940e7c4ba59.tar.gz
puppet-4cf9710bd27fdb5f0720f4d8478ef940e7c4ba59.tar.xz
puppet-4cf9710bd27fdb5f0720f4d8478ef940e7c4ba59.zip
Add parser for arbitrary expressions
The expressions can be used in if 'test' and in the right side of assignements. The expressions can contain any number of sub-expressions combined by either arithmetic operators, comparison operators, or boolean operators. Random Usage Examples: $result = ((( $two + 2) / $one) + 4 * 5.45) - (6 << 7) + (0x800 + -9) or if ($a < 10) and ($a + 10 != 200) { ... }
Diffstat (limited to 'lib/puppet/parser/lexer.rb')
-rw-r--r--lib/puppet/parser/lexer.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index 71210d919..5dd036e52 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -126,12 +126,22 @@ class Puppet::Parser::Lexer
'\\' => :BACKSLASH,
'=>' => :FARROW,
'+>' => :PARROW,
+ '+' => :PLUS,
+ '-' => :MINUS,
+ '/' => :DIV,
+ '*' => :TIMES,
+ '<<' => :LSHIFT,
+ '>>' => :RSHIFT,
%r{([a-z][-\w]*::)+[a-z][-\w]*} => :CLASSNAME,
%r{((::){0,1}[A-Z][-\w]*)+} => :CLASSREF
)
TOKENS.add_tokens "Whatever" => :DQTEXT, "Nomatter" => :SQTEXT, "alsonomatter" => :BOOLEAN
+ TOKENS.add_token :NUMBER, %r{\b(?:0[xX][0-9A-Fa-f]+|0?\d+(?:\.\d+)?(?:[eE]-?\d+)?)\b} do |lexer, value|
+ [TOKENS[:NAME], value]
+ end
+
TOKENS.add_token :NAME, %r{[a-z0-9][-\w]*} do |lexer, value|
string_token = self
# we're looking for keywords here
@@ -145,10 +155,6 @@ class Puppet::Parser::Lexer
[string_token, value]
end
- TOKENS.add_token :NUMBER, %r{[0-9]+} do |lexer, value|
- [TOKENS[:NAME], value]
- end
-
TOKENS.add_token :COMMENT, %r{#.*}, :skip => true
TOKENS.add_token :RETURN, "\n", :skip => true, :incr_line => true, :skip_text => true