Class: AsciiMath::Parser

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

Constant Summary collapse

SYMBOLS =
{
    # Operation symbols
    '+' => {:value => '+', :type => :operator},
    '-' => {:value => "\u2212", :type => :operator},
    '*' => {:value => "\u22C5", :type => :operator},
    '**' => {:value => "\u002A", :type => :operator},
    '***' => {:value => "\u22C6", :type => :operator},
    '//' => {:value => '/', :type => :operator},
    '\\\\' => {:value => '\\', :type => :operator},
    'xx' => {:value => "\u00D7", :type => :operator},
    '-:' => {:value => "\u00F7", :type => :operator},
    '|><' => {:value => "\u22C9", :type => :operator},
    '><|' => {:value => "\u22CA", :type => :operator},
    '|><|' => {:value => "\u22C8", :type => :operator},
    '@' => {:value => "\u26AC", :type => :operator},
    'o+' => {:value => "\u2295", :type => :operator},
    'ox' => {:value => "\u2297", :type => :operator},
    'o.' => {:value => "\u2299", :type => :operator},
    'sum' => {:value => "\u2211", :type => :operator, :underover => true},
    'prod' => {:value => "\u220F", :type => :operator, :underover => true},
    '^^' => {:value => "\u2227", :type => :operator},
    '^^^' => {:value => "\u22C0", :type => :operator, :underover => true},
    'vv' => {:value => "\u2228", :type => :operator},
    'vvv' => {:value => "\u22C1", :type => :operator, :underover => true},
    'nn' => {:value => "\u2229", :type => :operator},
    'nnn' => {:value => "\u22C2", :type => :operator, :underover => true},
    'uu' => {:value => "\u222A", :type => :operator},
    'uuu' => {:value => "\u22C3", :type => :operator, :underover => true},

    # Relation symbols
    '=' => {:value => '=', :type => :operator},
    '!=' => {:value => "\u2260", :type => :operator},
    ':=' => {:value => ':=', :type => :operator},
    '<' => {:value => "\u003C", :type => :operator},
    'lt' => {:value => "\u003C", :type => :operator},
    '>' => {:value => "\u003E", :type => :operator},
    'gt' => {:value => "\u003E", :type => :operator},
    '<=' => {:value => "\u2264", :type => :operator},
    'le' => {:value => "\u2264", :type => :operator},
    '>=' => {:value => "\u2265", :type => :operator},
    'ge' => {:value => "\u2265", :type => :operator},
    '-<' => {:value => "\u227A", :type => :operator},
    '>-' => {:value => "\u227B", :type => :operator},
    '-<=' => {:value => "\u2AAF", :type => :operator},
    '>-=' => {:value => "\u2AB0", :type => :operator},
    'in' => {:value => "\u2208", :type => :operator},
    '!in' => {:value => "\u2209", :type => :operator},
    'sub' => {:value => "\u2282", :type => :operator},
    'sup' => {:value => "\u2283", :type => :operator},
    'sube' => {:value => "\u2286", :type => :operator},
    'supe' => {:value => "\u2287", :type => :operator},
    '-=' => {:value => "\u2261", :type => :operator},
    '~=' => {:value => "\u2245", :type => :operator},
    '~~' => {:value => "\u2248", :type => :operator},
    'prop' => {:value => "\u221D", :type => :operator},

    # Logical symbols
    'and' => {:value => 'and', :type => :text},
    'or' => {:value => 'or', :type => :text},
    'not' => {:value => "\u00AC", :type => :operator},
    '=>' => {:value => "\u21D2", :type => :operator},
    'if' => {:value => 'if', :type => :operator},
    '<=>' => {:value => "\u21D4", :type => :operator},
    'AA' => {:value => "\u2200", :type => :operator},
    'EE' => {:value => "\u2203", :type => :operator},
    '_|_' => {:value => "\u22A5", :type => :operator},
    'TT' => {:value => "\u22A4", :type => :operator},
    '|--' => {:value => "\u22A2", :type => :operator},
    '|==' => {:value => "\u22A8", :type => :operator},

    # Grouping brackets
    '(' => {:value => '(', :type => :lparen},
    ')' => {:value => ')', :type => :rparen},
    '[' => {:value => '[', :type => :lparen},
    ']' => {:value => ']', :type => :rparen},
    '{' => {:value => '{', :type => :lparen},
    '}' => {:value => '}', :type => :rparen},
    '(:' => {:value => "\u2329", :type => :lparen},
    ':)' => {:value => "\u232A", :type => :rparen},
    '<<' => {:value => "\u2329", :type => :lparen},
    '>>' => {:value => "\u232A", :type => :rparen},
    '|' => {:value => '|', :type => :lrparen},
    '||' => {:value => '||', :type => :lrparen},
    '{:' => {:value => nil, :type => :lparen},
    ':}' => {:value => nil, :type => :rparen},

    # Miscellaneous symbols
    'int' => {:value => "\u222B", :type => :operator},
    'dx' => {:value => 'dx', :type => :identifier},
    'dy' => {:value => 'dy', :type => :identifier},
    'dz' => {:value => 'dz', :type => :identifier},
    'dt' => {:value => 'dt', :type => :identifier},
    'oint' => {:value => "\u222E", :type => :operator},
    'del' => {:value => "\u2202", :type => :operator},
    'grad' => {:value => "\u2207", :type => :operator},
    '+-' => {:value => "\u00B1", :type => :operator},
    'O/' => {:value => "\u2205", :type => :operator},
    'oo' => {:value => "\u221E", :type => :operator},
    'aleph' => {:value => "\u2135", :type => :operator},
    '...' => {:value => '...', :type => :operator},
    ':.' => {:value => "\u2234", :type => :operator},
    '/_' => {:value => "\u2220", :type => :operator},
    '\\ ' => {:value => "\u00A0", :type => :operator},
    'quad' => {:value => '\u00A0\u00A0', :type => :operator},
    'qquad' => {:value => '\u00A0\u00A0\u00A0\u00A0', :type => :operator},
    'cdots' => {:value => "\u22EF", :type => :operator},
    'vdots' => {:value => "\u22EE", :type => :operator},
    'ddots' => {:value => "\u22F1", :type => :operator},
    'diamond' => {:value => "\u22C4", :type => :operator},
    'square' => {:value => "\u25A1", :type => :operator},
    '|__' => {:value => "\u230A", :type => :operator},
    '__|' => {:value => "\u230B", :type => :operator},
    '|~' => {:value => "\u2308", :type => :operator},
    '~|' => {:value => "\u2309", :type => :operator},
    'CC' => {:value => "\u2102", :type => :operator},
    'NN' => {:value => "\u2115", :type => :operator},
    'QQ' => {:value => "\u211A", :type => :operator},
    'RR' => {:value => "\u211D", :type => :operator},
    'ZZ' => {:value => "\u2124", :type => :operator},

    'lim' => {:value => 'lim', :type => :operator, :underover => true},
    'Lim' => {:value => 'Lim', :type => :operator, :underover => true},

    # Standard functions
    'sin' => {:value => 'sin', :type => :identifier},
    'cos' => {:value => 'cos', :type => :identifier},
    'tan' => {:value => 'tan', :type => :identifier},
    'sec' => {:value => 'sec', :type => :identifier},
    'csc' => {:value => 'csc', :type => :identifier},
    'cot' => {:value => 'cot', :type => :identifier},
    'arcsin' => {:value => 'arcsin', :type => :identifier},
    'arccos' => {:value => 'arccos', :type => :identifier},
    'arctan' => {:value => 'arctan', :type => :identifier},
    'sinh' => {:value => 'sinh', :type => :identifier},
    'cosh' => {:value => 'cosh', :type => :identifier},
    'tanh' => {:value => 'tanh', :type => :identifier},
    'sech' => {:value => 'sech', :type => :identifier},
    'csch' => {:value => 'csch', :type => :identifier},
    'coth' => {:value => 'coth', :type => :identifier},
    'exp' => {:value => 'exp', :type => :identifier},
    'log' => {:value => 'log', :type => :identifier},
    'ln' => {:value => 'ln', :type => :identifier},
    'det' => {:value => 'det', :type => :identifier},
    'dim' => {:value => 'dim', :type => :identifier},
    'mod' => {:value => 'mod', :type => :identifier},
    'gcd' => {:value => 'gcd', :type => :identifier},
    'lcm' => {:value => 'lcm', :type => :identifier},
    'lub' => {:value => 'lub', :type => :identifier},
    'glb' => {:value => 'glb', :type => :identifier},
    'min' => {:value => 'min', :type => :identifier, :underover => true},
    'max' => {:value => 'max', :type => :identifier, :underover => true},
    'f' => {:value => 'f', :type => :identifier},
    'g' => {:value => 'g', :type => :identifier},

    # Accents
    'hat' => {:value => "\u005E", :type => :accent, :position => :over},
    'bar' => {:value => "\u00AF", :type => :accent, :position => :over},
    'ul' => {:value => '_', :type => :accent, :position => :under},
    'vec' => {:value => "\u2192", :type => :accent, :position => :over},
    'dot' => {:value => '.', :type => :accent, :position => :over},
    'ddot' => {:value => '..', :type => :accent, :position => :over},
    'obrace' => {:value => "\u23DE", :type => :accent, :position => :over},
    'ubrace' => {:value => "\u23DF", :type => :accent, :position => :under},

    # Arrows
    'uarr' => {:value => "\u2191", :type => :operator},
    'darr' => {:value => "\u2193", :type => :operator},
    'rarr' => {:value => "\u2192", :type => :operator},
    '->' => {:value => "\u2192", :type => :operator},
    '>->' => {:value => "\u21A3", :type => :operator},
    '->>' => {:value => "\u21A0", :type => :operator},
    '>->>' => {:value => "\u2916", :type => :operator},
    '|->' => {:value => "\u21A6", :type => :operator},
    'larr' => {:value => "\u2190", :type => :operator},
    'harr' => {:value => "\u2194", :type => :operator},
    'rArr' => {:value => "\u21D2", :type => :operator},
    'lArr' => {:value => "\u21D0", :type => :operator},
    'hArr' => {:value => "\u21D4", :type => :operator},

    # Other
    'sqrt' => {:value => :sqrt, :type => :unary},
    'text' => {:value => :text, :type => :unary},
    'bb' => {:value => :bold, :type => :font},
    'bbb' => {:value => :double_struck, :type => :font},
    'ii' => {:value => :italic, :type => :font},
    'bii' => {:value => :bold_italic, :type => :font},
    'cc' => {:value => :script, :type => :font},
    'bcc' => {:value => :bold_script, :type => :font},
    'tt' => {:value => :monospace, :type => :font},
    'fr' => {:value => :fraktur, :type => :font},
    'bfr' => {:value => :bold_fraktur, :type => :font},
    'sf' => {:value => :sans_serif, :type => :font},
    'bsf' => {:value => :bold_sans_serif, :type => :font},
    'sfi' => {:value => :sans_serif_italic, :type => :font},
    'sfbi' => {:value => :sans_serif_bold_italic, :type => :font},
    'frac' => {:value => :frac, :type => :binary},
    'root' => {:value => :root, :type => :binary},
    'stackrel' => {:value => :over, :type => :binary},
    '/' => {:value => :frac, :type => :infix},
    '_' => {:value => :sub, :type => :infix},
    '^' => {:value => :sup, :type => :infix},

    # Greek letters
    'alpha' => {:value => "\u03b1", :type => :identifier},
    'Alpha' => {:value => "\u0391", :type => :identifier},
    'beta' => {:value => "\u03b2", :type => :identifier},
    'Beta' => {:value => "\u0392", :type => :identifier},
    'gamma' => {:value => "\u03b3", :type => :identifier},
    'Gamma' => {:value => "\u0393", :type => :operator},
    'delta' => {:value => "\u03b4", :type => :identifier},
    'Delta' => {:value => "\u0394", :type => :operator},
    'epsilon' => {:value => "\u03b5", :type => :identifier},
    'Epsilon' => {:value => "\u0395", :type => :identifier},
    'varepsilon' => {:value => "\u025b", :type => :identifier},
    'zeta' => {:value => "\u03b6", :type => :identifier},
    'Zeta' => {:value => "\u0396", :type => :identifier},
    'eta' => {:value => "\u03b7", :type => :identifier},
    'Eta' => {:value => "\u0397", :type => :identifier},
    'theta' => {:value => "\u03b8", :type => :identifier},
    'Theta' => {:value => "\u0398", :type => :operator},
    'vartheta' => {:value => "\u03d1", :type => :identifier},
    'iota' => {:value => "\u03b9", :type => :identifier},
    'Iota' => {:value => "\u0399", :type => :identifier},
    'kappa' => {:value => "\u03ba", :type => :identifier},
    'Kappa' => {:value => "\u039a", :type => :identifier},
    'lambda' => {:value => "\u03bb", :type => :identifier},
    'Lambda' => {:value => "\u039b", :type => :operator},
    'mu' => {:value => "\u03bc", :type => :identifier},
    'Mu' => {:value => "\u039c", :type => :identifier},
    'nu' => {:value => "\u03bd", :type => :identifier},
    'Nu' => {:value => "\u039d", :type => :identifier},
    'xi' => {:value => "\u03be", :type => :identifier},
    'Xi' => {:value => "\u039e", :type => :operator},
    'omicron' => {:value => "\u03bf", :type => :identifier},
    'Omicron' => {:value => "\u039f", :type => :identifier},
    'pi' => {:value => "\u03c0", :type => :identifier},
    'Pi' => {:value => "\u03a0", :type => :operator},
    'rho' => {:value => "\u03c1", :type => :identifier},
    'Rho' => {:value => "\u03a1", :type => :identifier},
    'sigma' => {:value => "\u03c3", :type => :identifier},
    'Sigma' => {:value => "\u03a3", :type => :operator},
    'tau' => {:value => "\u03c4", :type => :identifier},
    'Tau' => {:value => "\u03a4", :type => :identifier},
    'upsilon' => {:value => "\u03c5", :type => :identifier},
    'Upsilon' => {:value => "\u03a5", :type => :identifier},
    'phi' => {:value => "\u03c6", :type => :identifier},
    'Phi' => {:value => "\u03a6", :type => :identifier},
    'varphi' => {:value => "\u03d5", :type => :identifier},
    'chi' => {:value => '\u03b3c7', :type => :identifier},
    'Chi' => {:value => '\u0393a7', :type => :identifier},
    'psi' => {:value => "\u03c8", :type => :identifier},
    'Psi' => {:value => "\u03a8", :type => :identifier},
    'omega' => {:value => "\u03c9", :type => :identifier},
    'Omega' => {:value => "\u03a9", :type => :operator},
}

Instance Method Summary collapse

Instance Method Details

#parse(input) ⇒ Object



459
460
461
462
463
464
# File 'lib/asciimath/parser.rb', line 459

def parse(input)
  Expression.new(
      input,
      parse_expression(Tokenizer.new(input, SYMBOLS), 0)
  )
end