-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: improve rendering with fallbacks during parsing (#14)
In this PR we introduce fallback during parsing. This makes it more consistent with the https://asciimath.org/ parser. Whenever a symbol is encountered, that can't be part of an expression (like unary, binary or grouping expressions), we parse this symbol as either `Var::UnknownOperator` for symbols that weren't recognized by the lexer, or as `Var::Other` for symbols that were recognized but aren't part of any expression. These are rendered as operators (`<mo>`). Also, parser now closes grouping expressions implicitly with a close ignored grouping token. The unary and binary expression also get an empty operator as a default expression instead of not parsing until end. This makes it possible to get a visual feedback when live rendering during typing of expressions. For example, previously `sqrt(` would not render anything, but `sqrt(x)` would render $\sqrt{x}$. By introducing the changes above, the `sqrt(` now renders to $\sqrt{}$. Changelog: fix: simplify ungroup_map by direct conversion fix: use more operator constructors fix: correctly handle `norm` groupings chore: update alemat to latest version fix: handle dots as operators instead of idents fix: use more pre-defined operator constructors fix: correctly lex set minus operators fix: improve handling of cdots etc fix: simplify handling of groupings fix: improve handling of matrix groupings chore: reformat for better readability fix: correctly parse `cdots`, `ldots` etc feat: implicitly close grouping expressions feat!: remove `Token::is_var` method feat: fallback to operator when no expr recognized test: update snapshots fix: fallback to operator when lexing unknown symbol fix: add fallback to Element conversion for Other keyword fix: add fallbacks when parsing color binary expr fix: fallback to default expression when parsing unary fix: correctly render `and` and `or` logicals fix: render groupings in a `mrow` element fix: correctly lex the divide symbol `-:`
- Loading branch information
Showing
22 changed files
with
327 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// this module tests fallback mechanism of the lexer | ||
|
||
use super::Snapshot; | ||
|
||
super::test_snap!(semicolon, "a + b;"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/lexer/tests/snapshots/mathemascii__lexer__tests__fallback__semicolon.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
source: src/lexer/tests/fallback.rs | ||
expression: "Snapshot((*input, tokens))" | ||
--- | ||
a + b; | ||
|
||
a | ||
^ -> Variable at: 0 -> 1 | ||
|
||
+ | ||
^ -> Operator(Plus) at: 2 -> 3 | ||
|
||
b | ||
^ -> Variable at: 4 -> 5 | ||
|
||
; | ||
^ -> UnknownOperator at: 5 -> 6 | ||
|
||
|
5 changes: 4 additions & 1 deletion
5
src/lexer/tests/snapshots/mathemascii__lexer__tests__numbers__stop_at_dot.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
--- | ||
source: src/lexer/tests/numbers.rs | ||
expression: "Snapshot((input, tokens))" | ||
expression: "Snapshot((*input, tokens))" | ||
--- | ||
24.42. | ||
|
||
24.42 | ||
^^^^^ -> Number at: 0 -> 5 | ||
|
||
. | ||
^ -> UnknownOperator at: 5 -> 6 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.