Skip to content

Commit

Permalink
Add a "itex identifier mode" and some tests for this mode and the saf…
Browse files Browse the repository at this point in the history
…e mode. #13
  • Loading branch information
fred-wang committed Jun 1, 2014
1 parent c7ab7ff commit bdb972f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
5 changes: 5 additions & 0 deletions TeXZilla.jison
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ parser.setSafeMode = function(aEnable)
this.yy.mSafeMode = aEnable;
}
parser.setItexIdentifierMode = function(aEnable)
{
this.yy.mItexIdentifierMode = aEnable;
}
parser.getTeXSource = function(aMathMLElement) {
if (typeof aMathMLElement === "string") {
aMathMLElement = this.parseMathMLDocument(aMathMLElement);
Expand Down
4 changes: 4 additions & 0 deletions commonJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ if (typeof require !== "undefined") {
TeXZilla.setSafeMode(aEnable);
};

exports.setItexIdentifierMode = function (aEnable) {
TeXZilla.setItexIdentifierMode(aEnable);
};

exports.getTeXSource = function () {
return TeXZilla.getTeXSource.apply(TeXZilla, arguments);
};
Expand Down
7 changes: 5 additions & 2 deletions main.jisonlex
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

%x DOCUMENT TRYOPTARG TEXTOPTARG TEXTARG
%s MATH OPTARG
%s MATH0 MATH1 OPTARG

%%

<INITIAL>. { this.unput(yytext); this.pushState("DOCUMENT"); }

<DOCUMENT>"$$"|"\\["|"$"|"\\(" {
this.pushState("MATH");
this.pushState("MATH" + (0+!!yy.mItexIdentifierMode));
yy.startMath = this.matched.length;
return "STARTMATH" + (2 * (yytext[0] == "$") +
(yytext[1] == "$" || yytext[1] == "["));
Expand Down Expand Up @@ -55,3 +55,6 @@

/* Numbers */
[0-9]+(?:"."[0-9]+)?|[\u0660-\u0669]+(?:"\u066B"[\u0660-\u0669]+)?|(?:\uD835[\uDFCE-\uDFD7])+|(?:\uD835[\uDFCE-\uDFD7])+|(?:\uD835[\uDFD8-\uDFE1])+|(?:\uD835[\uDFE2-\uDFEB])+|(?:\uD835[\uDFEC-\uDFF5])+|(?:\uD835[\uDFF6-\uDFFF])+ return "NUM";

/* itex2MML identifier */
<MATH1>[a-zA-Z]+ { return "A"; }
56 changes: 39 additions & 17 deletions unit-tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bdb972f

Please sign in to comment.