Class: Plurimath::Asciimath::Parse
- Inherits:
-
Parslet::Parser
- Object
- Parslet::Parser
- Plurimath::Asciimath::Parse
- Defined in:
- lib/plurimath/asciimath/parse.rb
Instance Method Summary collapse
- #arr_to_expression(arr, name = nil) ⇒ Object
- #dynamic_parser_rules(expr) ⇒ Object
- #hash_to_expression(arr) ⇒ Object
- #read_text ⇒ Object
Instance Method Details
#arr_to_expression(arr, name = nil) ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/plurimath/asciimath/parse.rb', line 165 def arr_to_expression(arr, name = nil) type = arr.first.class arr.reduce do |expression, expr_string| expression = str(expression).as(name) if expression.is_a?(type) expression | str(expr_string).as(name) end end |
#dynamic_parser_rules(expr) ⇒ Object
188 189 190 191 192 193 194 195 196 |
# File 'lib/plurimath/asciimath/parse.rb', line 188 def dynamic_parser_rules(expr) first_value = str(expr.first.to_s) case expr.last when :symbol then first_value.as(:symbol) when :unary_class then (first_value.as(:unary_class) >> space? >> sequence.maybe).as(:unary) when :fonts then first_value.as(:fonts_class) >> space? >> sequence.as(:fonts_value) when :special_fonts then first_value.as(:bold_fonts) end end |
#hash_to_expression(arr) ⇒ Object
180 181 182 183 184 185 186 |
# File 'lib/plurimath/asciimath/parse.rb', line 180 def hash_to_expression(arr) type = arr.first.class @@expression ||= arr.reduce do |expression, expr_string| expression = dynamic_parser_rules(expression) if expression.is_a?(type) expression | dynamic_parser_rules(expr_string) end end |
#read_text ⇒ Object
173 174 175 176 177 178 |
# File 'lib/plurimath/asciimath/parse.rb', line 173 def read_text dynamic do |_sour, context| rparen = Constants::PARENTHESIS[context.captures[:paren].to_sym] match("[^#{rparen}]").repeat end end |