Rename .value to .body in "ordgroup". (#1609)

This commit is contained in:
Ashish Myles
2018-08-13 10:17:23 -04:00
committed by ylemkimon
parent 8492a7532b
commit fcc5c4420a
15 changed files with 84 additions and 84 deletions

View File

@@ -240,13 +240,13 @@ export default class Parser {
if (numerBody.length === 1 && numerBody[0].type === "ordgroup") {
numerNode = numerBody[0];
} else {
numerNode = {type: "ordgroup", mode: this.mode, value: numerBody};
numerNode = {type: "ordgroup", mode: this.mode, body: numerBody};
}
if (denomBody.length === 1 && denomBody[0].type === "ordgroup") {
denomNode = denomBody[0];
} else {
denomNode = {type: "ordgroup", mode: this.mode, value: denomBody};
denomNode = {type: "ordgroup", mode: this.mode, body: denomBody};
}
let node;
@@ -404,7 +404,7 @@ export default class Parser {
primes.push(this.handleSupSubscript("superscript"));
}
// Put everything into an ordgroup as the superscript
superscript = {type: "ordgroup", mode: this.mode, value: primes};
superscript = {type: "ordgroup", mode: this.mode, body: primes};
} else {
// If it wasn't ^, _, or ', stop parsing super/subscripts
break;
@@ -832,7 +832,7 @@ export default class Parser {
type: "ordgroup",
mode: this.mode,
loc: SourceLocation.range(firstToken, lastToken),
value: expression,
body: expression,
}, firstToken.range(lastToken, firstToken.text));
} else {
// Otherwise, just return a nucleus, or nothing for an optional group

View File

@@ -241,5 +241,5 @@ export function defineFunctionBuilders<NODETYPE: NodeType>({
// list of elements, we normalize for different kinds of arguments
export const ordargument = function(arg: AnyParseNode): AnyParseNode[] {
const node = checkNodeType(arg, "ordgroup");
return node ? node.value : [arg];
return node ? node.body : [arg];
};

View File

@@ -87,7 +87,7 @@ function parseArray(
cell = {
type: "ordgroup",
mode: parser.mode,
value: cell,
body: cell,
};
if (style) {
cell = {
@@ -106,7 +106,7 @@ function parseArray(
// the last line is empty.
// NOTE: Currently, `cell` is the last item added into `row`.
if (row.length === 1 && cell.type === "styling" &&
cell.body[0].value.length === 0) {
cell.body[0].body.length === 0) {
body.pop();
}
if (hLinesBeforeRow.length < body.length + 1) {
@@ -400,13 +400,13 @@ const alignedHandler = function(context, args) {
const emptyGroup = {
type: "ordgroup",
mode: context.mode,
value: [],
body: [],
};
const ordgroup = checkNodeType(args[0], "ordgroup");
if (ordgroup) {
let arg0 = "";
for (let i = 0; i < ordgroup.value.length; i++) {
const textord = assertNodeType(ordgroup.value[i], "textord");
for (let i = 0; i < ordgroup.body.length; i++) {
const textord = assertNodeType(ordgroup.body[i], "textord");
arg0 += textord.text;
}
numMaths = Number(arg0);
@@ -418,7 +418,7 @@ const alignedHandler = function(context, args) {
// Modify ordgroup node within styling node
const styling = assertNodeType(row[i], "styling");
const ordgroup = assertNodeType(styling.body[0], "ordgroup");
ordgroup.value.unshift(emptyGroup);
ordgroup.body.unshift(emptyGroup);
}
if (!isAligned) { // Case 1
const curMaths = row.length / 2;
@@ -471,7 +471,7 @@ defineEnvironment({
// - The argument is a bare symbol node.
const symNode = checkSymbolNodeType(args[0]);
const colalign: AnyParseNode[] =
symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").value;
symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").body;
const cols = colalign.map(function(nde) {
const node = assertSymbolNodeType(nde);
const ca = node.text;

View File

@@ -15,7 +15,7 @@ defineFunction({
},
handler({parser}, args) {
const arg = assertNodeType(args[0], "ordgroup");
const group = arg.value;
const group = arg.body;
let number = "";
for (let i = 0; i < group.length; i++) {
const node = assertNodeType(group[i], "textord");

View File

@@ -18,8 +18,8 @@ defineFunction({
throw new ParseError("Invalid environment name", nameGroup);
}
let name = "";
for (let i = 0; i < nameGroup.value.length; ++i) {
name += assertNodeType(nameGroup.value[i], "textord").text;
for (let i = 0; i < nameGroup.body.length; ++i) {
name += assertNodeType(nameGroup.body[i], "textord").text;
}
return {
type: "environment",

View File

@@ -110,7 +110,7 @@ defineFunction({
body: {
type: "ordgroup",
mode: parser.mode,
value: body,
body,
},
};
},

View File

@@ -365,7 +365,7 @@ defineFunction({
// Look into the parse nodes to get the desired delimiters.
let leftNode = checkNodeType(args[0], "ordgroup");
if (leftNode) {
leftNode = assertAtomFamily(leftNode.value[0], "open");
leftNode = assertAtomFamily(leftNode.body[0], "open");
} else {
leftNode = assertAtomFamily(args[0], "open");
}
@@ -373,7 +373,7 @@ defineFunction({
let rightNode = checkNodeType(args[1], "ordgroup");
if (rightNode) {
rightNode = assertAtomFamily(rightNode.value[0], "close");
rightNode = assertAtomFamily(rightNode.body[0], "close");
} else {
rightNode = assertAtomFamily(args[1], "close");
}
@@ -396,8 +396,8 @@ defineFunction({
let size = "auto";
let styl = checkNodeType(args[3], "ordgroup");
if (styl) {
if (styl.value.length > 0) {
const textOrd = assertNodeType(styl.value[0], "textord");
if (styl.body.length > 0) {
const textOrd = assertNodeType(styl.body[0], "textord");
size = stylArray[Number(textOrd.text)];
}
} else {

View File

@@ -49,7 +49,7 @@ export const binrelClass = (arg: AnyParseNode): string => {
// (by rendering separately and with {}s before and after, and measuring
// the change in spacing). We'll do roughly the same by detecting the
// atom type directly.
const atom = (arg.type === "ordgroup" && arg.value.length ? arg.value[0] : arg);
const atom = (arg.type === "ordgroup" && arg.body.length ? arg.body[0] : arg);
if (atom.type === "atom" && (atom.family === "bin" || atom.family === "rel")) {
return "m" + atom.family;
} else {

View File

@@ -9,10 +9,10 @@ defineFunctionBuilders({
type: "ordgroup",
htmlBuilder(group, options) {
return buildCommon.makeSpan(
["mord"], html.buildExpression(group.value, options, true), options);
["mord"], html.buildExpression(group.body, options, true), options);
},
mathmlBuilder(group, options) {
return mml.buildExpressionRow(group.value, options);
return mml.buildExpressionRow(group.body, options);
},
});

View File

@@ -25,8 +25,8 @@ defineFunction({
// ref: amsmath: \renewcommand{\smash}[1][tb]{%
// def\mb@t{\ht}\def\mb@b{\dp}\def\mb@tb{\ht\z@\z@\dp}%
let letter = "";
for (let i = 0; i < tbArg.value.length; ++i) {
const node = tbArg.value[i];
for (let i = 0; i < tbArg.body.length; ++i) {
const node = tbArg.body[i];
// $FlowFixMe: Not every node type has a `text` property.
letter = node.text;
if (letter === "t") {

View File

@@ -78,7 +78,7 @@ type ParseNodeTypes = {
type: "ordgroup",
mode: Mode,
loc?: ?SourceLocation,
value: AnyParseNode[],
body: AnyParseNode[],
|},
"size": {|
type: "size",

View File

@@ -162,7 +162,7 @@ const katexImagesData: {
const groupLength = function(arg: AnyParseNode): number {
if (arg.type === "ordgroup") {
return arg.value.length;
return arg.body.length;
} else {
return 1;
}

View File

@@ -98,8 +98,8 @@ function clearNode(node: Node) {
*/
const getBaseElem = function(group: AnyParseNode): AnyParseNode {
if (group.type === "ordgroup") {
if (group.value.length === 1) {
return getBaseElem(group.value[0]);
if (group.body.length === 1) {
return getBaseElem(group.body[0]);
} else {
return group;
}

View File

@@ -12,8 +12,7 @@ exports[`A begin/end parser should grab \\arraystretch 1`] = `
"body": [
{
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "mathord",
"loc": {
@@ -27,7 +26,8 @@ exports[`A begin/end parser should grab \\arraystretch 1`] = `
"mode": "math",
"text": "a"
}
]
],
"mode": "math"
}
],
"mode": "math",
@@ -38,8 +38,7 @@ exports[`A begin/end parser should grab \\arraystretch 1`] = `
"body": [
{
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "mathord",
"loc": {
@@ -53,7 +52,8 @@ exports[`A begin/end parser should grab \\arraystretch 1`] = `
"mode": "math",
"text": "b"
}
]
],
"mode": "math"
}
],
"mode": "math",
@@ -66,8 +66,7 @@ exports[`A begin/end parser should grab \\arraystretch 1`] = `
"body": [
{
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "mathord",
"loc": {
@@ -81,7 +80,8 @@ exports[`A begin/end parser should grab \\arraystretch 1`] = `
"mode": "math",
"text": "c"
}
]
],
"mode": "math"
}
],
"mode": "math",
@@ -92,8 +92,7 @@ exports[`A begin/end parser should grab \\arraystretch 1`] = `
"body": [
{
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "mathord",
"loc": {
@@ -107,7 +106,8 @@ exports[`A begin/end parser should grab \\arraystretch 1`] = `
"mode": "math",
"text": "d"
}
]
],
"mode": "math"
}
],
"mode": "math",
@@ -630,19 +630,18 @@ exports[`An implicit group parser within optional groups should work style comma
"type": "sqrt",
"body": {
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "mathord",
"mode": "math",
"text": "x"
}
]
],
"mode": "math"
},
"index": {
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "styling",
"body": [
@@ -655,7 +654,8 @@ exports[`An implicit group parser within optional groups should work style comma
"mode": "math",
"style": "text"
}
]
],
"mode": "math"
},
"mode": "math"
}
@@ -668,19 +668,18 @@ exports[`An implicit group parser within optional groups should work with \\colo
"type": "sqrt",
"body": {
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "mathord",
"mode": "math",
"text": "x"
}
]
],
"mode": "math"
},
"index": {
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "color",
"body": [
@@ -693,7 +692,8 @@ exports[`An implicit group parser within optional groups should work with \\colo
"color": "red",
"mode": "math"
}
]
],
"mode": "math"
},
"mode": "math"
}
@@ -706,36 +706,36 @@ exports[`An implicit group parser within optional groups should work with old fo
"type": "sqrt",
"body": {
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "mathord",
"mode": "math",
"text": "x"
}
]
],
"mode": "math"
},
"index": {
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "font",
"body": {
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "textord",
"mode": "math",
"text": "3"
}
]
],
"mode": "math"
},
"font": "mathtt",
"mode": "math"
}
]
],
"mode": "math"
},
"mode": "math"
}
@@ -748,19 +748,18 @@ exports[`An implicit group parser within optional groups should work with sizing
"type": "sqrt",
"body": {
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "mathord",
"mode": "math",
"text": "x"
}
]
],
"mode": "math"
},
"index": {
"type": "ordgroup",
"mode": "math",
"value": [
"body": [
{
"type": "sizing",
"body": [
@@ -773,7 +772,8 @@ exports[`An implicit group parser within optional groups should work with sizing
"mode": "math",
"size": 5
}
]
],
"mode": "math"
},
"mode": "math"
}

View File

@@ -325,7 +325,7 @@ describe("A group parser", function() {
const ord = parse[0];
expect(ord.type).toMatch("ord");
expect(ord.value).toBeTruthy();
expect(ord.body).toBeTruthy();
});
});
@@ -362,7 +362,7 @@ describe("An implicit group parser", function() {
const parse = getParsed`a { b \Large c } d`;
const group = parse[1];
const sizing = group.value[1];
const sizing = group.body[1];
expect(sizing.type).toEqual("sizing");
expect(sizing.body).toHaveLength(1);
@@ -552,14 +552,14 @@ describe("An over/brace/brack parser", function() {
const parse = getParsed(complexOver)[0];
const numer = parse.numer;
expect(numer.value).toHaveLength(4);
expect(numer.body).toHaveLength(4);
});
it("should create a demonimator from the atoms after \\over", function() {
const parse = getParsed(complexOver)[0];
const denom = parse.numer;
expect(denom.value).toHaveLength(4);
expect(denom.body).toHaveLength(4);
});
it("should handle empty numerators", function() {
@@ -582,7 +582,7 @@ describe("An over/brace/brack parser", function() {
const displaystyleExpression = r`\displaystyle 1 \over 2`;
const parse = getParsed(displaystyleExpression)[0];
expect(parse.type).toEqual("genfrac");
expect(parse.numer.value[0].type).toEqual("styling");
expect(parse.numer.body[0].type).toEqual("styling");
expect(parse.denom).toBeDefined();
});
@@ -595,11 +595,11 @@ describe("An over/brace/brack parser", function() {
const nestedOverExpression = r`{1 \over 2} \over 3`;
const parse = getParsed(nestedOverExpression)[0];
expect(parse.type).toEqual("genfrac");
expect(parse.numer.value[0].type).toEqual("genfrac");
expect(parse.numer.value[0].numer.value[0].text).toEqual("1");
expect(parse.numer.value[0].denom.value[0].text).toEqual("2");
expect(parse.numer.body[0].type).toEqual("genfrac");
expect(parse.numer.body[0].numer.body[0].text).toEqual("1");
expect(parse.numer.body[0].denom.body[0].text).toEqual("2");
expect(parse.denom).toBeDefined();
expect(parse.denom.value[0].text).toEqual("3");
expect(parse.denom.body[0].text).toEqual("3");
});
it("should fail with multiple overs in the same group", function() {
@@ -1467,7 +1467,7 @@ describe("A style change parser", function() {
const text = r`a b { c d \displaystyle e f } g h`;
const parse = getParsed(text);
const displayNode = parse[2].value[2];
const displayNode = parse[2].body[2];
expect(displayNode.type).toEqual("styling");
@@ -1520,7 +1520,7 @@ describe("A font parser", function() {
expect(nestedParse.font).toEqual("mathbb");
expect(nestedParse.type).toEqual("font");
const bbBody = nestedParse.body.value;
const bbBody = nestedParse.body.body;
expect(bbBody).toHaveLength(3);
expect(bbBody[0].type).toEqual("mathord");
expect(bbBody[2].type).toEqual("font");
@@ -1546,11 +1546,11 @@ describe("A font parser", function() {
const bf = getParsed`\mathbf{a\mathrm{b}c}`[0];
expect(bf.type).toEqual("font");
expect(bf.font).toEqual("mathbf");
expect(bf.body.value).toHaveLength(3);
expect(bf.body.value[0].text).toEqual("a");
expect(bf.body.value[1].type).toEqual("font");
expect(bf.body.value[1].font).toEqual("mathrm");
expect(bf.body.value[2].text).toEqual("c");
expect(bf.body.body).toHaveLength(3);
expect(bf.body.body[0].text).toEqual("a");
expect(bf.body.body[1].type).toEqual("font");
expect(bf.body.body[1].font).toEqual("mathrm");
expect(bf.body.body[2].text).toEqual("c");
});
it("should have the correct greediness", function() {