1 |
|
2 | import defineFunction from "../defineFunction";
|
3 | import ParseError from "../ParseError";
|
4 | import {assertNodeType} from "../parseNode";
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | defineFunction({
|
10 | type: "textord",
|
11 | names: ["\\@char"],
|
12 | props: {
|
13 | numArgs: 1,
|
14 | allowedInText: true,
|
15 | },
|
16 | handler({parser}, args) {
|
17 | const arg = assertNodeType(args[0], "ordgroup");
|
18 | const group = arg.body;
|
19 | let number = "";
|
20 | for (let i = 0; i < group.length; i++) {
|
21 | const node = assertNodeType(group[i], "textord");
|
22 | number += node.text;
|
23 | }
|
24 | const code = parseInt(number);
|
25 | if (isNaN(code)) {
|
26 | throw new ParseError(`\\@char has non-numeric argument ${number}`);
|
27 | }
|
28 | return {
|
29 | type: "textord",
|
30 | mode: parser.mode,
|
31 | text: String.fromCharCode(code),
|
32 | };
|
33 | },
|
34 | });
|