summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/lexer.rb
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-05-12 15:40:08 -0700
committerNick Lewis <nick@puppetlabs.com>2011-05-17 14:54:43 -0700
commit3ac7aede7233e0554077f7abbf6e561960a05e4d (patch)
tree6d60a694bfe85a01a53b1314d4f6c6d9363f99e8 /lib/puppet/parser/lexer.rb
parent99d437d2bbc2339f092304715ec562fbbcb0a50c (diff)
downloadpuppet-3ac7aede7233e0554077f7abbf6e561960a05e4d.tar.gz
puppet-3ac7aede7233e0554077f7abbf6e561960a05e4d.tar.xz
puppet-3ac7aede7233e0554077f7abbf6e561960a05e4d.zip
(#7523) Refactor the grammar to reduce duplication
This commit unifies some paths in the grammar, which had previously been duplicated to avoid shift/reduce conflicts. Merging these paths together and separating only the conflicting structures leads to a cleaner grammar, with fewer holes. Several bugs are fixed as a result: (#3129) Nested class names beginning with numbers work correctly (#5268) Hyphens in class names work correctly (#5817) Hashes and arrays can now be passed to functions (hashes require parentheses) Additionally, expressions are now legal in most places where they would make sense, when previously only bare rvalues were allowed. Paired-With: Markus Roberts Reviewed-By: Matt Robinson
Diffstat (limited to 'lib/puppet/parser/lexer.rb')
-rw-r--r--lib/puppet/parser/lexer.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index 2f416615e..cb1ff4536 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -152,7 +152,6 @@ class Puppet::Parser::Lexer
'>>' => :RSHIFT,
'=~' => :MATCH,
'!~' => :NOMATCH,
- %r{([a-z][-\w]*)?(::[a-z][-\w]*)+} => :CLASSNAME, # Require '::' in the class name, else we'd compete with NAME
%r{((::){0,1}[A-Z][-\w]*)+} => :CLASSREF,
"<string>" => :STRING,
"<dqstring up to first interpolation>" => :DQPRE,
@@ -161,6 +160,7 @@ class Puppet::Parser::Lexer
"<boolean>" => :BOOLEAN
)
+ # Numbers are treated separately from names, so that they may contain dots.
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
@@ -170,7 +170,7 @@ class Puppet::Parser::Lexer
end
#:startdoc:
- TOKENS.add_token :NAME, %r{[a-z0-9][-\w]*} do |lexer, value|
+ TOKENS.add_token :NAME, %r{((::)?[a-z0-9][-\w]*)(::[a-z0-9][-\w]*)*} do |lexer, value|
string_token = self
# we're looking for keywords here
if tmp = KEYWORDS.lookup(value)
@@ -240,11 +240,11 @@ class Puppet::Parser::Lexer
end
#:startdoc:
- TOKENS.add_token :DOLLAR_VAR, %r{\$(\w*::)*\w+} do |lexer, value|
+ TOKENS.add_token :DOLLAR_VAR, %r{\$(::)?([-\w]+::)*[-\w]+} do |lexer, value|
[TOKENS[:VARIABLE],value[1..-1]]
end
- TOKENS.add_token :VARIABLE, %r{(\w*::)*\w+}
+ TOKENS.add_token :VARIABLE, %r{(::)?([-\w]+::)*[-\w]+}
#:stopdoc: # Issue #4161
def (TOKENS[:VARIABLE]).acceptable?(context={})
[:DQPRE,:DQMID].include? context[:after]
@@ -549,7 +549,7 @@ class Puppet::Parser::Lexer
token_queue << [TOKENS[token_type[terminator]],preamble+value]
if terminator != '$' or @scanner.scan(/\{/)
token_queue.shift
- elsif var_name = @scanner.scan(%r{(\w*::)*\w+|[0-9]})
+ elsif var_name = @scanner.scan(TOKENS[:VARIABLE].regex)
token_queue << [TOKENS[:VARIABLE],var_name]
tokenize_interpolated_string(DQ_continuation_token_types)
else