Class: Plurimath::Asciimath::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/asciimath/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Parser

Returns a new instance of Parser.



11
12
13
14
15
16
17
18
# File 'lib/plurimath/asciimath/parser.rb', line 11

def initialize(text)
  @text = text
            &.gsub(/(\|:|:\|)/, "|")
            &.gsub(/(\{:)/, "")
            &.gsub(/(:\})/, "")
            &.gsub(/(\(:)/, "")
            &.gsub(/(:\))/, "")
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



9
10
11
# File 'lib/plurimath/asciimath/parser.rb', line 9

def text
  @text
end

Instance Method Details

#parseObject



20
21
22
23
24
25
26
# File 'lib/plurimath/asciimath/parser.rb', line 20

def parse
  nodes = Parse.new.parse(text)
  transformed_tree = Transform.new.apply(nodes)
  return transformed_tree if transformed_tree.is_a?(Math::Formula)

  Math::Formula.new(transformed_tree)
end