Class: Plurimath::Mathml::Parse
- Inherits:
 - 
      Parslet::Parser
      
        
- Object
 - Parslet::Parser
 - Plurimath::Mathml::Parse
 
 
- Defined in:
 - lib/plurimath/mathml/parse.rb
 
Instance Method Summary collapse
- #array_to_expression(array, name = nil) ⇒ Object
 - #attributes ⇒ Object
 - #parse_tag(opts) ⇒ Object
 - #parse_text_tag ⇒ Object
 - #quoted_string ⇒ Object
 - #str_to_expression(string, name) ⇒ Object
 
Instance Method Details
#array_to_expression(array, name = nil) ⇒ Object
      26 27 28 29 30 31 32  | 
    
      # File 'lib/plurimath/mathml/parse.rb', line 26 def array_to_expression(array, name = nil) initial_type = array.first.class array.reduce do |expr, tag| expr = str_to_expression(expr, name) if expr.is_a?(initial_type) expr | str_to_expression(tag, name) end end  | 
  
#attributes ⇒ Object
      48 49 50 51  | 
    
      # File 'lib/plurimath/mathml/parse.rb', line 48 def attributes (match["a-zA-Z"].repeat.as(:name) >> str("=") >> quoted_string).repeat end  | 
  
#parse_tag(opts) ⇒ Object
      40 41 42 43 44 45 46  | 
    
      # File 'lib/plurimath/mathml/parse.rb', line 40 def parse_tag(opts) tag = str("<") tag = tag >> str("/") if opts == :close tag = tag >> array_to_expression(Constants::TAGS, opts) tag = tag >> attributes.as(:attributes) if opts == :open tag >> str(">") end  | 
  
#parse_text_tag ⇒ Object
      58 59 60  | 
    
      # File 'lib/plurimath/mathml/parse.rb', line 58 def parse_text_tag str("<mtext>") >> match("[^<]").repeat.as(:quoted_text) >> str("</mtext>") end  | 
  
#quoted_string ⇒ Object
      53 54 55 56  | 
    
      # File 'lib/plurimath/mathml/parse.rb', line 53 def quoted_string (str('"') >> match("[^\"]").repeat.as(:value) >> str('"')) | (str("'") >> match("[^\']").repeat.as(:value) >> str("'")) end  | 
  
#str_to_expression(string, name) ⇒ Object
      34 35 36 37 38  | 
    
      # File 'lib/plurimath/mathml/parse.rb', line 34 def str_to_expression(string, name) return str(string) if name.nil? str(string).as(name) end  |