@spellu/engine
Advanced tools
Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "@spellu/engine", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -16,2 +16,5 @@ "description": "Spellu is a parser combinator engine.", | ||
], | ||
"engines": { | ||
"node": "~13" | ||
}, | ||
"scripts": { | ||
@@ -23,4 +26,3 @@ "build": "../../node_modules/.bin/esmc" | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"gitHead": "6a75afcfce0050588b0485785b3fee6719dfa0a6" | ||
} | ||
} |
@@ -5,6 +5,2 @@ declare namespace spellu { | ||
}; | ||
interface SourceFile { | ||
path: string; | ||
text: string; | ||
} | ||
interface TextRange { | ||
@@ -19,15 +15,20 @@ begin: number; | ||
interface Node { | ||
syntax: string; | ||
range: TextRange; | ||
syntax: string; | ||
} | ||
interface Token extends Node { | ||
syntax: string; | ||
string: string; | ||
value: string; | ||
raw: string; | ||
cooked: string; | ||
comments?: Comment[]; | ||
} | ||
type Comment = Token[]; | ||
interface Indent extends Node { | ||
syntax: 'text.indent'; | ||
string: string; | ||
const enum Syntax { | ||
Indentation = "$.indentation", | ||
Samedent = "$.samedent", | ||
Indent = "$.indent", | ||
Outdent = "$.outdent" | ||
} | ||
interface Indentation extends Token { | ||
syntax: Syntax.Indentation | Syntax.Samedent | Syntax.Indent | Syntax.Outdent; | ||
level: number; | ||
@@ -57,3 +58,8 @@ } | ||
declare namespace spellu { | ||
interface SourceOption { | ||
function createToken(syntax: string, position: number, raw: string, cooked: string): Token; | ||
function createIndentation(syntax: Syntax.Indentation | Syntax.Samedent | Syntax.Indent | Syntax.Outdent, position: number, raw: string, level: number): Indentation; | ||
function createNode<N extends Node>(scaned: Node | (Node | null)[] | any, syntax: string, properties: {}): N; | ||
} | ||
declare namespace spellu { | ||
interface SourceOptions { | ||
normalize?: boolean; | ||
@@ -63,5 +69,6 @@ } | ||
readonly input: string; | ||
protected location: string; | ||
readonly location: string; | ||
protected tabWidth: number; | ||
protected linePositions?: number[]; | ||
constructor(input: string, location: string, option?: SourceOption); | ||
constructor(input: string, location: string, options?: SourceOptions); | ||
protected normalizeSource(string: string): string; | ||
@@ -73,4 +80,6 @@ protected stripUtf8Bom(string: string): string; | ||
position2d(position: number): Location; | ||
getColumnNo(line: string, columnIndex: number): number; | ||
getLinePositions(): number[]; | ||
getLine(line: number): string | null; | ||
getLine(line: number): string; | ||
replaceTab(line: string): string; | ||
getExcerpt(position: number, maxLength: number): string; | ||
@@ -80,3 +89,3 @@ } | ||
declare namespace spellu { | ||
interface SourceStreamOption { | ||
interface SourceStreamOptions { | ||
length?: number; | ||
@@ -89,10 +98,8 @@ position?: number; | ||
position: number; | ||
constructor(input: string, option?: SourceStreamOption); | ||
constructor(input: string, options?: SourceStreamOptions); | ||
clone(): SourceStream; | ||
charCodeAt(offset?: number): number; | ||
substring(length: number): string; | ||
nowEol(): boolean; | ||
nowEos(): boolean; | ||
startsWith(pattern: string): boolean; | ||
test(pattern: string | RegExp): boolean; | ||
skip(length: number): number; | ||
@@ -102,7 +109,8 @@ consume(pattern: string | RegExp): boolean; | ||
scan(syntax: string, pattern: string | RegExp, matchIndex?: number): Token | null; | ||
fetchIndent(pattern?: string | RegExp): Indent; | ||
scanIndent(pattern?: string | RegExp): Indent; | ||
fetchIndentation(pattern?: string | RegExp): Indentation; | ||
scanIndentation(syntax: Syntax.Samedent | Syntax.Indent, pattern?: string | RegExp): Indentation; | ||
test<T>(pattern: string | RegExp, converter: (result: string[]) => T, defaultValue: T): T; | ||
read<T>(pattern: string | RegExp, converter: (result: string[]) => T, defaultValue: T): T; | ||
match<T>(pattern: string | RegExp, converter: (result: string[]) => T, defaultValue: T, option?: { | ||
locationUpdate?: boolean; | ||
match<T>(pattern: string | RegExp, converter: (result: string[]) => T, defaultValue: T, option: { | ||
locationUpdate: boolean; | ||
}): T; | ||
@@ -116,4 +124,2 @@ matchString<T>(pattern: string, converter: (result: string[]) => T, defaultValue: T, option?: { | ||
protected regexp(stringOrPattern: string | RegExp): RegExp; | ||
token(syntax: string, position: number, string: string | undefined, value: string): Token; | ||
indent(position: number, string: string | undefined, level: number): Indent; | ||
protected updateLocation(string: string): void; | ||
@@ -124,2 +130,3 @@ } | ||
type TextPrinterOptions = { | ||
space?: string; | ||
indent?: number | 'tab'; | ||
@@ -129,2 +136,4 @@ lineBreak?: string; | ||
class TextPrinter { | ||
constructor(options?: TextPrinterOptions); | ||
_space: string; | ||
_indent: number | 'tab'; | ||
@@ -135,3 +144,3 @@ _lineBreak: string; | ||
_line: string; | ||
constructor(options?: TextPrinterOptions); | ||
_(condition?: boolean): this; | ||
indentUp(level?: number): this; | ||
@@ -194,6 +203,8 @@ indentDown(level?: number): this; | ||
class Parser<V> { | ||
constructor(runner: (m: Machine) => ParserResult<V>, name?: string, args?: any[]); | ||
static lastId: number; | ||
readonly id: number; | ||
readonly runner: (m: Machine) => ParserResult<V>; | ||
readonly name?: string; | ||
readonly args?: any[]; | ||
constructor(runner: (m: Machine) => ParserResult<V>, name?: string, args?: any[]); | ||
run(m: Machine): ParserResult<V>; | ||
@@ -220,6 +231,21 @@ andL<T>(parser: Parser<T>): Parser<V>; | ||
const BLANKLINE_PATTERN: RegExp; | ||
interface ParsedHistory { | ||
position: number; | ||
parser: Parser<any>; | ||
result: ParserResult<any>; | ||
state: Dictionary<any>; | ||
} | ||
interface MachineOptions { | ||
debug?: boolean; | ||
memorable?: boolean; | ||
maxRepeat?: number; | ||
spacePattern?: RegExp; | ||
} | ||
class Machine { | ||
constructor(input: SourceStream, cluster: Dictionary<Board>); | ||
constructor(input: SourceStream, cluster: Dictionary<Board>, options?: MachineOptions); | ||
input: SourceStream; | ||
cluster: Dictionary<Board>; | ||
debug: boolean; | ||
memorable: boolean; | ||
maxRepeat: number; | ||
spacePattern: RegExp; | ||
@@ -230,6 +256,7 @@ commentParser: Parser<Token> | null; | ||
inSkipComment: boolean; | ||
parsedCache: Map<number, ParsedHistory[]>; | ||
expectedRules: Expected[]; | ||
diagnoses: Diagnosis[]; | ||
logs: string[]; | ||
run<V>(parser: Parser<V>): ParserResult<V>; | ||
run<V>(parser: Parser<V>, memoization?: boolean): ParserResult<V>; | ||
success<V>(value: V): Success<V>; | ||
@@ -244,22 +271,9 @@ failure<V>(value: V): Failure<V>; | ||
consumeSkippedComments(): Comment[]; | ||
scanIndentation(): Indentation | null; | ||
retrieve<V>(path: string): Parser<V>; | ||
findParsedResult(position: number, parser: Parser<any>): ParserResult<any> | null; | ||
recordParsedResult(position: number, parser: Parser<any>, result: ParserResult<any>): void; | ||
fixExpectedRules(): void; | ||
clearExpectedRules(): void; | ||
} | ||
interface ParserBox<V> { | ||
(...args: any[]): Parser<V>; | ||
} | ||
function delay<V>(box: ParserBox<V>, ...args: any[]): Parser<V>; | ||
interface TokenPattern { | ||
syntax: string; | ||
pattern: string | RegExp; | ||
label?: string; | ||
capture?: number; | ||
value?: string; | ||
} | ||
function token(sticky: boolean, pattern: TokenPattern | TokenPattern[]): Parser<Token>; | ||
function indentUp<V>(parser: Parser<V>): Parser<V | null>; | ||
function indent(): Parser<Indent>; | ||
function eol(): Parser<Comment[]>; | ||
function ruleRef<V>(rulePath: string): Parser<V>; | ||
} | ||
@@ -271,7 +285,7 @@ declare namespace spellu { | ||
protected _rules: Dictionary<ParserBox<any>>; | ||
protected _spacePattern: RegExp; | ||
protected _spacePattern?: RegExp; | ||
protected _commentRuleName?: string; | ||
protected _parsers: Dictionary<Parser<any>>; | ||
name(): string; | ||
spacePattern(): RegExp; | ||
spacePattern(): RegExp | undefined; | ||
ruleExists(name: string): boolean; | ||
@@ -286,2 +300,20 @@ ruleNames(): string[]; | ||
declare namespace spellu { | ||
interface ParserBox<V> { | ||
(...args: any[]): Parser<V>; | ||
} | ||
function delay<V>(box: ParserBox<V>, ...args: any[]): Parser<V>; | ||
interface TokenPattern { | ||
syntax: string; | ||
pattern: string | RegExp; | ||
label?: string; | ||
capture?: number; | ||
value?: string; | ||
} | ||
function token(sticky: boolean, pattern: TokenPattern | TokenPattern[]): Parser<Token>; | ||
function block<V>(parser: Parser<V>): Parser<V[]>; | ||
function indent(): Parser<Indentation>; | ||
function outdent(): Parser<Indentation>; | ||
function samedent(): Parser<Indentation>; | ||
function eol(): Parser<Comment[]>; | ||
function ruleRef<V>(rulePath: string): Parser<V>; | ||
function and<V1>(p1: Parser<V1>): Parser<V1>; | ||
@@ -310,2 +342,4 @@ function and<V1, V2>(p1: Parser<V1>, p2: Parser<V2>): Parser<[V1, V2]>; | ||
function recover<V>(parser: Parser<V>, callback: (machine: Machine) => void): Parser<V>; | ||
} | ||
declare namespace spellu { | ||
function $$<V1>(p1: Parser<V1>): Parser<V1>; | ||
@@ -370,2 +404,4 @@ function $$<V1, V2>(p1: Parser<V1>, p2: Parser<V2>): Parser<[V1, V2]>; | ||
} | ||
} | ||
declare namespace spellu { | ||
function $0<V1>(p1: Parser<V1>): Parser<V1[]>; | ||
@@ -429,2 +465,4 @@ function $0<V1, V2>(p1: Parser<V1>, p2: Parser<V2>): Parser<[V1, V2][]>; | ||
} | ||
} | ||
declare namespace spellu { | ||
function $1<V1>(p1: Parser<V1>): Parser<V1[]>; | ||
@@ -488,2 +526,4 @@ function $1<V1, V2>(p1: Parser<V1>, p2: Parser<V2>): Parser<[V1, V2][]>; | ||
} | ||
} | ||
declare namespace spellu { | ||
function $_<V1>(p1: Parser<V1>): Parser<V1 | null>; | ||
@@ -546,2 +586,4 @@ function $_<V1, V2>(p1: Parser<V1>, p2: Parser<V2>): Parser<[V1, V2] | null>; | ||
} | ||
} | ||
declare namespace spellu { | ||
function $<V>(box: ParserBox<V>, ...args: any[]): Parser<V>; | ||
@@ -557,2 +599,3 @@ namespace $ { | ||
allowTrailingSeparator: boolean; | ||
multiplicity?: number; | ||
}): Parser<V[]>; | ||
@@ -566,4 +609,6 @@ function alternate<V, C>(valueParser: Parser<V>, combinorParser: Parser<C>): Parser<(V | C)[]>; | ||
function annex(pattern: TokenPattern | TokenPattern[]): Parser<Token>; | ||
function indentUp<V>(parser: Parser<V>): Parser<V | null>; | ||
function indent(): Parser<Indent>; | ||
function block<V>(parser: Parser<V>): Parser<V[] | null>; | ||
function indent(): Parser<Indentation>; | ||
function outdent(): Parser<Indentation>; | ||
function samedent(): Parser<Indentation>; | ||
function eol(): Parser<Comment[]>; | ||
@@ -575,2 +620,5 @@ function tap<T>(object: T, callback: (object: T) => void): T; | ||
declare namespace spellu { | ||
function source(string: string, location?: string): Source; | ||
} | ||
declare namespace spellu { | ||
type ScanOptions = { | ||
@@ -581,3 +629,2 @@ boards?: Board[]; | ||
}; | ||
function source(string: string, location?: string): Source; | ||
function scan<V>(ruleOrParser: string | Parser<V>, source: Source, options?: ScanOptions): Success<V> | Failure<Diagnosis[]>; | ||
@@ -584,0 +631,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109206
2209