Class: RLSM::RegExp
- Inherits:
-
Object
- Object
- RLSM::RegExp
- Defined in:
- lib/rlsm/regexp.rb
Instance Attribute Summary collapse
-
#parse_tree ⇒ Object
readonly
Returns the value of attribute parse_tree.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Class Method Summary collapse
-
.[](description) ⇒ Object
Synonym for new.
-
.empty_set ⇒ Object
Returns a RegExp which represents the empty language.
-
.empty_word ⇒ Object
Returns a RegExp which is the empty word.
Instance Method Summary collapse
-
#+(other) ⇒ Object
Concatenate
self
withother
. -
#==(other) ⇒ Object
Checks if
self
is equal toother
, i.e. -
#initialize(description) ⇒ RegExp
constructor
Creates a new RegExp.
-
#star ⇒ Object
Returns the Kleene closure of
self
. -
#to_dfa ⇒ Object
Calculates a minimal DFA which represents the same languge as
self
. -
#to_monoid ⇒ Object
Calculates the syntactic monoid of the represented language.
-
#to_regexp ⇒ Object
Simply returns self.
-
#|(other) ⇒ Object
Returns the union of
self
andother
.
Constructor Details
#initialize(description) ⇒ RegExp
Creates a new RegExp. The description
is a string consiting of latin letters, numbers and the following special characters
-
(, ) for grouping subexpressions
-
| for union of regular expressions
-
* for the Kleene-Closure of a regular expression
-
@ the empty word.
Whitspaces will be ignored and the empty string represents the empty language.
30 31 32 33 |
# File 'lib/rlsm/regexp.rb', line 30 def initialize(description) @parse_tree = RLSM::RE::Parser[ description ] @string = @parse_tree.to_s end |
Instance Attribute Details
#parse_tree ⇒ Object (readonly)
Returns the value of attribute parse_tree.
35 36 37 |
# File 'lib/rlsm/regexp.rb', line 35 def parse_tree @parse_tree end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
35 36 37 |
# File 'lib/rlsm/regexp.rb', line 35 def string @string end |
Class Method Details
.[](description) ⇒ Object
Synonym for new.
19 20 21 |
# File 'lib/rlsm/regexp.rb', line 19 def self.[](description) new(description) end |
.empty_set ⇒ Object
Returns a RegExp which represents the empty language.
14 15 16 |
# File 'lib/rlsm/regexp.rb', line 14 def self.empty_set new '' end |
.empty_word ⇒ Object
Returns a RegExp which is the empty word.
9 10 11 |
# File 'lib/rlsm/regexp.rb', line 9 def self.empty_word new RLSM::RE::ParserHelpers::EmptyWordSymbol end |
Instance Method Details
#+(other) ⇒ Object
Concatenate self
with other
.
38 39 40 |
# File 'lib/rlsm/regexp.rb', line 38 def +(other) RLSM::RegExp.new "(#@string)(#{other.string})" end |
#==(other) ⇒ Object
Checks if self
is equal to other
, i.e. they represent the same language.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rlsm/regexp.rb', line 68 def ==(other) return true if @string == other.string first = @parse_tree.first.map { |pos| pos.to_s }.uniq other_first = other.parse_tree.first.map { |pos| pos.to_s }.uniq return false if first != other_first last = @parse_tree.last.map { |pos| pos.to_s }.uniq other_last = other.parse_tree.last.map { |pos| pos.to_s }.uniq return false if last != other_last to_dfa =~ other.to_dfa end |
#star ⇒ Object
Returns the Kleene closure of self
.
48 49 50 |
# File 'lib/rlsm/regexp.rb', line 48 def star RLSM::RegExp.new "(#@string)*" end |
#to_dfa ⇒ Object
Calculates a minimal DFA which represents the same languge as self
.
53 54 55 |
# File 'lib/rlsm/regexp.rb', line 53 def to_dfa RLSM::DFA.new(subset_construction).minimize! end |
#to_monoid ⇒ Object
Calculates the syntactic monoid of the represented language.
63 64 65 |
# File 'lib/rlsm/regexp.rb', line 63 def to_monoid to_dfa.to_monoid end |
#to_regexp ⇒ Object
Simply returns self.
58 59 60 |
# File 'lib/rlsm/regexp.rb', line 58 def to_regexp self end |