A world-class math input for the web
at main 27 lines 745 B view raw
1import { 2 CaretParser, 3 CaretNode, 4 CaretLeafParselet, 5 TokensTag, 6} from "@caret-js/core"; 7import { ParenthesesToken } from "../tokens/parentheses"; 8import { NodeTag } from "@caret-js/core"; 9 10export class ParenthesesChildTag extends NodeTag<false> { 11 public readonly allowMultiple = false; 12 equals(other: this): boolean { 13 return other instanceof ParenthesesChildTag; 14 } 15} 16 17export class ParenthesesParselet extends CaretLeafParselet { 18 parse(parser: CaretParser): CaretNode { 19 const token = parser.consume(); 20 this.assert(token instanceof ParenthesesToken, "Expected ParenthesesToken"); 21 22 return parser 23 .parseSubStrand(token.child) 24 .addTag(new TokensTag([token])) 25 .addTag(new ParenthesesChildTag()); 26 } 27}