Move \global and \def to functions (#2138)

* Add parseNode type `internal`

* Move \def and \newcommand to functions

* Fix Flow error

* Separate \global

Move \newcommand back to macros for now

* Rename assignment.js to def.js

* Update test cases

* Add comments

* Update a test case
This commit is contained in:
ylemkimon
2019-12-05 10:07:20 +09:00
committed by Kevin Barabash
parent 0d8830af30
commit b1eeeecf91
8 changed files with 104 additions and 57 deletions

View File

@@ -3156,6 +3156,11 @@ describe("A macro expander", function() {
//expect`\gdef{\foo}{}`.not.toParse();
});
it("\\def should be handled in Parser", () => {
expect`\gdef\foo{1}`.toParse(new Settings({maxExpand: 0}));
expect`2^\def\foo{1}2`.not.toParse();
});
it("\\def works locally", () => {
expect("\\def\\x{1}\\x{\\def\\x{2}\\x{\\def\\x{3}\\x}\\x}\\x")
.toParseLike`1{2{3}2}1`;
@@ -3174,8 +3179,7 @@ describe("A macro expander", function() {
it("\\global needs to followed by \\def", () => {
expect`\global\def\foo{}\foo`.toParseLike``;
// TODO: This doesn't work yet; \global needs to expand argument.
//expect`\def\DEF{\def}\global\DEF\foo{}\foo`.toParseLike``;
expect`\def\DEF{\def}\global\DEF\foo{}\foo`.toParseLike``;
expect`\global\foo`.not.toParse();
expect`\global\bar x`.not.toParse();
});
@@ -3563,8 +3567,7 @@ describe("The maxSize setting", function() {
describe("The maxExpand setting", () => {
it("should prevent expansion", () => {
expect`\gdef\foo{1}\foo`.toParse();
expect`\gdef\foo{1}\foo`.toParse(new Settings({maxExpand: 2}));
expect`\gdef\foo{1}\foo`.not.toParse(new Settings({maxExpand: 1}));
expect`\gdef\foo{1}\foo`.toParse(new Settings({maxExpand: 1}));
expect`\gdef\foo{1}\foo`.not.toParse(new Settings({maxExpand: 0}));
});