Add \ in front of functions in the parser

Auditors: alpert
This commit is contained in:
Emily Eisenberg
2013-07-13 16:13:05 -07:00
parent 38e2d600fd
commit 20658a95b6
2 changed files with 16 additions and 15 deletions

View File

@@ -45,7 +45,7 @@ Lexer.prototype.lex = function(pos) {
var match;
if ((match = input.match(anyFunc))) {
// If we match one of the tokens, extract the type
return new LexResult(match[1], match[0], pos + match[0].length);
return new LexResult(match[0], match[0], pos + match[0].length);
} else {
// Otherwise, we look through the normal token regexes and see if it's
// one of them.

View File

@@ -172,7 +172,7 @@ function contains(list, elem) {
// A list of 1-argument color functions
var colorFuncs = [
"blue", "orange", "pink", "red", "green", "gray", "purple"
"\\blue", "\\orange", "\\pink", "\\red", "\\green", "\\gray", "\\purple"
];
// A map of elements that don't have arguments, and should simply be placed
@@ -185,15 +185,16 @@ var colorFuncs = [
var copyFuncs = {
"textord": ["textord"],
"mathord": ["mathord"],
"bin": ["bin", "pm", "div", "cdot"],
"open": ["open", "lvert"],
"close": ["close", "rvert"],
"rel": ["rel", "leq", "geq", "neq", "nleq", "ngeq"],
"spacing": ["qquad", "quad", "space", " ", ",", ":", ";"],
"punct": ["punct", "colon"],
"namedfn": ["arcsin", "arccos", "arctan", "arg", "cos", "cosh", "cot",
"coth", "csc", "deg", "dim", "exp", "hom", "ker", "lg", "ln", "log",
"sec", "sin", "sinh", "tan", "tanh"]
"bin": ["bin", "\\pm", "\\div", "\\cdot"],
"open": ["open", "\\lvert"],
"close": ["close", "\\rvert"],
"rel": ["rel", "\\leq", "\\geq", "\\neq", "\\nleq", "\\ngeq"],
"spacing": ["\\qquad", "\\quad", "\\space", "\\ ", "\\,", "\\:", "\\;"],
"punct": ["punct", "\\colon"],
"namedfn": ["\\arcsin", "\\arccos", "\\arctan", "\\arg", "\\cos", "\\cosh",
"\\cot", "\\coth", "\\csc", "\\deg", "\\dim", "\\exp", "\\hom",
"\\ker", "\\lg", "\\ln", "\\log", "\\sec", "\\sin", "\\sinh", "\\tan",
"\\tanh"]
};
// Build a list of all of the different functions in the copyFuncs list, to
@@ -217,22 +218,22 @@ Parser.prototype.parseNucleus = function(pos) {
if (group) {
return new ParseResult(
new ParseNode("color",
{color: nucleus.type, value: group.result}),
{color: nucleus.type.slice(1), value: group.result}),
group.position);
} else {
throw "Parse error: Expected group after '" + nucleus.text + "'";
}
} else if (nucleus.type === "llap" || nucleus.type === "rlap") {
} else if (nucleus.type === "\\llap" || nucleus.type === "\\rlap") {
// If this is an llap or rlap, parse its argument and return
var group = this.parseGroup(nucleus.position);
if (group) {
return new ParseResult(
new ParseNode(nucleus.type, nucleus.text),
new ParseNode(nucleus.type.slice(1), nucleus.text),
group.position);
} else {
throw "Parse error: Expected group after '" + nucleus.text + "'";
}
} else if (nucleus.type === "dfrac") {
} else if (nucleus.type === "\\dfrac") {
// If this is a dfrac, parse its two arguments and return
var numer = this.parseGroup(nucleus.position);
if (numer) {