A world-class math input for the web
at main 25 lines 822 B view raw
1import { 2 CaretNode, 3 CaretParser, 4 CaretPrefixParselet, 5 TokensTag, 6} from "@caret-js/core"; 7import { CharToken } from "@caret-js/core"; 8import { PositiveNode } from "../nodes/positive"; 9 10// This parselet looks for a sequence of `CharToken`s that form a decimal number, 11// meaning it has digits, optionally a single decimal point, and more digits. The digits 12// are optional on either side of the decimal point, but at least one digit must be present. 13 14export class UnaryPlusParselet extends CaretPrefixParselet { 15 parse(parser: CaretParser): CaretNode { 16 const token = parser.consume(); 17 this.assert( 18 token instanceof CharToken && token.char === "+", 19 "Expected '+' token" 20 ); 21 22 const child = parser.parseMinBP(this); 23 return PositiveNode.from(child).addTag(new TokensTag([token])); 24 } 25}