feat(macro): improve argument parsing (#2085)

* Improve macro argument parsing

* Make \above a primitive command

* Fix screenshotter data

* Normalize argument where necessary

* Improve argument location info

* Update comments

* Minor refactor

* Modularize group parsers

* Allow braced and blank size argument

for non-strict mode and \genfrac, respectively.

* Minor refactor & update comments

* Remove raw option in parseStringGroup

* Update tests

* Fix { delimited parameter

* Update tests

* Update tests

* Normalize argument in \genfrac

* Update tests

* Consume space before scanning an optional argument

* Fix \\, \newline, and \cr behavior

* Fix flow error

* Update comments

* Remove unnecessary mode switching

Parser mode affects neither fetch nor consume.

* Allow single (active) character macro

* Add function property `primitive`

* Set \mathchoice and \*style primitive

* Separate size-related improvements out to #2139

* Fix flow error

* Update screenshots

* Update demo example

* Add a migration guide

* Fix capitalization

* Make a primitive function unexpandable

* Update screenshots

* Update screenshots

* Revert "Document \def doesn't support delimiters (#2288) (#2289)"

This reverts commit f96fba6f7f.

* Update comments, errors, and tests

* Update screenshots
This commit is contained in:
ylemkimon
2020-09-06 12:56:13 +09:00
committed by GitHub
parent 8578d74f82
commit dc5f97aaa2
35 changed files with 432 additions and 348 deletions

View File

@@ -1,5 +1,5 @@
// @flow
import defineFunction from "../defineFunction";
import defineFunction, {normalizeArgument} from "../defineFunction";
import buildCommon from "../buildCommon";
import delimiter from "../delimiter";
import mathMLTree from "../mathMLTree";
@@ -382,10 +382,12 @@ defineFunction({
const denom = args[5];
// Look into the parse nodes to get the desired delimiters.
const leftDelim = args[0].type === "atom" && args[0].family === "open"
? delimFromValue(args[0].text) : null;
const rightDelim = args[1].type === "atom" && args[1].family === "close"
? delimFromValue(args[1].text) : null;
const leftNode = normalizeArgument(args[0]);
const leftDelim = leftNode.type === "atom" && leftNode.family === "open"
? delimFromValue(leftNode.text) : null;
const rightNode = normalizeArgument(args[1]);
const rightDelim = rightNode.type === "atom" && rightNode.family === "close"
? delimFromValue(rightNode.text) : null;
const barNode = assertNodeType(args[2], "size");
let hasBarLine;