Class: Radius::Parser
- Inherits:
-
Object
- Object
- Radius::Parser
- Defined in:
- lib/radius/parser.rb
Overview
The Radius parser. Initialize a parser with a Context object that defines how tags should be expanded. See the QUICKSTART for a detailed explaination of its usage.
Instance Attribute Summary collapse
-
#context ⇒ Object
The Context object used to expand template tags.
-
#scanner ⇒ Object
The class that performs tokenization of the input string.
-
#tag_prefix ⇒ Object
The string that prefixes all tags that are expanded by a parser (the part in the tag name before the first colon).
Instance Method Summary collapse
-
#initialize(context = Context.new, options = {}) ⇒ Parser
constructor
Creates a new parser object initialized with a Context.
-
#parse(string) ⇒ Object
Parses string for tags, expands them, and returns the result.
Constructor Details
#initialize(context = Context.new, options = {}) ⇒ Parser
Creates a new parser object initialized with a Context.
19 20 21 22 23 24 25 26 27 |
# File 'lib/radius/parser.rb', line 19 def initialize(context = Context.new, = {}) if context.kind_of?(Hash) and .empty? , context = context, (context[:context] || context['context']) end = Utility.symbolize_keys() self.context = context ? context.dup : Context.new self.tag_prefix = [:tag_prefix] || 'radius' self.scanner = [:scanner] || default_scanner end |
Instance Attribute Details
#context ⇒ Object
The Context object used to expand template tags.
9 10 11 |
# File 'lib/radius/parser.rb', line 9 def context @context end |
#scanner ⇒ Object
The class that performs tokenization of the input string
16 17 18 |
# File 'lib/radius/parser.rb', line 16 def scanner @scanner end |
#tag_prefix ⇒ Object
The string that prefixes all tags that are expanded by a parser (the part in the tag name before the first colon).
13 14 15 |
# File 'lib/radius/parser.rb', line 13 def tag_prefix @tag_prefix end |
Instance Method Details
#parse(string) ⇒ Object
Parses string for tags, expands them, and returns the result.
30 31 32 33 34 35 |
# File 'lib/radius/parser.rb', line 30 def parse(string) @stack = [ ParseContainerTag.new { |t| Utility.array_to_s(t.contents) } ] tokenize(string) stack_up @stack.last.to_s end |