Class: RLSM::RE::Parser
- Inherits:
-
Object
- Object
- RLSM::RE::Parser
- Extended by:
- ParserHelpers
- Defined in:
- lib/rlsm/regexp_parser.rb
Overview
:nodoc:
Constant Summary
Constants included from ParserHelpers
RLSM::RE::ParserHelpers::CloseBracket, RLSM::RE::ParserHelpers::EmptyWordSymbol, RLSM::RE::ParserHelpers::LetterRegexp, RLSM::RE::ParserHelpers::OpenBracket, RLSM::RE::ParserHelpers::StarSymbol, RLSM::RE::ParserHelpers::UnionSymbol
Class Method Summary collapse
Methods included from ParserHelpers
close_bracket?, empty_set?, empty_symbol?, empty_word?, letter?, open_bracket?, single_letter?, star?, star_symbol?, union?, union_symbol?
Class Method Details
.[](string) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rlsm/regexp_parser.rb', line 115 def self.[](string) index = -1 input = string.gsub(/\s+/,'').scan(/./).map do |char| letter?(char) ? Position.new(char,index += 1) : Position.new(char) end if unbalanced_brackets?(input) raise RLSM::Error, "Parse Error: Unbalanced brackets." end parse(input) end |
.parse(input) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/rlsm/regexp_parser.rb', line 128 def self.parse(input) input = remove_surrounding_brackets(input) if empty_set?(input) EmptySet[] elsif empty_word?(input) EmptyWord[] elsif single_letter?(input) Prim[ input.first ] elsif star?(input) create_star_node( input ) elsif union?(input) create_union_node(input) else #must be a concat create_concat_node(input) end end |