#-- # DO NOT MODIFY!!!! # This file is automatically generated by rex 1.0.2 # from lexical definition file "lib/puppetdb/lexer.l". #++ require 'racc/parser' # vim: syntax=ruby require 'yaml' module PuppetDB class Lexer < Racc::Parser require 'strscan' class ScanError < StandardError ; end attr_reader :lineno attr_reader :filename def scan_setup ; end def action &block yield end def scan_str( str ) scan_evaluate str do_parse end def load_file( filename ) @filename = filename open(filename, "r") do |f| scan_evaluate f.read end end def scan_file( filename ) load_file filename do_parse end def next_token @rex_tokens.shift end def scan_evaluate( str ) scan_setup @rex_tokens = [] @lineno = 1 ss = StringScanner.new(str) state = nil until ss.eos? text = ss.peek(1) @lineno += 1 if text == "\n" case state when nil case when (text = ss.scan(/\s/)) ; when (text = ss.scan(/\(/)) @rex_tokens.push action { [:LPAREN, text] } when (text = ss.scan(/\)/)) @rex_tokens.push action { [:RPAREN, text] } when (text = ss.scan(/\[/)) @rex_tokens.push action { [:LBRACK, text] } when (text = ss.scan(/\]/)) @rex_tokens.push action { [:RBRACK, text] } when (text = ss.scan(/\{/)) @rex_tokens.push action { [:LBRACE, text] } when (text = ss.scan(/\}/)) @rex_tokens.push action { [:RBRACE, text] } when (text = ss.scan(/=/)) @rex_tokens.push action { [:EQUALS, text] } when (text = ss.scan(/\!=/)) @rex_tokens.push action { [:NOTEQUALS, text] } when (text = ss.scan(/~/)) @rex_tokens.push action { [:MATCH, text] } when (text = ss.scan(//)) @rex_tokens.push action { [:GREATERTHAN, text] } when (text = ss.scan(/not(?![\w_:])/)) @rex_tokens.push action { [:NOT, text] } when (text = ss.scan(/and(?![\w_:])/)) @rex_tokens.push action { [:AND, text] } when (text = ss.scan(/or(?![\w_:])/)) @rex_tokens.push action { [:OR, text] } when (text = ss.scan(/true(?![\w_:])/)) @rex_tokens.push action { [:BOOLEAN, true]} when (text = ss.scan(/false(?![\w_:])/)) @rex_tokens.push action { [:BOOLEAN, false]} when (text = ss.scan(/-?\d+\.\d+/)) @rex_tokens.push action { [:NUMBER, text.to_f] } when (text = ss.scan(/-?\d+/)) @rex_tokens.push action { [:NUMBER, text.to_i] } when (text = ss.scan(/\"(\\.|[^\\"])*\"/)) @rex_tokens.push action { [:STRING, YAML.load(text)] } when (text = ss.scan(/[\w_:]+/)) @rex_tokens.push action { [:STRING, text] } when (text = ss.scan(/@@/)) @rex_tokens.push action { [:EXPORTED, text] } else text = ss.string[ss.pos .. -1] raise ScanError, "can not match: '" + text + "'" end # if else raise ScanError, "undefined state: '" + state.to_s + "'" end # case state end # until ss end # def scan_evaluate end # class end # module