UNPKG

prong-editor

Version:

Prong (PRojectional jsON Gui) is an editor framework for creating bespoke in-browser editors for JSON-based domain-specific languages (such as [Vega](https://vega.github.io/vega/), [Vega-Lite](https://vega.github.io/vega-lite/), [Tracery](https://tracery.

159 lines (158 loc) 5.53 kB
import { ErrorCode } from "./utils"; import { Severity } from "./validator"; export declare type ASTNode = ObjectASTNode | PropertyASTNode | ArrayASTNode | StringASTNode | NumberASTNode | BooleanASTNode | NullASTNode; export interface BaseASTNode { readonly type: "object" | "array" | "property" | "string" | "number" | "boolean" | "null"; readonly parent?: ASTNode; readonly offset: number; readonly length: number; readonly children?: ASTNode[]; readonly value?: string | boolean | number | null; } export interface ObjectASTNode extends BaseASTNode { readonly type: "object"; readonly properties: PropertyASTNode[]; readonly children: ASTNode[]; } export interface PropertyASTNode extends BaseASTNode { readonly type: "property"; readonly keyNode: StringASTNode; readonly valueNode?: ASTNode; readonly colonOffset?: number; readonly children: ASTNode[]; } export interface ArrayASTNode extends BaseASTNode { readonly type: "array"; readonly items: ASTNode[]; readonly children: ASTNode[]; } export interface StringASTNode extends BaseASTNode { readonly type: "string"; readonly value: string; } export interface NumberASTNode extends BaseASTNode { readonly type: "number"; readonly value: number; readonly isInteger: boolean; } export interface BooleanASTNode extends BaseASTNode { readonly type: "boolean"; readonly value: boolean; } export interface NullASTNode extends BaseASTNode { readonly type: "null"; readonly value: null; } /** * A range in a text document expressed as (zero-based) start and end positions. * * If you want to specify a range that contains a line including the line ending * character(s) then use an end position denoting the start of the next line. * For example: * ```ts * { * start: { line: 5, character: 23 } * end : { line 6, character : 0 } * } * ``` */ export interface Range { /** * The range's start position */ start: Position; /** * The range's end position. */ end: Position; } interface Diagnostic { range: Range; message: string; severity: Severity; code: ErrorCode; language: "json"; } export declare function parse(text: string): { root: ASTNode | undefined; problems: Diagnostic[]; }; export declare abstract class ASTNodeImpl { abstract readonly type: "object" | "property" | "array" | "number" | "boolean" | "null" | "string"; offset: number; length: number; readonly parent: ASTNode | undefined; constructor(parent: ASTNode | undefined, offset: number, length?: number); get children(): ASTNode[]; toString(): string; } export declare class NullASTNodeImpl extends ASTNodeImpl implements NullASTNode { type: "null"; value: null; constructor(parent: ASTNode | undefined, offset: number); } export declare class BooleanASTNodeImpl extends ASTNodeImpl implements BooleanASTNode { type: "boolean"; value: boolean; constructor(parent: ASTNode | undefined, boolValue: boolean, offset: number); } export declare class ArrayASTNodeImpl extends ASTNodeImpl implements ArrayASTNode { type: "array"; items: ASTNode[]; constructor(parent: ASTNode | undefined, offset: number); get children(): ASTNode[]; } export declare class NumberASTNodeImpl extends ASTNodeImpl implements NumberASTNode { type: "number"; isInteger: boolean; value: number; constructor(parent: ASTNode | undefined, offset: number); } export declare class StringASTNodeImpl extends ASTNodeImpl implements StringASTNode { type: "string"; value: string; constructor(parent: ASTNode | undefined, offset: number, length?: number); } export declare class PropertyASTNodeImpl extends ASTNodeImpl implements PropertyASTNode { type: "property"; keyNode: StringASTNode; valueNode?: ASTNode; colonOffset: number; constructor(parent: ObjectASTNode | undefined, offset: number, keyNode: StringASTNode); get children(): ASTNode[]; } export declare class ObjectASTNodeImpl extends ASTNodeImpl implements ObjectASTNode { type: "object"; properties: PropertyASTNode[]; constructor(parent: ASTNode | undefined, offset: number); get children(): ASTNode[]; } /** * Position in a text document expressed as zero-based line and character offset. * The offsets are based on a UTF-16 string representation. So a string of the form * `a𐐀b` the character offset of the character `a` is 0, the character offset of `𐐀` * is 1 and the character offset of b is 3 since `𐐀` is represented using two code * units in UTF-16. * * Positions are line end character agnostic. So you can not specify a position that * denotes `\r|\n` or `\n|` where `|` represents the character offset. */ export interface Position { /** * Line position in a document (zero-based). * If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document. * If a line number is negative, it defaults to 0. */ line: number; /** * Character offset on a line in a document (zero-based). Assuming that the line is * represented as a string, the `character` value represents the gap between the * `character` and `character + 1`. * * If the character value is greater than the line length it defaults back to the * line length. * If a line number is negative, it defaults to 0. */ character: number; } export {};