Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | 15x 209x 209x 209x 209x 1674x 1674x 733x 733x 176x 149x 27x 27x 5x 25x 25x 25x 2x 20x 15x 1320x 96x 247x 247x 247x 247x 247x 2838x 2838x 2838x 2838x 373x 240x 240x 373x 373x 2465x 367x 367x 235x 235x 235x 132x 2098x 247x 7x 240x 1049x 1041x 8x 8x 8x 12x 12x 12x 12x 12x 12x 2x 2x 12x 3x 9x 1x 8x 18x 18x 18x 18x 18x 8x 10x 10x 10x 10x 10x 10x 40x 30x 30x 2590x 15x 15x 1276x 47x 47x 47x 47x 47x 19x 28x 28x 47x 47x 47x 47x 15x 75x 15x 15x | import { accents, identifiers, operators, groupings, fonts } from "./lexicon";
function splitNextOperator(str) {
const re = new RegExp(`^${operators.regexp.source}`);
const match = re.exec(str);
const op = match[0];
return [operators.get(op), str.slice(op.length)];
}
function isgroupStart(str) {
const re = new RegExp(`^${groupings.open.regexp.source}`);
return str.match(re);
}
function isgroupable(str, options) {
const re = new RegExp(
`^[0-9A-Za-z+\\-!]{2,}(\\s|${options.colSep}|${options.rowSep})`
);
return str.match(re);
}
function ismatrixInterior(str, colSep, rowSep) {
if (!isgroupStart(str)) {
return false;
}
let rest = splitNextGroup(str)[4];
if (
!(
rest.trim().startsWith(colSep) ||
(rest.match(/^\s*\n/) && isgroupStart(rest.trim()))
)
) {
return false;
}
// Make sure we are building the matrix with parenthesis, as opposed
// to rowSeps.
while (rest && rest.trim()) {
[, , , , rest] = splitNextGroup(rest) || [];
if (rest && (rest.startsWith(rowSep) || rest.match(/^\s*\n/))) {
// `rowSep` delimited matrices are handled elsewhere.
return false;
}
}
return true;
}
const funcEndingRe = new RegExp(
`(${identifiers.funs
.concat(Object.keys(accents))
.concat(["sqrt"])
.sort((a, b) => a.length - b.length)
.join("|")})$`
);
function endsInFunc(str) {
return str.match(funcEndingRe);
}
function splitNextGroup(str) {
/** Split the string into `[before, open, group, close, after]` */
const openRE = new RegExp(`^${groupings.open.regexp.source}`);
const closeRE = new RegExp(`^${groupings.close.regexp.source}`);
let start;
let stop;
let open;
let close;
let inners = 0;
let i = 0;
while (i < str.length) {
const rest = str.slice(i);
const openMatch = rest.match(openRE);
const closeMatch = rest.match(closeRE);
if (openMatch) {
if (typeof start !== "number") {
start = i;
[open] = openMatch;
}
inners += 1;
i += openMatch[0].length;
} else if (closeMatch) {
inners -= 1;
if (inners === 0) {
[close] = closeMatch;
stop = i + (close.length - 1);
break;
}
i += closeMatch[0].length;
} else {
i += 1;
}
}
if (!open) {
return null;
}
return [
start === 0 ? "" : str.slice(0, start),
groupings.open.get(open),
str.slice(
start + open.length,
close ? stop - (close.length - 1) : str.length
),
close ? groupings.close.get(close) : "",
stop ? str.slice(stop + 1) : ""
];
}
function isvertGroupStart(str) {
if (!str.startsWith("|")) {
return false;
}
const split = splitNextVert(str);
return split && split[0] === "";
}
function splitNextVert(str) {
function retval(start, stop, double) {
return [
start === 0 ? "" : str.slice(0, start),
double ? "‖" : "|",
str.slice(start + (double ? 2 : 1), stop),
double ? "‖" : "|",
str.slice(stop + (double ? 2 : 1))
];
}
const start = str.indexOf("|");
let stop = start + 1;
let rest = str.slice(start + 1);
const double = rest.startsWith("|");
const re = double ? /\|\|/ : /\|/;
if (double) {
rest = rest.slice(1);
stop += 1;
}
if (rest.indexOf("|") === -1) {
return null;
}
if (rest.match(/^\.?[_^]/)) {
return null;
}
while (rest.length > 0) {
const split = splitNextGroup(rest);
const head = split ? split[0] : rest;
const tail = split ? split[4] : "";
const match = re.exec(head);
if (match) {
return retval(start, stop + match.index, double);
}
stop += split
.slice(0, -1)
.map(dot("length"))
.reduce(plus);
// adjust for slim brackets
Iif (split[1] === "") {
stop += 2;
} else Iif (split[1] === "〈") {
stop += 1;
}
Iif (split[3] === "") {
stop += 2;
} else Iif (split[3] === "〉") {
stop += 1;
}
rest = tail;
}
return null;
}
function dot(attr) {
return obj => obj[attr];
}
function plus(a, b) {
return a + b;
}
// Fonts
// =====
function isforcedEl(reEnd) {
const re = new RegExp(`^(${fonts.regexp.source} ?)?${reEnd}`);
return str => re.exec(str);
}
const isforcedIdentifier = isforcedEl("(`)\\w+`");
const isforcedText = isforcedEl('(")');
function isfontCommand(str) {
return isforcedIdentifier(str) || isforcedText(str);
}
function splitfont(ascii) {
const typematch = isforcedIdentifier(ascii) || isforcedText(ascii);
const font = typematch && typematch[2];
const type = typematch && typematch[3];
let tagname = "";
if (type === '"') {
tagname = "mtext";
} else Eif (type === "`") {
tagname = "mi";
}
const start = ascii.indexOf(type);
const stop = start + 1 + ascii.slice(start + 1).indexOf(type);
const fontvariant = start > 0 ? fonts.get(font) : "";
return {
tagname,
text: ascii.slice(start + 1, stop),
font: fontvariant,
rest: ascii.slice(stop + 1)
};
}
const underEls = ["<mi>lim</mi>", "<mo>∑</mo>", "<mo>∏</mo>"];
function shouldGoUnder(el) {
return underEls.indexOf(el) >= 0;
}
const syntax = {
endsInFunc,
isgroupStart,
isgroupable,
isvertGroupStart,
splitNextGroup,
splitNextVert,
splitNextOperator,
ismatrixInterior,
isfontCommand,
splitfont,
shouldGoUnder
};
export default syntax;
|