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
Refactor Parser #1723
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
I'm excited about the removal of |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
@edemaine Thank you for the review! |
There was a problem hiding this 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, |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
parseGroup
parseGivenFunction
to parse only function, removeparseFunction
, and renameparseGivenFunction
toparseFunction
. Moved argument greediness check toparseFunction
parseImplicitGroup
andparseGroup
ParsedFunc
andParsedArg
parseFunction
call fromparseSymbol
toparseGroup
This is a step toward #428.