diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-07-26 13:44:06 +0200 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-08-01 11:15:28 +1000 |
commit | 0ccd2590b2bf0494388c4656759b47612776bc53 (patch) | |
tree | 75371d2b34bb055d8d06a235d33fefe0530dcbfa /lib/puppet/parser/lexer.rb | |
parent | 201ae59eacaff289a8a5bb45f7d301c1a490a119 (diff) | |
download | puppet-0ccd2590b2bf0494388c4656759b47612776bc53.tar.gz puppet-0ccd2590b2bf0494388c4656759b47612776bc53.tar.xz puppet-0ccd2590b2bf0494388c4656759b47612776bc53.zip |
Add regex, match and not match token to the lexer
The lexer recognizes regex delimited by / as in:
/^$/
The match operator is defined by =~
The not match operator is defined by !~
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet/parser/lexer.rb')
-rw-r--r-- | lib/puppet/parser/lexer.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb index 5bab6d65d..56863a2fc 100644 --- a/lib/puppet/parser/lexer.rb +++ b/lib/puppet/parser/lexer.rb @@ -134,6 +134,8 @@ class Puppet::Parser::Lexer '*' => :TIMES, '<<' => :LSHIFT, '>>' => :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 ) @@ -169,6 +171,11 @@ class Puppet::Parser::Lexer [self,value] end + TOKENS.add_token :REGEX, %r{/(.*?)/} do |lexer, value| + value.sub!(/^\/(.*?)\/$/,"\\1") + [self, Regexp.new(value)] + end + TOKENS.add_token :RETURN, "\n", :skip => true, :incr_line => true, :skip_text => true TOKENS.add_token :SQUOTE, "'" do |lexer, value| |