Introduce recognizers

This commit is contained in:
Yura Dupyn 2026-04-25 11:55:46 +02:00
parent a56020cd9f
commit bb9ca93f4e
4 changed files with 91 additions and 16 deletions

View file

@ -1,5 +1,6 @@
import { sourceText } from 'source-region';
import { CodePointString, sourceText } from 'source-region';
import { parseDocument } from './parser';
import { matchCodePointString } from './recognizers';
import { Expr } from './syntax';
// === Experiments ===
@ -32,6 +33,15 @@ function experiment06_unicodeSpans(): void {
logParse("unicode spans", "alpha 💥 (beta 2)");
}
function experiment07_matchCodePointString(): void {
const region = sourceText("λx").fullRegion();
const cursor = region.makeCursor();
const lambda = CodePointString.makeFromString("λ");
console.log("==== recognizer:match code point string ====");
console.dir(matchCodePointString(cursor, lambda), { depth: null });
console.log("cursor", cursor.current());
}
function logParse(name: string, input: string): void {
const region = sourceText(input).fullRegion();
const result = parseDocument(region);
@ -49,4 +59,5 @@ function logParse(name: string, input: string): void {
experiment04_recoverAtDocumentLevel,
experiment05_recoverInsideList,
experiment06_unicodeSpans,
experiment07_matchCodePointString,
].forEach((experiment) => experiment());