Class: ABNF::Compiler::Rule::TerminalValue
- Inherits:
-
Object
- Object
- ABNF::Compiler::Rule::TerminalValue
- Includes:
- ABNF::Compiler::Rule
- Defined in:
- lib/abnf/compiler/rule/terminal_value.rb
Instance Attribute Summary collapse
-
#case_sensitive ⇒ Object
readonly
Returns the value of attribute case_sensitive.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
-
#initialize(string, case_sensitive = false) ⇒ TerminalValue
constructor
A new instance of TerminalValue.
- #parse(stream) ⇒ Object
- #regexp ⇒ Object
Methods included from ABNF::Compiler::Rule
Constructor Details
#initialize(string, case_sensitive = false) ⇒ TerminalValue
Returns a new instance of TerminalValue.
10 11 12 13 |
# File 'lib/abnf/compiler/rule/terminal_value.rb', line 10 def initialize string, case_sensitive = false @string = string @case_sensitive = case_sensitive end |
Instance Attribute Details
#case_sensitive ⇒ Object (readonly)
Returns the value of attribute case_sensitive.
7 8 9 |
# File 'lib/abnf/compiler/rule/terminal_value.rb', line 7 def case_sensitive @case_sensitive end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
8 9 10 |
# File 'lib/abnf/compiler/rule/terminal_value.rb', line 8 def string @string end |
Instance Method Details
#parse(stream) ⇒ Object
15 16 17 18 19 |
# File 'lib/abnf/compiler/rule/terminal_value.rb', line 15 def parse stream match_data = stream.match regexp return unless match_data AST.leaf match_data.to_s end |
#regexp ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/abnf/compiler/rule/terminal_value.rb', line 21 def regexp @regexp ||= begin escaped_string = Regexp.escape string case_insensitive = !case_sensitive Regexp.new escaped_string, case_insensitive, 'n'.freeze end end |