Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
lib/parser.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a newline so that the "no newline" mark is gone, but it seems GitHub still displays it as if there is no newline at the end. Should I add another?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add another.

1 change: 1 addition & 0 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ var Tex = module.exports.Tex = new Enum( 'Tex', {
FUN2sq: { args: [ 'string', 'self', 'self' ] },
FUN3: { args: [ 'string', 'self', 'self', 'self'] },
MATRIX: { args: [ 'string', [ [ [ 'self' ] ] ] ] },
MULTLINE: { args: [ 'string', [ [ [ 'self' ] ] ] ] },
DECLh: { args: [ 'string', FontForce, [ 'self' ] ] },
JACOBI: { args: [ 'self', 'self', 'self', 'self']},
LAGUERRE1: { args:['self', 'self']},
Expand Down
11 changes: 11 additions & 0 deletions lib/astutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ ast.Tex.defineVisitor("contains_func", {
match(target, '\\end{'+t+'}') ||
matrix_has(m);
},
MULTLINE: function(target, t, m) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference in the functions for multine and matrix. Can't you just create one functaion and assign it to both keys MATRIX and MULTILINE

// \begin{env} .. \\ .. \\ .. \\ .. \end{env}
// t is the environment name.
// m is a one-dimensional array.
var expr_has = function(e) { return arr_contains_func(e, target); };
var line_has = function(l) { return some(l, expr_has); };
var lines_have = function(m) { return some(m, line_has); };
return match(target, '\\begin{'+t+'}') ||
match(target, '\\end{'+t+'}') ||
lines_have(m);
},
LR: function(target, l, r, tl) {
// \left\l tl1 tl2 tl3 ... \right\r (a balanced pair of delimiters)
return match(target, '\\left') || match(target, '\\right') ||
Expand Down
14 changes: 7 additions & 7 deletions lib/build-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ var buildParser = module.exports = function(inFile, outFile) {
var PEG = require('pegjs');
var fs = require('fs');

var parserSource = PEG.buildParser(fs.readFileSync(inFile, 'utf8'), {
var parserSource = PEG.generate(fs.readFileSync(inFile, 'utf8'), {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain, what this change means

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the newest version of pegJS (0.10.0), pegjs.buildParser was changed to pegjs.generate.

/* PEGJS options */
output: "source",
cache: true,// makes repeated calls to generic_func production efficient
allowedStartTules: [ "start" ]
});
// hack up the source to make it pass jshint
parserSource = parserSource
.replace(/(peg\$subclass\(child, parent\)|peg\$SyntaxError\(message, expected, found, location\)|peg\$parse\(input\)) {/g,
function (m) {
return m + "\n /*jshint validthis:true, newcap:false*/ ";
}).replace(/\n(\s+)([?:+]) (expectedDescs|" or "|peg)/g, ' $2\n$1$3');
// parserSource = parserSource

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old code will remain in the git history. You do not need to comment it out.

// .replace(/(peg\$subclass\(child, parent\)|peg\$SyntaxError\(message, expected, found, location\)|peg\$parse\(input\)) {/g,
// function (m) {
// return m + "\n /*jshint validthis:true, newcap:false*/ ";
// }).replace(/\n(\s+)([?:+]) (expectedDescs|" or "|peg)/g, ' $2\n$1$3');
parserSource =
'/* jshint latedef: false */\n' +
// '/* jshint latedef: false */\n' +
'module.exports = ' + parserSource + ';';

fs.writeFileSync(outFile, parserSource, 'utf8');
Expand Down
2,582 changes: 1,506 additions & 1,076 deletions lib/parser.js

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions lib/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ lit
{ return ast.Tex.MATRIX("smallmatrix", lst2arr(m)); }
/ BEGIN_CASES m:matrix END_CASES
{ return ast.Tex.MATRIX("cases", lst2arr(m)); }
/ BEGIN_MULTLINE m:multline END_MULTLINE
{ return ast.Tex.MULTLINE("multline", lst2arr(m)); }
/ BEGIN_MULTLINE_STAR m:multline END_MULTLINE_STAR
{ return ast.Tex.MULTLINE("multline*", lst2arr(m)); }
/ "\\begin{" alpha+ "}" /* better error messages for unknown environments */
{ throw new peg$SyntaxError("Illegal TeX function", [], text(), location()); }
/ f:generic_func &{ return !tu.all_functions[f]; }
Expand Down Expand Up @@ -294,6 +298,10 @@ litstuff = //basically lit without DELIMITER or LITERAL as an option (replaced b
{ return ast.Tex.MATRIX("smallmatrix", lst2arr(m)); }
/ BEGIN_CASES m:matrix END_CASES
{ return ast.Tex.MATRIX("cases", lst2arr(m)); }
/ BEGIN_MULTLINE m:multline END_MULTLINE
{ return ast.Tex.MULTLINE("multline", lst2arr(m)); }
/ BEGIN_MULTLINE_STAR m:multline END_MULTLINE_STAR
{ return ast.Tex.MULTLINE("multline*", lst2arr(m)); }
/ "\\begin{" alpha+ "}" /* better error messages for unknown environments */
{ throw new peg$SyntaxError("Illegal TeX function", [], text(), location()); }
/ f:generic_func &{ return !tu.all_functions[f]; }
Expand Down Expand Up @@ -348,6 +356,15 @@ line
= e:expr tail:( NEXT_CELL l:line { return l; } )?
{ return { head: e.toArray(), tail: tail }; }

multline
= l:mline_start tail:( NEXT_ROW m:multline { return m; } )?
{ return { head: lst2arr(l), tail: tail }; }
mline_start
= f:HLINE m:mline_start
{ m.head.unshift(ast.Tex.LITERAL(ast.RenderT.TEX_ONLY(f + " "))); return m; }
/ e:expr
{ return { head: e.toArray(), tail: null }; }

column_spec
= CURLY_OPEN cs:(one_col+ { return text(); }) CURLY_CLOSE
{ return ast.Tex.CURLY([ast.Tex.LITERAL(ast.RenderT.TEX_ONLY(cs))]); }
Expand Down Expand Up @@ -543,6 +560,14 @@ BEGIN_CASES
= BEGIN "{cases}" _
END_CASES
= END "{cases}" _
BEGIN_MULTLINE
= BEGIN "{multline}" _
END_MULTLINE
= END "{multline}" _
BEGIN_MULTLINE_STAR
= BEGIN "{multline*}" _
END_MULTLINE_STAR
= END "{multline*}" _

SQ_CLOSE
= "]" _
Expand Down
4 changes: 4 additions & 0 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ ast.Tex.defineVisitor("render_tex", {
var render_matrix = function(m) { return m.map(render_line).join('\\\\'); };
return curlies("\\begin{"+t+"}" + render_matrix(m) + "\\end{"+t+"}");
},
MULTLINE: function(t, m) {
var render_lines = function(l) { return l.map(render).join('\\\\'); };
return "\\begin{"+t+"}" + render_lines(m) + "\\end{"+t+"}";
},
LR: function(l, r, tl) {
return "\\left" + l.tex_part() + render(tl) + "\\right" + r.tex_part();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/texutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ module.exports.ams_required = arr2set([
"\\begin{alignedat}",
"\\begin{smallmatrix}",
"\\begin{cases}",
"\\begin{multline}",
"\\begin{multline*}",

"\\ulcorner",
"\\urcorner",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"devDependencies": {
"jshint": "~2.9.1",
"mocha": "~3.0.2",
"pegjs": "~0.9.0",
"pegjs": "~0.10.0",
"balanced-match": "~0.4.2"
},
"bin": {
Expand Down