Moving stuff around
This commit is contained in:
parent
309fa373f4
commit
2129c26fe5
5 changed files with 29 additions and 32 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import { CodePointString, sourceText } from 'source-region';
|
import { CodePointString, sourceText } from 'source-region';
|
||||||
import { parseDocument } from './parser';
|
import { parseDocument } from './parser';
|
||||||
import { matchCodePointString } from './recognizers';
|
import { matchCodePointString } from './recognizers';
|
||||||
import { Program, programOf } from './syntax';
|
import { Program } from './syntax';
|
||||||
|
|
||||||
// === Experiments ===
|
// === Experiments ===
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ import type { FoundSyntax, ParseError } from './parse_errors';
|
||||||
import { consumeWhile, consumeWhile1, skipWhile } from './recognizers';
|
import { consumeWhile, consumeWhile1, skipWhile } from './recognizers';
|
||||||
import {
|
import {
|
||||||
ConcreteError,
|
ConcreteError,
|
||||||
ConcreteSyntaxResult,
|
|
||||||
DelimiterToken,
|
DelimiterToken,
|
||||||
Expr,
|
Expr,
|
||||||
ListItem,
|
ListItem,
|
||||||
|
|
@ -25,8 +24,6 @@ import {
|
||||||
import type {
|
import type {
|
||||||
ConcreteInfo,
|
ConcreteInfo,
|
||||||
ListItem as ListItemType,
|
ListItem as ListItemType,
|
||||||
PartialConcreteSyntax,
|
|
||||||
ValidConcreteSyntax,
|
|
||||||
Expr as ExprType,
|
Expr as ExprType,
|
||||||
} from './syntax';
|
} from './syntax';
|
||||||
|
|
||||||
|
|
@ -55,14 +52,39 @@ const COMMA = char(',');
|
||||||
const DASH = char('-');
|
const DASH = char('-');
|
||||||
const UNDERSCORE = char('_');
|
const UNDERSCORE = char('_');
|
||||||
|
|
||||||
|
|
||||||
|
export type ConcreteSyntaxResult =
|
||||||
|
| { tag: "valid", value: ValidConcreteSyntax }
|
||||||
|
| { tag: "invalid", value: PartialConcreteSyntax }
|
||||||
|
|
||||||
export type ParseDocumentResult = {
|
export type ParseDocumentResult = {
|
||||||
syntax: ConcreteSyntaxResult;
|
syntax: ConcreteSyntaxResult;
|
||||||
errors: ParseError[];
|
errors: ParseError[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// The main constraints are
|
||||||
|
// - `ValidConcreteSyntax` should be a subtype of `PartialConcreteSyntax`
|
||||||
|
// - if `PartialConcreteSyntax` doesn't contain any sort of error nodes, we should be able to coerce it to `ValidConcreteSyntax` without rebuilding the whole tree
|
||||||
|
export type ValidConcreteSyntax = Program<ConcreteInfo, never>
|
||||||
|
export type PartialConcreteSyntax = Program<ConcreteInfo, ConcreteError>
|
||||||
type PartialExpr = ExprType<ConcreteInfo, ConcreteError>;
|
type PartialExpr = ExprType<ConcreteInfo, ConcreteError>;
|
||||||
type PartialListItem = ListItemType<ConcreteInfo, ConcreteError>;
|
type PartialListItem = ListItemType<ConcreteInfo, ConcreteError>;
|
||||||
|
|
||||||
|
export namespace ConcreteSyntaxResult {
|
||||||
|
export function valid(value: ValidConcreteSyntax): ConcreteSyntaxResult {
|
||||||
|
return { tag: "valid", value };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function invalid(value: PartialConcreteSyntax): ConcreteSyntaxResult {
|
||||||
|
return { tag: "invalid", value };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function programOf(result: ConcreteSyntaxResult): PartialConcreteSyntax {
|
||||||
|
return result.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function parseDocument(region: SourceRegion): ParseDocumentResult {
|
export function parseDocument(region: SourceRegion): ParseDocumentResult {
|
||||||
return new Parser(region).parseDocument();
|
return new Parser(region).parseDocument();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,6 @@ import type { ParseError } from './parse_errors';
|
||||||
|
|
||||||
export type ConcreteInfo = { span: CodePointSpan };
|
export type ConcreteInfo = { span: CodePointSpan };
|
||||||
|
|
||||||
export type ConcreteSyntaxResult =
|
|
||||||
| { tag: "valid", value: ValidConcreteSyntax }
|
|
||||||
| { tag: "invalid", value: PartialConcreteSyntax }
|
|
||||||
|
|
||||||
// The main constraints are
|
|
||||||
// - `ValidConcreteSyntax` should be a subtype of `PartialConcreteSyntax`
|
|
||||||
// - if `PartialConcreteSyntax` doesn't contain any sort of error nodes, we should be able to coerce it to `ValidConcreteSyntax` without rebuilding the whole tree
|
|
||||||
export type ValidConcreteSyntax = Program<ConcreteInfo, never>
|
|
||||||
export type PartialConcreteSyntax = Program<ConcreteInfo, ConcreteError>
|
|
||||||
|
|
||||||
export type ConcreteError = ConcreteErrorNode[] // Convention: can't be empty.
|
export type ConcreteError = ConcreteErrorNode[] // Convention: can't be empty.
|
||||||
export type ConcreteErrorNode = {
|
export type ConcreteErrorNode = {
|
||||||
span: CodePointSpan,
|
span: CodePointSpan,
|
||||||
|
|
@ -78,16 +68,6 @@ export type Literal<Info, Error> =
|
||||||
|
|
||||||
export type Identifier = string
|
export type Identifier = string
|
||||||
|
|
||||||
export namespace ConcreteSyntaxResult {
|
|
||||||
export function valid(value: ValidConcreteSyntax): ConcreteSyntaxResult {
|
|
||||||
return { tag: "valid", value };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function invalid(value: PartialConcreteSyntax): ConcreteSyntaxResult {
|
|
||||||
return { tag: "invalid", value };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export namespace Program {
|
export namespace Program {
|
||||||
export function make<Info, Error>(
|
export function make<Info, Error>(
|
||||||
expressions: Expr<Info, Error>[],
|
expressions: Expr<Info, Error>[],
|
||||||
|
|
@ -170,7 +150,3 @@ export namespace ListItem {
|
||||||
return Expr.show(item);
|
return Expr.show(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function programOf(result: ConcreteSyntaxResult): PartialConcreteSyntax {
|
|
||||||
return result.value;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
import { createMemo, createSignal } from 'solid-js';
|
import { createMemo, createSignal } from 'solid-js';
|
||||||
import { sourceText } from 'source-region';
|
import { sourceText } from 'source-region';
|
||||||
import type { CodePointSpan, SourceRegion, SourceText } from 'source-region';
|
import type { CodePointSpan, SourceRegion, SourceText } from 'source-region';
|
||||||
import { parseDocument } from '../parser';
|
import { parseDocument, programOf } from '../parser';
|
||||||
|
import type { ConcreteSyntaxResult, PartialConcreteSyntax } from '../parser';
|
||||||
import type { ParseError } from '../parse_errors';
|
import type { ParseError } from '../parse_errors';
|
||||||
import { programOf } from '../syntax';
|
|
||||||
import type { ConcreteSyntaxResult, PartialConcreteSyntax } from '../syntax';
|
|
||||||
import { spanLabel } from './format';
|
import { spanLabel } from './format';
|
||||||
import { PaneHeader, PaneSplitter } from './Pane';
|
import { PaneHeader, PaneSplitter } from './Pane';
|
||||||
import { SourceGrid } from './SourceGrid';
|
import { SourceGrid } from './SourceGrid';
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ import type {
|
||||||
ConcreteInfo,
|
ConcreteInfo,
|
||||||
List,
|
List,
|
||||||
ListItem,
|
ListItem,
|
||||||
PartialConcreteSyntax,
|
|
||||||
Expr as SyntaxExpr,
|
Expr as SyntaxExpr,
|
||||||
} from '../syntax';
|
} from '../syntax';
|
||||||
|
import type { PartialConcreteSyntax } from '../parser';
|
||||||
import { Expr } from '../syntax';
|
import { Expr } from '../syntax';
|
||||||
import { errorDetail, errorTitle, spanLabel } from './format';
|
import { errorDetail, errorTitle, spanLabel } from './format';
|
||||||
import type { HoverTarget } from './types';
|
import type { HoverTarget } from './types';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue