Develop a partial syntax parser.
This commit is contained in:
parent
84cfc5863e
commit
b2e96b9a22
9 changed files with 721 additions and 257 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { CodePointString, sourceText } from 'source-region';
|
||||
import { parseDocument } from './parser';
|
||||
import { matchCodePointString } from './recognizers';
|
||||
import { Expr } from './syntax';
|
||||
import { Program, programOf } from './syntax';
|
||||
|
||||
// === Experiments ===
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ function experiment00_emptyDocument(): void {
|
|||
}
|
||||
|
||||
function experiment01_topLevelExpressions(): void {
|
||||
logParse("top-level expressions", "foo 123 (bar baz_1 qux-2)");
|
||||
logParse("top-level expressions", "foo 123 (bar baz_1 qux-2) [a, b, c]");
|
||||
}
|
||||
|
||||
function experiment02_nestedLists(): void {
|
||||
|
|
@ -42,12 +42,24 @@ function experiment07_matchCodePointString(): void {
|
|||
console.log("cursor", cursor.current());
|
||||
}
|
||||
|
||||
function experiment08_squareListSeparator(): void {
|
||||
logParse("square list separator", "[a, b c, d]");
|
||||
}
|
||||
|
||||
function experiment09_invalidNumberFragment(): void {
|
||||
logParse("invalid number fragment", "123fasd");
|
||||
}
|
||||
|
||||
function experiment10_repeatedLeadingComma(): void {
|
||||
logParse("repeated leading comma", "[, , foo, bar]");
|
||||
}
|
||||
|
||||
function logParse(name: string, input: string): void {
|
||||
const region = sourceText(input).fullRegion();
|
||||
const result = parseDocument(region);
|
||||
console.log(`==== parser:${name} ====`);
|
||||
console.log(input);
|
||||
console.log(result.values.map(Expr.show));
|
||||
console.log(result.syntax.tag, Program.show(programOf(result.syntax)));
|
||||
console.dir(result.errors, { depth: null });
|
||||
}
|
||||
|
||||
|
|
@ -60,4 +72,7 @@ function logParse(name: string, input: string): void {
|
|||
experiment05_recoverInsideList,
|
||||
experiment06_unicodeSpans,
|
||||
experiment07_matchCodePointString,
|
||||
experiment08_squareListSeparator,
|
||||
experiment09_invalidNumberFragment,
|
||||
experiment10_repeatedLeadingComma,
|
||||
].forEach((experiment) => experiment());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue