lib/hemingway/math/math.rb in hemingway-0.0.2 vs lib/hemingway/math/math.rb in hemingway-0.0.3

- old
+ new

@@ -14,11 +14,11 @@ module Math0 def math_start elements[0] end - def symbol + def content elements[1] end def math_end elements[2] @@ -38,15 +38,27 @@ i0, s0 = index, [] r1 = _nt_math_start s0 << r1 if r1 - r2 = _nt_symbol + i2 = index + r3 = _nt_symbol + if r3 + r2 = r3 + else + r4 = _nt_exponent + if r4 + r2 = r4 + else + @index = i2 + r2 = nil + end + end s0 << r2 if r2 - r3 = _nt_math_end - s0 << r3 + r5 = _nt_math_end + s0 << r5 end end if s0.last r0 = instantiate_node(MathNode,input, i0...index, s0) r0.extend(Math0) @@ -72,9 +84,81 @@ end r0 = _nt_math_symbol node_cache[:symbol][start_index] = r0 + + r0 + end + + module Exponent0 + def value + elements[1] + end + + end + + def _nt_exponent + start_index = index + if node_cache[:exponent].has_key?(index) + cached = node_cache[:exponent][index] + if cached + cached = SyntaxNode.new(input, index...(index + 1)) if cached == true + @index = cached.interval.end + end + return cached + end + + i0, s0 = index, [] + if has_terminal?("^{", false, index) + r1 = instantiate_node(SyntaxNode,input, index...(index + 2)) + @index += 2 + else + terminal_parse_failure("^{") + r1 = nil + end + s0 << r1 + if r1 + i2 = index + if has_terminal?("\\circ", false, index) + r3 = instantiate_node(SyntaxNode,input, index...(index + 5)) + @index += 5 + else + terminal_parse_failure("\\circ") + r3 = nil + end + if r3 + r2 = r3 + else + r4 = _nt_text + if r4 + r2 = r4 + else + @index = i2 + r2 = nil + end + end + s0 << r2 + if r2 + if has_terminal?("}", false, index) + r5 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 + else + terminal_parse_failure("}") + r5 = nil + end + s0 << r5 + end + end + if s0.last + r0 = instantiate_node(ExponentNode,input, i0...index, s0) + r0.extend(Exponent0) + else + @index = i0 + r0 = nil + end + + node_cache[:exponent][start_index] = r0 r0 end def _nt_math_start \ No newline at end of file