Class: Plurimath::UnicodeMath::Parser

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

Constant Summary collapse

LABELED_TR_REGEX =
/"([^"]*(#|#|\\\\eqno)[^"]*[^"]*|[^"]*(#|#|\\\\eqno)[^"]*[^"]*)"/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Parser

Returns a new instance of Parser.



15
16
17
18
19
20
21
22
23
24
# File 'lib/plurimath/unicode_math/parser.rb', line 15

def initialize(text)
  text = pre_processing(text)
  @text = HTMLEntities.new.encode(text, :hexadecimal)
  @text = @text.gsub("&", "&")
  @text = @text.gsub(""", "\"")
  @text = @text.gsub(/⫷.*⫸/, "")
  @text = @text.gsub(/\\\\/, "\\")
  @text = @text.gsub(/\\u([\da-fA-F]{1,5})\w{0,5}/) { "&#x#{$1};" } # Converting \u#{xxxx} encoding to &#x#{xxxx};
  @text = @text.strip
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



11
12
13
# File 'lib/plurimath/unicode_math/parser.rb', line 11

def text
  @text
end

Instance Method Details

#parseObject



26
27
28
29
30
31
32
33
34
# File 'lib/plurimath/unicode_math/parser.rb', line 26

def parse
  tree = Parse.new.parse(text)
  tree = post_processing(tree) if @splitted
  Math::Formula.new(
    Array(
      Transform.new.apply(tree),
    ),
  )
end