lib/radius/parser.rb in radius-ts-1.0.0 vs lib/radius/parser.rb in radius-ts-1.1.0

- old
+ new

@@ -9,19 +9,23 @@ attr_accessor :context # The string that prefixes all tags that are expanded by a parser # (the part in the tag name before the first colon). attr_accessor :tag_prefix + + # The class that performs tokenization of the input string + attr_accessor :scanner # Creates a new parser object initialized with a Context. def initialize(context = Context.new, options = {}) if context.kind_of?(Hash) and options.empty? options, context = context, (context[:context] || context['context']) end options = Utility.symbolize_keys(options) self.context = context ? context.dup : Context.new self.tag_prefix = options[:tag_prefix] || 'radius' + self.scanner = options[:scanner] || Radius::Scanner.new end # Parses string for tags, expands them, and returns the result. def parse(string) @stack = [ParseContainerTag.new { |t| t.contents.to_s }] @@ -31,10 +35,10 @@ end protected # Convert the string into a list of text blocks and scanners (tokens) def tokenize(string) - @tokens = Scanner.new.operate(tag_prefix, string) + @tokens = scanner.operate(tag_prefix, string) end def stack_up @tokens.each do |t| if t.is_a? String