Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Parser #1723

Merged
merged 11 commits into from Oct 13, 2018
Merged

Refactor Parser #1723

merged 11 commits into from Oct 13, 2018

Conversation

ylemkimon
Copy link
Member

@ylemkimon ylemkimon commented Sep 21, 2018

  • Moved unsupported command (undefined control sequence) handlings to parseGroup
  • Changed parseGivenFunction to parse only function, remove parseFunction, and rename parseGivenFunction to parseFunction. Moved argument greediness check to parseFunction
  • Merged parseImplicitGroup and parseGroup
  • Removed ParsedFunc and ParsedArg
  • Moved parseFunction call from parseSymbol to parseGroup
  • Throw an error if the group type is unknown: Support \includegraphics #1620 (comment)
  • Throw "undefined control sequence" error for undefined control sequence (unknown/unsupported command): fixes Improve error message on unsupported command #538

This is a step toward #428.

@codecov
Copy link

codecov bot commented Sep 21, 2018

Codecov Report

Merging #1723 into master will increase coverage by 0.03%.
The diff coverage is 98.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1723      +/-   ##
==========================================
+ Coverage   93.95%   93.99%   +0.03%     
==========================================
  Files          78       78              
  Lines        4584     4545      -39     
  Branches      809      792      -17     
==========================================
- Hits         4307     4272      -35     
+ Misses        245      242       -3     
+ Partials       32       31       -1
Flag Coverage Δ
#screenshotter 88.63% <84.72%> (+0.05%) ⬆️
#test 85.34% <97.22%> (-0.04%) ⬇️
Impacted Files Coverage Δ
src/environments/array.js 98.29% <100%> (+0.4%) ⬆️
src/functions/environment.js 100% <100%> (ø) ⬆️
src/functions/delimsizing.js 97.64% <100%> (+1.09%) ⬆️
src/Parser.js 97.2% <98.14%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 94d4338...4452e43. Read the comment docs.

@kevinbarabash
Copy link
Member

I'm excited about the removal of ParsedArg and ParsedFunc. There's a lot going on in this PR so it may take me a while to review.

@edemaine edemaine self-assigned this Oct 13, 2018
Copy link
Member

@edemaine edemaine left a comment

Choose a reason for hiding this comment

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

This is an awesome code simplification. Most everything looks good to me. Thanks also for fixing the merge bugs.

}
rowGaps.push(assertNodeType(cr, "cr").size);
const cr = assertNodeType(parser.parseFunction(), "cr");
rowGaps.push(cr.size);
Copy link
Member

Choose a reason for hiding this comment

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

I guess this simpler error checking is fine because parseFunction will return null only if \cr is not a defined function, which shouldn't happen. Ditto below for \right.

Copy link
Member

Choose a reason for hiding this comment

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

assertNodeType will throw if parser.parseFunction() returns null.

test/errors-spec.js Show resolved Hide resolved
test/errors-spec.js Show resolved Hide resolved
@ylemkimon
Copy link
Member Author

@edemaine Thank you for the review!

@ylemkimon ylemkimon closed this Oct 13, 2018
@ylemkimon ylemkimon reopened this Oct 13, 2018
@ylemkimon ylemkimon merged commit 0bc31f1 into KaTeX:master Oct 13, 2018
Copy link
Member

@kevinbarabash kevinbarabash left a comment

Choose a reason for hiding this comment

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

@ylemkimon thank you for this awesome PR, sorry for not looking at it in detail sooner. @edemaine thanks for reviewing this!

optional?: boolean,
greediness?: ?number,
breakOnTokenText?: BreakToken,
mode?: Mode,
Copy link
Member

Choose a reason for hiding this comment

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

Now that we have so many optional params here we might want to replace them with an a single options object param.

if (!this.settings.throwOnError && lex.text[0] === "\\") {
const errorNode = this.handleUnsupportedCmd();
body.push(errorNode);
continue;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this no longer necessary?

Copy link
Member

Choose a reason for hiding this comment

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

I see, it looks like it got moved inside parseGroup.

"Can't use function '" + func + "' in text mode", token);
} else if (this.mode === "math" && funcData.allowedInMath === false) {
throw new ParseError(
"Can't use function '" + func + "' in math mode", token);
Copy link
Member

Choose a reason for hiding this comment

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

This is really nice. I like how you collected a number of different errors in the same place.

// function and say that it is a function.
// The token will be consumed later in parseGivenFunction
// (after possibly switching modes).
return newFunction(nucleus);
Copy link
Member

Choose a reason for hiding this comment

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

Getting rid of this sure allowed you clean up a lot of things.

}
rowGaps.push(assertNodeType(cr, "cr").size);
const cr = assertNodeType(parser.parseFunction(), "cr");
rowGaps.push(cr.size);
Copy link
Member

Choose a reason for hiding this comment

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

assertNodeType will throw if parser.parseFunction() returns null.

}

if (funcName === "\\begin") {
// begin...end is similar to left...right
Copy link
Member

Choose a reason for hiding this comment

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

This is easier to follow. I'm glad that you were able to make this look a little more like delimsizing.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message on unsupported command
3 participants