update interface button styles

This commit is contained in:
2023-07-28 02:15:00 +02:00
parent aff5e643ac
commit 12c07c83b3
2901 changed files with 1369600 additions and 41 deletions

21
node_modules/@lezer/common/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (C) 2018 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

14
node_modules/@lezer/common/README.md generated vendored Normal file
View File

@ -0,0 +1,14 @@
# @lezer/common
[ [**WEBSITE**](http://lezer.codemirror.net) | [**ISSUES**](https://github.com/lezer-parser/lezer/issues) | [**FORUM**](https://discuss.codemirror.net/c/lezer) | [**CHANGELOG**](https://github.com/lezer-parser/common/blob/master/CHANGELOG.md) ]
[Lezer](https://lezer.codemirror.net/) is an incremental parser system
intended for use in an editor or similar system.
@lezer/common provides the syntax tree data structure and parser
abstractions for Lezer parsers.
Its programming interface is documented on [the
website](https://lezer.codemirror.net/docs/ref/#common).
This code is licensed under an MIT license.

1838
node_modules/@lezer/common/dist/index.cjs generated vendored Normal file

File diff suppressed because it is too large Load Diff

3
node_modules/@lezer/common/dist/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,3 @@
export { DefaultBufferLength, NodeProp, MountedTree, NodePropSource, NodeType, NodeSet, Tree, TreeBuffer, SyntaxNode, SyntaxNodeRef, TreeCursor, BufferCursor, NodeWeakMap, IterMode } from "./tree";
export { ChangedRange, TreeFragment, PartialParse, Parser, Input, ParseWrapper } from "./parse";
export { NestedParse, parseMixed } from "./mix";

1823
node_modules/@lezer/common/dist/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

13
node_modules/@lezer/common/dist/mix.d.ts generated vendored Normal file
View File

@ -0,0 +1,13 @@
import { SyntaxNodeRef } from "./tree";
import { Input, Parser, ParseWrapper } from "./parse";
export interface NestedParse {
parser: Parser;
overlay?: readonly {
from: number;
to: number;
}[] | ((node: SyntaxNodeRef) => {
from: number;
to: number;
} | boolean);
}
export declare function parseMixed(nest: (node: SyntaxNodeRef, input: Input) => NestedParse | null): ParseWrapper;

48
node_modules/@lezer/common/dist/parse.d.ts generated vendored Normal file
View File

@ -0,0 +1,48 @@
import { Tree } from "./tree";
export interface ChangedRange {
fromA: number;
toA: number;
fromB: number;
toB: number;
}
export declare class TreeFragment {
readonly from: number;
readonly to: number;
readonly tree: Tree;
readonly offset: number;
constructor(from: number, to: number, tree: Tree, offset: number, openStart?: boolean, openEnd?: boolean);
get openStart(): boolean;
get openEnd(): boolean;
static addTree(tree: Tree, fragments?: readonly TreeFragment[], partial?: boolean): readonly TreeFragment[];
static applyChanges(fragments: readonly TreeFragment[], changes: readonly ChangedRange[], minGap?: number): readonly TreeFragment[];
}
export interface PartialParse {
advance(): Tree | null;
readonly parsedPos: number;
stopAt(pos: number): void;
readonly stoppedAt: number | null;
}
export declare abstract class Parser {
abstract createParse(input: Input, fragments: readonly TreeFragment[], ranges: readonly {
from: number;
to: number;
}[]): PartialParse;
startParse(input: Input | string, fragments?: readonly TreeFragment[], ranges?: readonly {
from: number;
to: number;
}[]): PartialParse;
parse(input: Input | string, fragments?: readonly TreeFragment[], ranges?: readonly {
from: number;
to: number;
}[]): Tree;
}
export interface Input {
readonly length: number;
chunk(from: number): string;
readonly lineChunks: boolean;
read(from: number, to: number): string;
}
export type ParseWrapper = (inner: PartialParse, input: Input, fragments: readonly TreeFragment[], ranges: readonly {
from: number;
to: number;
}[]) => PartialParse;

262
node_modules/@lezer/common/dist/tree.d.ts generated vendored Normal file
View File

@ -0,0 +1,262 @@
import { Parser } from "./parse";
export declare const DefaultBufferLength = 1024;
export declare class Range {
readonly from: number;
readonly to: number;
constructor(from: number, to: number);
}
export declare class NodeProp<T> {
perNode: boolean;
deserialize: (str: string) => T;
constructor(config?: {
deserialize?: (str: string) => T;
perNode?: boolean;
});
add(match: {
[selector: string]: T;
} | ((type: NodeType) => T | undefined)): NodePropSource;
static closedBy: NodeProp<readonly string[]>;
static openedBy: NodeProp<readonly string[]>;
static group: NodeProp<readonly string[]>;
static contextHash: NodeProp<number>;
static lookAhead: NodeProp<number>;
static mounted: NodeProp<MountedTree>;
}
export declare class MountedTree {
readonly tree: Tree;
readonly overlay: readonly {
from: number;
to: number;
}[] | null;
readonly parser: Parser;
constructor(tree: Tree, overlay: readonly {
from: number;
to: number;
}[] | null, parser: Parser);
}
export type NodePropSource = (type: NodeType) => null | [NodeProp<any>, any];
export declare class NodeType {
readonly name: string;
readonly id: number;
static define(spec: {
id: number;
name?: string;
props?: readonly ([NodeProp<any>, any] | NodePropSource)[];
top?: boolean;
error?: boolean;
skipped?: boolean;
}): NodeType;
prop<T>(prop: NodeProp<T>): T | undefined;
get isTop(): boolean;
get isSkipped(): boolean;
get isError(): boolean;
get isAnonymous(): boolean;
is(name: string | number): boolean;
static none: NodeType;
static match<T>(map: {
[selector: string]: T;
}): (node: NodeType) => T | undefined;
}
export declare class NodeSet {
readonly types: readonly NodeType[];
constructor(types: readonly NodeType[]);
extend(...props: NodePropSource[]): NodeSet;
}
export declare enum IterMode {
ExcludeBuffers = 1,
IncludeAnonymous = 2,
IgnoreMounts = 4,
IgnoreOverlays = 8
}
export declare class Tree {
readonly type: NodeType;
readonly children: readonly (Tree | TreeBuffer)[];
readonly positions: readonly number[];
readonly length: number;
constructor(type: NodeType, children: readonly (Tree | TreeBuffer)[], positions: readonly number[], length: number, props?: readonly [NodeProp<any> | number, any][]);
static empty: Tree;
cursor(mode?: IterMode): TreeCursor;
cursorAt(pos: number, side?: -1 | 0 | 1, mode?: IterMode): TreeCursor;
get topNode(): SyntaxNode;
resolve(pos: number, side?: -1 | 0 | 1): SyntaxNode;
resolveInner(pos: number, side?: -1 | 0 | 1): SyntaxNode;
iterate(spec: {
enter(node: SyntaxNodeRef): boolean | void;
leave?(node: SyntaxNodeRef): void;
from?: number;
to?: number;
mode?: IterMode;
}): void;
prop<T>(prop: NodeProp<T>): T | undefined;
get propValues(): readonly [NodeProp<any> | number, any][];
balance(config?: {
makeTree?: (children: readonly (Tree | TreeBuffer)[], positions: readonly number[], length: number) => Tree;
}): Tree;
static build(data: BuildData): Tree;
}
type BuildData = {
buffer: BufferCursor | readonly number[];
nodeSet: NodeSet;
topID: number;
start?: number;
bufferStart?: number;
length?: number;
maxBufferLength?: number;
reused?: readonly Tree[];
minRepeatType?: number;
};
export interface BufferCursor {
pos: number;
id: number;
start: number;
end: number;
size: number;
next(): void;
fork(): BufferCursor;
}
export declare class TreeBuffer {
readonly buffer: Uint16Array;
readonly length: number;
readonly set: NodeSet;
constructor(buffer: Uint16Array, length: number, set: NodeSet);
}
export interface SyntaxNodeRef {
readonly from: number;
readonly to: number;
readonly type: NodeType;
readonly name: string;
readonly tree: Tree | null;
readonly node: SyntaxNode;
matchContext(context: readonly string[]): boolean;
}
export interface SyntaxNode extends SyntaxNodeRef {
parent: SyntaxNode | null;
firstChild: SyntaxNode | null;
lastChild: SyntaxNode | null;
childAfter(pos: number): SyntaxNode | null;
childBefore(pos: number): SyntaxNode | null;
enter(pos: number, side: -1 | 0 | 1, mode?: IterMode): SyntaxNode | null;
nextSibling: SyntaxNode | null;
prevSibling: SyntaxNode | null;
cursor(mode?: IterMode): TreeCursor;
resolve(pos: number, side?: -1 | 0 | 1): SyntaxNode;
resolveInner(pos: number, side?: -1 | 0 | 1): SyntaxNode;
enterUnfinishedNodesBefore(pos: number): SyntaxNode;
toTree(): Tree;
getChild(type: string | number, before?: string | number | null, after?: string | number | null): SyntaxNode | null;
getChildren(type: string | number, before?: string | number | null, after?: string | number | null): SyntaxNode[];
matchContext(context: readonly string[]): boolean;
}
declare const enum Side {
Before = -2,
AtOrBefore = -1,
Around = 0,
AtOrAfter = 1,
After = 2,
DontCare = 4
}
export declare class TreeNode implements SyntaxNode {
readonly _tree: Tree;
readonly from: number;
readonly index: number;
readonly _parent: TreeNode | null;
constructor(_tree: Tree, from: number, index: number, _parent: TreeNode | null);
get type(): NodeType;
get name(): string;
get to(): number;
nextChild(i: number, dir: 1 | -1, pos: number, side: Side, mode?: IterMode): TreeNode | BufferNode | null;
get firstChild(): TreeNode | BufferNode;
get lastChild(): TreeNode | BufferNode;
childAfter(pos: number): TreeNode | BufferNode;
childBefore(pos: number): TreeNode | BufferNode;
enter(pos: number, side: -1 | 0 | 1, mode?: number): TreeNode | BufferNode;
nextSignificantParent(): TreeNode;
get parent(): TreeNode | null;
get nextSibling(): SyntaxNode | null;
get prevSibling(): SyntaxNode | null;
cursor(mode?: IterMode): TreeCursor;
get tree(): Tree;
toTree(): Tree;
resolve(pos: number, side?: -1 | 0 | 1): SyntaxNode;
resolveInner(pos: number, side?: -1 | 0 | 1): SyntaxNode;
enterUnfinishedNodesBefore(pos: number): SyntaxNode;
getChild(type: string | number, before?: string | number | null, after?: string | number | null): SyntaxNode;
getChildren(type: string | number, before?: string | number | null, after?: string | number | null): SyntaxNode[];
get node(): this;
matchContext(context: readonly string[]): boolean;
}
declare class BufferContext {
readonly parent: TreeNode;
readonly buffer: TreeBuffer;
readonly index: number;
readonly start: number;
constructor(parent: TreeNode, buffer: TreeBuffer, index: number, start: number);
}
declare class BufferNode implements SyntaxNode {
readonly context: BufferContext;
readonly _parent: BufferNode | null;
readonly index: number;
type: NodeType;
get name(): string;
get from(): number;
get to(): number;
constructor(context: BufferContext, _parent: BufferNode | null, index: number);
child(dir: 1 | -1, pos: number, side: Side): BufferNode | null;
get firstChild(): BufferNode;
get lastChild(): BufferNode;
childAfter(pos: number): BufferNode;
childBefore(pos: number): BufferNode;
enter(pos: number, side: -1 | 0 | 1, mode?: IterMode): BufferNode;
get parent(): SyntaxNode | null;
externalSibling(dir: 1 | -1): TreeNode | BufferNode;
get nextSibling(): SyntaxNode | null;
get prevSibling(): SyntaxNode | null;
cursor(mode?: IterMode): TreeCursor;
get tree(): any;
toTree(): Tree;
resolve(pos: number, side?: -1 | 0 | 1): SyntaxNode;
resolveInner(pos: number, side?: -1 | 0 | 1): SyntaxNode;
enterUnfinishedNodesBefore(pos: number): SyntaxNode;
getChild(type: string | number, before?: string | number | null, after?: string | number | null): SyntaxNode;
getChildren(type: string | number, before?: string | number | null, after?: string | number | null): SyntaxNode[];
get node(): this;
matchContext(context: readonly string[]): boolean;
}
export declare class TreeCursor implements SyntaxNodeRef {
type: NodeType;
get name(): string;
from: number;
to: number;
private stack;
private bufferNode;
private yieldNode;
private yieldBuf;
private yield;
firstChild(): boolean;
lastChild(): boolean;
childAfter(pos: number): boolean;
childBefore(pos: number): boolean;
enter(pos: number, side: -1 | 0 | 1, mode?: IterMode): boolean;
parent(): boolean;
nextSibling(): boolean;
prevSibling(): boolean;
private atLastNode;
private move;
next(enter?: boolean): boolean;
prev(enter?: boolean): boolean;
moveTo(pos: number, side?: -1 | 0 | 1): this;
get node(): SyntaxNode;
get tree(): Tree | null;
iterate(enter: (node: SyntaxNodeRef) => boolean | void, leave?: (node: SyntaxNodeRef) => void): void;
matchContext(context: readonly string[]): boolean;
}
export declare class NodeWeakMap<T> {
private map;
private setBuffer;
private getBuffer;
set(node: SyntaxNode, value: T): void;
get(node: SyntaxNode): T | undefined;
cursorSet(cursor: TreeCursor, value: T): void;
cursorGet(cursor: TreeCursor): T | undefined;
}
export {};

36
node_modules/@lezer/common/package.json generated vendored Normal file
View File

@ -0,0 +1,36 @@
{
"name": "@lezer/common",
"version": "1.0.3",
"description": "Syntax tree data structure and parser interfaces for the lezer parser",
"main": "dist/index.cjs",
"type": "module",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"module": "dist/index.js",
"types": "dist/index.d.ts",
"author": "Marijn Haverbeke <marijn@haverbeke.berlin>",
"license": "MIT",
"devDependencies": {
"ist": "^1.1.1",
"rollup": "^2.52.2",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"rollup-plugin-typescript2": "^0.34.1",
"typescript": "^4.3.4",
"@types/mocha": "^5.2.6",
"ts-node": "^10.0.0",
"mocha": "^9.0.1"
},
"files": ["dist"],
"repository": {
"type" : "git",
"url" : "https://github.com/lezer-parser/common.git"
},
"scripts": {
"watch": "rollup -w -c rollup.config.js",
"prepare": "rollup -c rollup.config.js",
"test": "mocha"
}
}

21
node_modules/@lezer/highlight/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (C) 2018 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

14
node_modules/@lezer/highlight/README.md generated vendored Normal file
View File

@ -0,0 +1,14 @@
# @lezer/highlight
[ [**WEBSITE**](http://lezer.codemirror.net) | [**ISSUES**](https://github.com/lezer-parser/lezer/issues) | [**FORUM**](https://discuss.codemirror.net/c/lezer) | [**CHANGELOG**](https://github.com/lezer-parser/highlight/blob/master/CHANGELOG.md) ]
[Lezer](https://lezer.codemirror.net/) is an incremental parser system
intended for use in an editor or similar system.
@lezer/highlight provides a syntax highlighting framework for Lezer
parse trees.
Its programming interface is documented on [the
website](https://lezer.codemirror.net/docs/ref/#highlight).
This code is licensed under an MIT license.

869
node_modules/@lezer/highlight/dist/index.cjs generated vendored Normal file
View File

@ -0,0 +1,869 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var common = require('@lezer/common');
let nextTagID = 0;
/**
Highlighting tags are markers that denote a highlighting category.
They are [associated](#highlight.styleTags) with parts of a syntax
tree by a language mode, and then mapped to an actual CSS style by
a [highlighter](#highlight.Highlighter).
Because syntax tree node types and highlight styles have to be
able to talk the same language, CodeMirror uses a mostly _closed_
[vocabulary](#highlight.tags) of syntax tags (as opposed to
traditional open string-based systems, which make it hard for
highlighting themes to cover all the tokens produced by the
various languages).
It _is_ possible to [define](#highlight.Tag^define) your own
highlighting tags for system-internal use (where you control both
the language package and the highlighter), but such tags will not
be picked up by regular highlighters (though you can derive them
from standard tags to allow highlighters to fall back to those).
*/
class Tag {
/**
@internal
*/
constructor(
/**
The set of this tag and all its parent tags, starting with
this one itself and sorted in order of decreasing specificity.
*/
set,
/**
The base unmodified tag that this one is based on, if it's
modified @internal
*/
base,
/**
The modifiers applied to this.base @internal
*/
modified) {
this.set = set;
this.base = base;
this.modified = modified;
/**
@internal
*/
this.id = nextTagID++;
}
/**
Define a new tag. If `parent` is given, the tag is treated as a
sub-tag of that parent, and
[highlighters](#highlight.tagHighlighter) that don't mention
this tag will try to fall back to the parent tag (or grandparent
tag, etc).
*/
static define(parent) {
if (parent === null || parent === void 0 ? void 0 : parent.base)
throw new Error("Can not derive from a modified tag");
let tag = new Tag([], null, []);
tag.set.push(tag);
if (parent)
for (let t of parent.set)
tag.set.push(t);
return tag;
}
/**
Define a tag _modifier_, which is a function that, given a tag,
will return a tag that is a subtag of the original. Applying the
same modifier to a twice tag will return the same value (`m1(t1)
== m1(t1)`) and applying multiple modifiers will, regardless or
order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
When multiple modifiers are applied to a given base tag, each
smaller set of modifiers is registered as a parent, so that for
example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
`m1(m3(t1)`, and so on.
*/
static defineModifier() {
let mod = new Modifier;
return (tag) => {
if (tag.modified.indexOf(mod) > -1)
return tag;
return Modifier.get(tag.base || tag, tag.modified.concat(mod).sort((a, b) => a.id - b.id));
};
}
}
let nextModifierID = 0;
class Modifier {
constructor() {
this.instances = [];
this.id = nextModifierID++;
}
static get(base, mods) {
if (!mods.length)
return base;
let exists = mods[0].instances.find(t => t.base == base && sameArray(mods, t.modified));
if (exists)
return exists;
let set = [], tag = new Tag(set, base, mods);
for (let m of mods)
m.instances.push(tag);
let configs = powerSet(mods);
for (let parent of base.set)
if (!parent.modified.length)
for (let config of configs)
set.push(Modifier.get(parent, config));
return tag;
}
}
function sameArray(a, b) {
return a.length == b.length && a.every((x, i) => x == b[i]);
}
function powerSet(array) {
let sets = [[]];
for (let i = 0; i < array.length; i++) {
for (let j = 0, e = sets.length; j < e; j++) {
sets.push(sets[j].concat(array[i]));
}
}
return sets.sort((a, b) => b.length - a.length);
}
/**
This function is used to add a set of tags to a language syntax
via [`NodeSet.extend`](#common.NodeSet.extend) or
[`LRParser.configure`](#lr.LRParser.configure).
The argument object maps node selectors to [highlighting
tags](#highlight.Tag) or arrays of tags.
Node selectors may hold one or more (space-separated) node paths.
Such a path can be a [node name](#common.NodeType.name), or
multiple node names (or `*` wildcards) separated by slash
characters, as in `"Block/Declaration/VariableName"`. Such a path
matches the final node but only if its direct parent nodes are the
other nodes mentioned. A `*` in such a path matches any parent,
but only a single level—wildcards that match multiple parents
aren't supported, both for efficiency reasons and because Lezer
trees make it rather hard to reason about what they would match.)
A path can be ended with `/...` to indicate that the tag assigned
to the node should also apply to all child nodes, even if they
match their own style (by default, only the innermost style is
used).
When a path ends in `!`, as in `Attribute!`, no further matching
happens for the node's child nodes, and the entire node gets the
given style.
In this notation, node names that contain `/`, `!`, `*`, or `...`
must be quoted as JSON strings.
For example:
```javascript
parser.withProps(
styleTags({
// Style Number and BigNumber nodes
"Number BigNumber": tags.number,
// Style Escape nodes whose parent is String
"String/Escape": tags.escape,
// Style anything inside Attributes nodes
"Attributes!": tags.meta,
// Add a style to all content inside Italic nodes
"Italic/...": tags.emphasis,
// Style InvalidString nodes as both `string` and `invalid`
"InvalidString": [tags.string, tags.invalid],
// Style the node named "/" as punctuation
'"/"': tags.punctuation
})
)
```
*/
function styleTags(spec) {
let byName = Object.create(null);
for (let prop in spec) {
let tags = spec[prop];
if (!Array.isArray(tags))
tags = [tags];
for (let part of prop.split(" "))
if (part) {
let pieces = [], mode = 2 /* Normal */, rest = part;
for (let pos = 0;;) {
if (rest == "..." && pos > 0 && pos + 3 == part.length) {
mode = 1 /* Inherit */;
break;
}
let m = /^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(rest);
if (!m)
throw new RangeError("Invalid path: " + part);
pieces.push(m[0] == "*" ? "" : m[0][0] == '"' ? JSON.parse(m[0]) : m[0]);
pos += m[0].length;
if (pos == part.length)
break;
let next = part[pos++];
if (pos == part.length && next == "!") {
mode = 0 /* Opaque */;
break;
}
if (next != "/")
throw new RangeError("Invalid path: " + part);
rest = part.slice(pos);
}
let last = pieces.length - 1, inner = pieces[last];
if (!inner)
throw new RangeError("Invalid path: " + part);
let rule = new Rule(tags, mode, last > 0 ? pieces.slice(0, last) : null);
byName[inner] = rule.sort(byName[inner]);
}
}
return ruleNodeProp.add(byName);
}
const ruleNodeProp = new common.NodeProp();
class Rule {
constructor(tags, mode, context, next) {
this.tags = tags;
this.mode = mode;
this.context = context;
this.next = next;
}
get opaque() { return this.mode == 0 /* Opaque */; }
get inherit() { return this.mode == 1 /* Inherit */; }
sort(other) {
if (!other || other.depth < this.depth) {
this.next = other;
return this;
}
other.next = this.sort(other.next);
return other;
}
get depth() { return this.context ? this.context.length : 0; }
}
Rule.empty = new Rule([], 2 /* Normal */, null);
/**
Define a [highlighter](#highlight.Highlighter) from an array of
tag/class pairs. Classes associated with more specific tags will
take precedence.
*/
function tagHighlighter(tags, options) {
let map = Object.create(null);
for (let style of tags) {
if (!Array.isArray(style.tag))
map[style.tag.id] = style.class;
else
for (let tag of style.tag)
map[tag.id] = style.class;
}
let { scope, all = null } = options || {};
return {
style: (tags) => {
let cls = all;
for (let tag of tags) {
for (let sub of tag.set) {
let tagClass = map[sub.id];
if (tagClass) {
cls = cls ? cls + " " + tagClass : tagClass;
break;
}
}
}
return cls;
},
scope
};
}
function highlightTags(highlighters, tags) {
let result = null;
for (let highlighter of highlighters) {
let value = highlighter.style(tags);
if (value)
result = result ? result + " " + value : value;
}
return result;
}
/**
Highlight the given [tree](#common.Tree) with the given
[highlighter](#highlight.Highlighter).
*/
function highlightTree(tree, highlighter,
/**
Assign styling to a region of the text. Will be called, in order
of position, for any ranges where more than zero classes apply.
`classes` is a space separated string of CSS classes.
*/
putStyle,
/**
The start of the range to highlight.
*/
from = 0,
/**
The end of the range.
*/
to = tree.length) {
let builder = new HighlightBuilder(from, Array.isArray(highlighter) ? highlighter : [highlighter], putStyle);
builder.highlightRange(tree.cursor(), from, to, "", builder.highlighters);
builder.flush(to);
}
class HighlightBuilder {
constructor(at, highlighters, span) {
this.at = at;
this.highlighters = highlighters;
this.span = span;
this.class = "";
}
startSpan(at, cls) {
if (cls != this.class) {
this.flush(at);
if (at > this.at)
this.at = at;
this.class = cls;
}
}
flush(to) {
if (to > this.at && this.class)
this.span(this.at, to, this.class);
}
highlightRange(cursor, from, to, inheritedClass, highlighters) {
let { type, from: start, to: end } = cursor;
if (start >= to || end <= from)
return;
if (type.isTop)
highlighters = this.highlighters.filter(h => !h.scope || h.scope(type));
let cls = inheritedClass;
let rule = getStyleTags(cursor) || Rule.empty;
let tagCls = highlightTags(highlighters, rule.tags);
if (tagCls) {
if (cls)
cls += " ";
cls += tagCls;
if (rule.mode == 1 /* Inherit */)
inheritedClass += (inheritedClass ? " " : "") + tagCls;
}
this.startSpan(Math.max(from, start), cls);
if (rule.opaque)
return;
let mounted = cursor.tree && cursor.tree.prop(common.NodeProp.mounted);
if (mounted && mounted.overlay) {
let inner = cursor.node.enter(mounted.overlay[0].from + start, 1);
let innerHighlighters = this.highlighters.filter(h => !h.scope || h.scope(mounted.tree.type));
let hasChild = cursor.firstChild();
for (let i = 0, pos = start;; i++) {
let next = i < mounted.overlay.length ? mounted.overlay[i] : null;
let nextPos = next ? next.from + start : end;
let rangeFrom = Math.max(from, pos), rangeTo = Math.min(to, nextPos);
if (rangeFrom < rangeTo && hasChild) {
while (cursor.from < rangeTo) {
this.highlightRange(cursor, rangeFrom, rangeTo, inheritedClass, highlighters);
this.startSpan(Math.min(rangeTo, cursor.to), cls);
if (cursor.to >= nextPos || !cursor.nextSibling())
break;
}
}
if (!next || nextPos > to)
break;
pos = next.to + start;
if (pos > from) {
this.highlightRange(inner.cursor(), Math.max(from, next.from + start), Math.min(to, pos), "", innerHighlighters);
this.startSpan(Math.min(to, pos), cls);
}
}
if (hasChild)
cursor.parent();
}
else if (cursor.firstChild()) {
if (mounted)
inheritedClass = "";
do {
if (cursor.to <= from)
continue;
if (cursor.from >= to)
break;
this.highlightRange(cursor, from, to, inheritedClass, highlighters);
this.startSpan(Math.min(to, cursor.to), cls);
} while (cursor.nextSibling());
cursor.parent();
}
}
}
/**
Match a syntax node's [highlight rules](#highlight.styleTags). If
there's a match, return its set of tags, and whether it is
opaque (uses a `!`) or applies to all child nodes (`/...`).
*/
function getStyleTags(node) {
let rule = node.type.prop(ruleNodeProp);
while (rule && rule.context && !node.matchContext(rule.context))
rule = rule.next;
return rule || null;
}
const t = Tag.define;
const comment = t(), name = t(), typeName = t(name), propertyName = t(name), literal = t(), string = t(literal), number = t(literal), content = t(), heading = t(content), keyword = t(), operator = t(), punctuation = t(), bracket = t(punctuation), meta = t();
/**
The default set of highlighting [tags](#highlight.Tag).
This collection is heavily biased towards programming languages,
and necessarily incomplete. A full ontology of syntactic
constructs would fill a stack of books, and be impractical to
write themes for. So try to make do with this set. If all else
fails, [open an
issue](https://github.com/codemirror/codemirror.next) to propose a
new tag, or [define](#highlight.Tag^define) a local custom tag for
your use case.
Note that it is not obligatory to always attach the most specific
tag possible to an element—if your grammar can't easily
distinguish a certain type of element (such as a local variable),
it is okay to style it as its more general variant (a variable).
For tags that extend some parent tag, the documentation links to
the parent.
*/
const tags = {
/**
A comment.
*/
comment,
/**
A line [comment](#highlight.tags.comment).
*/
lineComment: t(comment),
/**
A block [comment](#highlight.tags.comment).
*/
blockComment: t(comment),
/**
A documentation [comment](#highlight.tags.comment).
*/
docComment: t(comment),
/**
Any kind of identifier.
*/
name,
/**
The [name](#highlight.tags.name) of a variable.
*/
variableName: t(name),
/**
A type [name](#highlight.tags.name).
*/
typeName: typeName,
/**
A tag name (subtag of [`typeName`](#highlight.tags.typeName)).
*/
tagName: t(typeName),
/**
A property or field [name](#highlight.tags.name).
*/
propertyName: propertyName,
/**
An attribute name (subtag of [`propertyName`](#highlight.tags.propertyName)).
*/
attributeName: t(propertyName),
/**
The [name](#highlight.tags.name) of a class.
*/
className: t(name),
/**
A label [name](#highlight.tags.name).
*/
labelName: t(name),
/**
A namespace [name](#highlight.tags.name).
*/
namespace: t(name),
/**
The [name](#highlight.tags.name) of a macro.
*/
macroName: t(name),
/**
A literal value.
*/
literal,
/**
A string [literal](#highlight.tags.literal).
*/
string,
/**
A documentation [string](#highlight.tags.string).
*/
docString: t(string),
/**
A character literal (subtag of [string](#highlight.tags.string)).
*/
character: t(string),
/**
An attribute value (subtag of [string](#highlight.tags.string)).
*/
attributeValue: t(string),
/**
A number [literal](#highlight.tags.literal).
*/
number,
/**
An integer [number](#highlight.tags.number) literal.
*/
integer: t(number),
/**
A floating-point [number](#highlight.tags.number) literal.
*/
float: t(number),
/**
A boolean [literal](#highlight.tags.literal).
*/
bool: t(literal),
/**
Regular expression [literal](#highlight.tags.literal).
*/
regexp: t(literal),
/**
An escape [literal](#highlight.tags.literal), for example a
backslash escape in a string.
*/
escape: t(literal),
/**
A color [literal](#highlight.tags.literal).
*/
color: t(literal),
/**
A URL [literal](#highlight.tags.literal).
*/
url: t(literal),
/**
A language keyword.
*/
keyword,
/**
The [keyword](#highlight.tags.keyword) for the self or this
object.
*/
self: t(keyword),
/**
The [keyword](#highlight.tags.keyword) for null.
*/
null: t(keyword),
/**
A [keyword](#highlight.tags.keyword) denoting some atomic value.
*/
atom: t(keyword),
/**
A [keyword](#highlight.tags.keyword) that represents a unit.
*/
unit: t(keyword),
/**
A modifier [keyword](#highlight.tags.keyword).
*/
modifier: t(keyword),
/**
A [keyword](#highlight.tags.keyword) that acts as an operator.
*/
operatorKeyword: t(keyword),
/**
A control-flow related [keyword](#highlight.tags.keyword).
*/
controlKeyword: t(keyword),
/**
A [keyword](#highlight.tags.keyword) that defines something.
*/
definitionKeyword: t(keyword),
/**
A [keyword](#highlight.tags.keyword) related to defining or
interfacing with modules.
*/
moduleKeyword: t(keyword),
/**
An operator.
*/
operator,
/**
An [operator](#highlight.tags.operator) that dereferences something.
*/
derefOperator: t(operator),
/**
Arithmetic-related [operator](#highlight.tags.operator).
*/
arithmeticOperator: t(operator),
/**
Logical [operator](#highlight.tags.operator).
*/
logicOperator: t(operator),
/**
Bit [operator](#highlight.tags.operator).
*/
bitwiseOperator: t(operator),
/**
Comparison [operator](#highlight.tags.operator).
*/
compareOperator: t(operator),
/**
[Operator](#highlight.tags.operator) that updates its operand.
*/
updateOperator: t(operator),
/**
[Operator](#highlight.tags.operator) that defines something.
*/
definitionOperator: t(operator),
/**
Type-related [operator](#highlight.tags.operator).
*/
typeOperator: t(operator),
/**
Control-flow [operator](#highlight.tags.operator).
*/
controlOperator: t(operator),
/**
Program or markup punctuation.
*/
punctuation,
/**
[Punctuation](#highlight.tags.punctuation) that separates
things.
*/
separator: t(punctuation),
/**
Bracket-style [punctuation](#highlight.tags.punctuation).
*/
bracket,
/**
Angle [brackets](#highlight.tags.bracket) (usually `<` and `>`
tokens).
*/
angleBracket: t(bracket),
/**
Square [brackets](#highlight.tags.bracket) (usually `[` and `]`
tokens).
*/
squareBracket: t(bracket),
/**
Parentheses (usually `(` and `)` tokens). Subtag of
[bracket](#highlight.tags.bracket).
*/
paren: t(bracket),
/**
Braces (usually `{` and `}` tokens). Subtag of
[bracket](#highlight.tags.bracket).
*/
brace: t(bracket),
/**
Content, for example plain text in XML or markup documents.
*/
content,
/**
[Content](#highlight.tags.content) that represents a heading.
*/
heading,
/**
A level 1 [heading](#highlight.tags.heading).
*/
heading1: t(heading),
/**
A level 2 [heading](#highlight.tags.heading).
*/
heading2: t(heading),
/**
A level 3 [heading](#highlight.tags.heading).
*/
heading3: t(heading),
/**
A level 4 [heading](#highlight.tags.heading).
*/
heading4: t(heading),
/**
A level 5 [heading](#highlight.tags.heading).
*/
heading5: t(heading),
/**
A level 6 [heading](#highlight.tags.heading).
*/
heading6: t(heading),
/**
A prose separator (such as a horizontal rule).
*/
contentSeparator: t(content),
/**
[Content](#highlight.tags.content) that represents a list.
*/
list: t(content),
/**
[Content](#highlight.tags.content) that represents a quote.
*/
quote: t(content),
/**
[Content](#highlight.tags.content) that is emphasized.
*/
emphasis: t(content),
/**
[Content](#highlight.tags.content) that is styled strong.
*/
strong: t(content),
/**
[Content](#highlight.tags.content) that is part of a link.
*/
link: t(content),
/**
[Content](#highlight.tags.content) that is styled as code or
monospace.
*/
monospace: t(content),
/**
[Content](#highlight.tags.content) that has a strike-through
style.
*/
strikethrough: t(content),
/**
Inserted text in a change-tracking format.
*/
inserted: t(),
/**
Deleted text.
*/
deleted: t(),
/**
Changed text.
*/
changed: t(),
/**
An invalid or unsyntactic element.
*/
invalid: t(),
/**
Metadata or meta-instruction.
*/
meta,
/**
[Metadata](#highlight.tags.meta) that applies to the entire
document.
*/
documentMeta: t(meta),
/**
[Metadata](#highlight.tags.meta) that annotates or adds
attributes to a given syntactic element.
*/
annotation: t(meta),
/**
Processing instruction or preprocessor directive. Subtag of
[meta](#highlight.tags.meta).
*/
processingInstruction: t(meta),
/**
[Modifier](#highlight.Tag^defineModifier) that indicates that a
given element is being defined. Expected to be used with the
various [name](#highlight.tags.name) tags.
*/
definition: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) that indicates that
something is constant. Mostly expected to be used with
[variable names](#highlight.tags.variableName).
*/
constant: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) used to indicate that
a [variable](#highlight.tags.variableName) or [property
name](#highlight.tags.propertyName) is being called or defined
as a function.
*/
function: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) that can be applied to
[names](#highlight.tags.name) to indicate that they belong to
the language's standard environment.
*/
standard: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) that indicates a given
[names](#highlight.tags.name) is local to some scope.
*/
local: Tag.defineModifier(),
/**
A generic variant [modifier](#highlight.Tag^defineModifier) that
can be used to tag language-specific alternative variants of
some common tag. It is recommended for themes to define special
forms of at least the [string](#highlight.tags.string) and
[variable name](#highlight.tags.variableName) tags, since those
come up a lot.
*/
special: Tag.defineModifier()
};
/**
This is a highlighter that adds stable, predictable classes to
tokens, for styling with external CSS.
The following tags are mapped to their name prefixed with `"tok-"`
(for example `"tok-comment"`):
* [`link`](#highlight.tags.link)
* [`heading`](#highlight.tags.heading)
* [`emphasis`](#highlight.tags.emphasis)
* [`strong`](#highlight.tags.strong)
* [`keyword`](#highlight.tags.keyword)
* [`atom`](#highlight.tags.atom)
* [`bool`](#highlight.tags.bool)
* [`url`](#highlight.tags.url)
* [`labelName`](#highlight.tags.labelName)
* [`inserted`](#highlight.tags.inserted)
* [`deleted`](#highlight.tags.deleted)
* [`literal`](#highlight.tags.literal)
* [`string`](#highlight.tags.string)
* [`number`](#highlight.tags.number)
* [`variableName`](#highlight.tags.variableName)
* [`typeName`](#highlight.tags.typeName)
* [`namespace`](#highlight.tags.namespace)
* [`className`](#highlight.tags.className)
* [`macroName`](#highlight.tags.macroName)
* [`propertyName`](#highlight.tags.propertyName)
* [`operator`](#highlight.tags.operator)
* [`comment`](#highlight.tags.comment)
* [`meta`](#highlight.tags.meta)
* [`punctuation`](#highlight.tags.punctuation)
* [`invalid`](#highlight.tags.invalid)
In addition, these mappings are provided:
* [`regexp`](#highlight.tags.regexp),
[`escape`](#highlight.tags.escape), and
[`special`](#highlight.tags.special)[`(string)`](#highlight.tags.string)
are mapped to `"tok-string2"`
* [`special`](#highlight.tags.special)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName2"`
* [`local`](#highlight.tags.local)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName tok-local"`
* [`definition`](#highlight.tags.definition)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName tok-definition"`
* [`definition`](#highlight.tags.definition)[`(propertyName)`](#highlight.tags.propertyName)
to `"tok-propertyName tok-definition"`
*/
const classHighlighter = tagHighlighter([
{ tag: tags.link, class: "tok-link" },
{ tag: tags.heading, class: "tok-heading" },
{ tag: tags.emphasis, class: "tok-emphasis" },
{ tag: tags.strong, class: "tok-strong" },
{ tag: tags.keyword, class: "tok-keyword" },
{ tag: tags.atom, class: "tok-atom" },
{ tag: tags.bool, class: "tok-bool" },
{ tag: tags.url, class: "tok-url" },
{ tag: tags.labelName, class: "tok-labelName" },
{ tag: tags.inserted, class: "tok-inserted" },
{ tag: tags.deleted, class: "tok-deleted" },
{ tag: tags.literal, class: "tok-literal" },
{ tag: tags.string, class: "tok-string" },
{ tag: tags.number, class: "tok-number" },
{ tag: [tags.regexp, tags.escape, tags.special(tags.string)], class: "tok-string2" },
{ tag: tags.variableName, class: "tok-variableName" },
{ tag: tags.local(tags.variableName), class: "tok-variableName tok-local" },
{ tag: tags.definition(tags.variableName), class: "tok-variableName tok-definition" },
{ tag: tags.special(tags.variableName), class: "tok-variableName2" },
{ tag: tags.definition(tags.propertyName), class: "tok-propertyName tok-definition" },
{ tag: tags.typeName, class: "tok-typeName" },
{ tag: tags.namespace, class: "tok-namespace" },
{ tag: tags.className, class: "tok-className" },
{ tag: tags.macroName, class: "tok-macroName" },
{ tag: tags.propertyName, class: "tok-propertyName" },
{ tag: tags.operator, class: "tok-operator" },
{ tag: tags.comment, class: "tok-comment" },
{ tag: tags.meta, class: "tok-meta" },
{ tag: tags.invalid, class: "tok-invalid" },
{ tag: tags.punctuation, class: "tok-punctuation" }
]);
exports.Tag = Tag;
exports.classHighlighter = classHighlighter;
exports.getStyleTags = getStyleTags;
exports.highlightTree = highlightTree;
exports.styleTags = styleTags;
exports.tagHighlighter = tagHighlighter;
exports.tags = tags;

612
node_modules/@lezer/highlight/dist/index.d.cts generated vendored Normal file
View File

@ -0,0 +1,612 @@
import * as _lezer_common from '@lezer/common';
import { NodeType, Tree, SyntaxNodeRef } from '@lezer/common';
/**
Highlighting tags are markers that denote a highlighting category.
They are [associated](#highlight.styleTags) with parts of a syntax
tree by a language mode, and then mapped to an actual CSS style by
a [highlighter](#highlight.Highlighter).
Because syntax tree node types and highlight styles have to be
able to talk the same language, CodeMirror uses a mostly _closed_
[vocabulary](#highlight.tags) of syntax tags (as opposed to
traditional open string-based systems, which make it hard for
highlighting themes to cover all the tokens produced by the
various languages).
It _is_ possible to [define](#highlight.Tag^define) your own
highlighting tags for system-internal use (where you control both
the language package and the highlighter), but such tags will not
be picked up by regular highlighters (though you can derive them
from standard tags to allow highlighters to fall back to those).
*/
declare class Tag {
/**
The set of this tag and all its parent tags, starting with
this one itself and sorted in order of decreasing specificity.
*/
readonly set: Tag[];
/**
Define a new tag. If `parent` is given, the tag is treated as a
sub-tag of that parent, and
[highlighters](#highlight.tagHighlighter) that don't mention
this tag will try to fall back to the parent tag (or grandparent
tag, etc).
*/
static define(parent?: Tag): Tag;
/**
Define a tag _modifier_, which is a function that, given a tag,
will return a tag that is a subtag of the original. Applying the
same modifier to a twice tag will return the same value (`m1(t1)
== m1(t1)`) and applying multiple modifiers will, regardless or
order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
When multiple modifiers are applied to a given base tag, each
smaller set of modifiers is registered as a parent, so that for
example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
`m1(m3(t1)`, and so on.
*/
static defineModifier(): (tag: Tag) => Tag;
}
/**
This function is used to add a set of tags to a language syntax
via [`NodeSet.extend`](#common.NodeSet.extend) or
[`LRParser.configure`](#lr.LRParser.configure).
The argument object maps node selectors to [highlighting
tags](#highlight.Tag) or arrays of tags.
Node selectors may hold one or more (space-separated) node paths.
Such a path can be a [node name](#common.NodeType.name), or
multiple node names (or `*` wildcards) separated by slash
characters, as in `"Block/Declaration/VariableName"`. Such a path
matches the final node but only if its direct parent nodes are the
other nodes mentioned. A `*` in such a path matches any parent,
but only a single level—wildcards that match multiple parents
aren't supported, both for efficiency reasons and because Lezer
trees make it rather hard to reason about what they would match.)
A path can be ended with `/...` to indicate that the tag assigned
to the node should also apply to all child nodes, even if they
match their own style (by default, only the innermost style is
used).
When a path ends in `!`, as in `Attribute!`, no further matching
happens for the node's child nodes, and the entire node gets the
given style.
In this notation, node names that contain `/`, `!`, `*`, or `...`
must be quoted as JSON strings.
For example:
```javascript
parser.withProps(
styleTags({
// Style Number and BigNumber nodes
"Number BigNumber": tags.number,
// Style Escape nodes whose parent is String
"String/Escape": tags.escape,
// Style anything inside Attributes nodes
"Attributes!": tags.meta,
// Add a style to all content inside Italic nodes
"Italic/...": tags.emphasis,
// Style InvalidString nodes as both `string` and `invalid`
"InvalidString": [tags.string, tags.invalid],
// Style the node named "/" as punctuation
'"/"': tags.punctuation
})
)
```
*/
declare function styleTags(spec: {
[selector: string]: Tag | readonly Tag[];
}): _lezer_common.NodePropSource;
/**
A highlighter defines a mapping from highlighting tags and
language scopes to CSS class names. They are usually defined via
[`tagHighlighter`](#highlight.tagHighlighter) or some wrapper
around that, but it is also possible to implement them from
scratch.
*/
interface Highlighter {
/**
Get the set of classes that should be applied to the given set
of highlighting tags, or null if this highlighter doesn't assign
a style to the tags.
*/
style(tags: readonly Tag[]): string | null;
/**
When given, the highlighter will only be applied to trees on
whose [top](#common.NodeType.isTop) node this predicate returns
true.
*/
scope?(node: NodeType): boolean;
}
/**
Define a [highlighter](#highlight.Highlighter) from an array of
tag/class pairs. Classes associated with more specific tags will
take precedence.
*/
declare function tagHighlighter(tags: readonly {
tag: Tag | readonly Tag[];
class: string;
}[], options?: {
/**
By default, highlighters apply to the entire document. You can
scope them to a single language by providing the tree's
[top](#common.NodeType.isTop) node type here.
*/
scope?: (node: NodeType) => boolean;
/**
Add a style to _all_ tokens. Probably only useful in combination
with `scope`.
*/
all?: string;
}): Highlighter;
/**
Highlight the given [tree](#common.Tree) with the given
[highlighter](#highlight.Highlighter).
*/
declare function highlightTree(tree: Tree, highlighter: Highlighter | readonly Highlighter[],
/**
Assign styling to a region of the text. Will be called, in order
of position, for any ranges where more than zero classes apply.
`classes` is a space separated string of CSS classes.
*/
putStyle: (from: number, to: number, classes: string) => void,
/**
The start of the range to highlight.
*/
from?: number,
/**
The end of the range.
*/
to?: number): void;
/**
Match a syntax node's [highlight rules](#highlight.styleTags). If
there's a match, return its set of tags, and whether it is
opaque (uses a `!`) or applies to all child nodes (`/...`).
*/
declare function getStyleTags(node: SyntaxNodeRef): {
tags: readonly Tag[];
opaque: boolean;
inherit: boolean;
} | null;
/**
The default set of highlighting [tags](#highlight.Tag).
This collection is heavily biased towards programming languages,
and necessarily incomplete. A full ontology of syntactic
constructs would fill a stack of books, and be impractical to
write themes for. So try to make do with this set. If all else
fails, [open an
issue](https://github.com/codemirror/codemirror.next) to propose a
new tag, or [define](#highlight.Tag^define) a local custom tag for
your use case.
Note that it is not obligatory to always attach the most specific
tag possible to an element—if your grammar can't easily
distinguish a certain type of element (such as a local variable),
it is okay to style it as its more general variant (a variable).
For tags that extend some parent tag, the documentation links to
the parent.
*/
declare const tags: {
/**
A comment.
*/
comment: Tag;
/**
A line [comment](#highlight.tags.comment).
*/
lineComment: Tag;
/**
A block [comment](#highlight.tags.comment).
*/
blockComment: Tag;
/**
A documentation [comment](#highlight.tags.comment).
*/
docComment: Tag;
/**
Any kind of identifier.
*/
name: Tag;
/**
The [name](#highlight.tags.name) of a variable.
*/
variableName: Tag;
/**
A type [name](#highlight.tags.name).
*/
typeName: Tag;
/**
A tag name (subtag of [`typeName`](#highlight.tags.typeName)).
*/
tagName: Tag;
/**
A property or field [name](#highlight.tags.name).
*/
propertyName: Tag;
/**
An attribute name (subtag of [`propertyName`](#highlight.tags.propertyName)).
*/
attributeName: Tag;
/**
The [name](#highlight.tags.name) of a class.
*/
className: Tag;
/**
A label [name](#highlight.tags.name).
*/
labelName: Tag;
/**
A namespace [name](#highlight.tags.name).
*/
namespace: Tag;
/**
The [name](#highlight.tags.name) of a macro.
*/
macroName: Tag;
/**
A literal value.
*/
literal: Tag;
/**
A string [literal](#highlight.tags.literal).
*/
string: Tag;
/**
A documentation [string](#highlight.tags.string).
*/
docString: Tag;
/**
A character literal (subtag of [string](#highlight.tags.string)).
*/
character: Tag;
/**
An attribute value (subtag of [string](#highlight.tags.string)).
*/
attributeValue: Tag;
/**
A number [literal](#highlight.tags.literal).
*/
number: Tag;
/**
An integer [number](#highlight.tags.number) literal.
*/
integer: Tag;
/**
A floating-point [number](#highlight.tags.number) literal.
*/
float: Tag;
/**
A boolean [literal](#highlight.tags.literal).
*/
bool: Tag;
/**
Regular expression [literal](#highlight.tags.literal).
*/
regexp: Tag;
/**
An escape [literal](#highlight.tags.literal), for example a
backslash escape in a string.
*/
escape: Tag;
/**
A color [literal](#highlight.tags.literal).
*/
color: Tag;
/**
A URL [literal](#highlight.tags.literal).
*/
url: Tag;
/**
A language keyword.
*/
keyword: Tag;
/**
The [keyword](#highlight.tags.keyword) for the self or this
object.
*/
self: Tag;
/**
The [keyword](#highlight.tags.keyword) for null.
*/
null: Tag;
/**
A [keyword](#highlight.tags.keyword) denoting some atomic value.
*/
atom: Tag;
/**
A [keyword](#highlight.tags.keyword) that represents a unit.
*/
unit: Tag;
/**
A modifier [keyword](#highlight.tags.keyword).
*/
modifier: Tag;
/**
A [keyword](#highlight.tags.keyword) that acts as an operator.
*/
operatorKeyword: Tag;
/**
A control-flow related [keyword](#highlight.tags.keyword).
*/
controlKeyword: Tag;
/**
A [keyword](#highlight.tags.keyword) that defines something.
*/
definitionKeyword: Tag;
/**
A [keyword](#highlight.tags.keyword) related to defining or
interfacing with modules.
*/
moduleKeyword: Tag;
/**
An operator.
*/
operator: Tag;
/**
An [operator](#highlight.tags.operator) that dereferences something.
*/
derefOperator: Tag;
/**
Arithmetic-related [operator](#highlight.tags.operator).
*/
arithmeticOperator: Tag;
/**
Logical [operator](#highlight.tags.operator).
*/
logicOperator: Tag;
/**
Bit [operator](#highlight.tags.operator).
*/
bitwiseOperator: Tag;
/**
Comparison [operator](#highlight.tags.operator).
*/
compareOperator: Tag;
/**
[Operator](#highlight.tags.operator) that updates its operand.
*/
updateOperator: Tag;
/**
[Operator](#highlight.tags.operator) that defines something.
*/
definitionOperator: Tag;
/**
Type-related [operator](#highlight.tags.operator).
*/
typeOperator: Tag;
/**
Control-flow [operator](#highlight.tags.operator).
*/
controlOperator: Tag;
/**
Program or markup punctuation.
*/
punctuation: Tag;
/**
[Punctuation](#highlight.tags.punctuation) that separates
things.
*/
separator: Tag;
/**
Bracket-style [punctuation](#highlight.tags.punctuation).
*/
bracket: Tag;
/**
Angle [brackets](#highlight.tags.bracket) (usually `<` and `>`
tokens).
*/
angleBracket: Tag;
/**
Square [brackets](#highlight.tags.bracket) (usually `[` and `]`
tokens).
*/
squareBracket: Tag;
/**
Parentheses (usually `(` and `)` tokens). Subtag of
[bracket](#highlight.tags.bracket).
*/
paren: Tag;
/**
Braces (usually `{` and `}` tokens). Subtag of
[bracket](#highlight.tags.bracket).
*/
brace: Tag;
/**
Content, for example plain text in XML or markup documents.
*/
content: Tag;
/**
[Content](#highlight.tags.content) that represents a heading.
*/
heading: Tag;
/**
A level 1 [heading](#highlight.tags.heading).
*/
heading1: Tag;
/**
A level 2 [heading](#highlight.tags.heading).
*/
heading2: Tag;
/**
A level 3 [heading](#highlight.tags.heading).
*/
heading3: Tag;
/**
A level 4 [heading](#highlight.tags.heading).
*/
heading4: Tag;
/**
A level 5 [heading](#highlight.tags.heading).
*/
heading5: Tag;
/**
A level 6 [heading](#highlight.tags.heading).
*/
heading6: Tag;
/**
A prose separator (such as a horizontal rule).
*/
contentSeparator: Tag;
/**
[Content](#highlight.tags.content) that represents a list.
*/
list: Tag;
/**
[Content](#highlight.tags.content) that represents a quote.
*/
quote: Tag;
/**
[Content](#highlight.tags.content) that is emphasized.
*/
emphasis: Tag;
/**
[Content](#highlight.tags.content) that is styled strong.
*/
strong: Tag;
/**
[Content](#highlight.tags.content) that is part of a link.
*/
link: Tag;
/**
[Content](#highlight.tags.content) that is styled as code or
monospace.
*/
monospace: Tag;
/**
[Content](#highlight.tags.content) that has a strike-through
style.
*/
strikethrough: Tag;
/**
Inserted text in a change-tracking format.
*/
inserted: Tag;
/**
Deleted text.
*/
deleted: Tag;
/**
Changed text.
*/
changed: Tag;
/**
An invalid or unsyntactic element.
*/
invalid: Tag;
/**
Metadata or meta-instruction.
*/
meta: Tag;
/**
[Metadata](#highlight.tags.meta) that applies to the entire
document.
*/
documentMeta: Tag;
/**
[Metadata](#highlight.tags.meta) that annotates or adds
attributes to a given syntactic element.
*/
annotation: Tag;
/**
Processing instruction or preprocessor directive. Subtag of
[meta](#highlight.tags.meta).
*/
processingInstruction: Tag;
/**
[Modifier](#highlight.Tag^defineModifier) that indicates that a
given element is being defined. Expected to be used with the
various [name](#highlight.tags.name) tags.
*/
definition: (tag: Tag) => Tag;
/**
[Modifier](#highlight.Tag^defineModifier) that indicates that
something is constant. Mostly expected to be used with
[variable names](#highlight.tags.variableName).
*/
constant: (tag: Tag) => Tag;
/**
[Modifier](#highlight.Tag^defineModifier) used to indicate that
a [variable](#highlight.tags.variableName) or [property
name](#highlight.tags.propertyName) is being called or defined
as a function.
*/
function: (tag: Tag) => Tag;
/**
[Modifier](#highlight.Tag^defineModifier) that can be applied to
[names](#highlight.tags.name) to indicate that they belong to
the language's standard environment.
*/
standard: (tag: Tag) => Tag;
/**
[Modifier](#highlight.Tag^defineModifier) that indicates a given
[names](#highlight.tags.name) is local to some scope.
*/
local: (tag: Tag) => Tag;
/**
A generic variant [modifier](#highlight.Tag^defineModifier) that
can be used to tag language-specific alternative variants of
some common tag. It is recommended for themes to define special
forms of at least the [string](#highlight.tags.string) and
[variable name](#highlight.tags.variableName) tags, since those
come up a lot.
*/
special: (tag: Tag) => Tag;
};
/**
This is a highlighter that adds stable, predictable classes to
tokens, for styling with external CSS.
The following tags are mapped to their name prefixed with `"tok-"`
(for example `"tok-comment"`):
* [`link`](#highlight.tags.link)
* [`heading`](#highlight.tags.heading)
* [`emphasis`](#highlight.tags.emphasis)
* [`strong`](#highlight.tags.strong)
* [`keyword`](#highlight.tags.keyword)
* [`atom`](#highlight.tags.atom)
* [`bool`](#highlight.tags.bool)
* [`url`](#highlight.tags.url)
* [`labelName`](#highlight.tags.labelName)
* [`inserted`](#highlight.tags.inserted)
* [`deleted`](#highlight.tags.deleted)
* [`literal`](#highlight.tags.literal)
* [`string`](#highlight.tags.string)
* [`number`](#highlight.tags.number)
* [`variableName`](#highlight.tags.variableName)
* [`typeName`](#highlight.tags.typeName)
* [`namespace`](#highlight.tags.namespace)
* [`className`](#highlight.tags.className)
* [`macroName`](#highlight.tags.macroName)
* [`propertyName`](#highlight.tags.propertyName)
* [`operator`](#highlight.tags.operator)
* [`comment`](#highlight.tags.comment)
* [`meta`](#highlight.tags.meta)
* [`punctuation`](#highlight.tags.punctuation)
* [`invalid`](#highlight.tags.invalid)
In addition, these mappings are provided:
* [`regexp`](#highlight.tags.regexp),
[`escape`](#highlight.tags.escape), and
[`special`](#highlight.tags.special)[`(string)`](#highlight.tags.string)
are mapped to `"tok-string2"`
* [`special`](#highlight.tags.special)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName2"`
* [`local`](#highlight.tags.local)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName tok-local"`
* [`definition`](#highlight.tags.definition)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName tok-definition"`
* [`definition`](#highlight.tags.definition)[`(propertyName)`](#highlight.tags.propertyName)
to `"tok-propertyName tok-definition"`
*/
declare const classHighlighter: Highlighter;
export { Highlighter, Tag, classHighlighter, getStyleTags, highlightTree, styleTags, tagHighlighter, tags };

612
node_modules/@lezer/highlight/dist/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,612 @@
import * as _lezer_common from '@lezer/common';
import { NodeType, Tree, SyntaxNodeRef } from '@lezer/common';
/**
Highlighting tags are markers that denote a highlighting category.
They are [associated](#highlight.styleTags) with parts of a syntax
tree by a language mode, and then mapped to an actual CSS style by
a [highlighter](#highlight.Highlighter).
Because syntax tree node types and highlight styles have to be
able to talk the same language, CodeMirror uses a mostly _closed_
[vocabulary](#highlight.tags) of syntax tags (as opposed to
traditional open string-based systems, which make it hard for
highlighting themes to cover all the tokens produced by the
various languages).
It _is_ possible to [define](#highlight.Tag^define) your own
highlighting tags for system-internal use (where you control both
the language package and the highlighter), but such tags will not
be picked up by regular highlighters (though you can derive them
from standard tags to allow highlighters to fall back to those).
*/
declare class Tag {
/**
The set of this tag and all its parent tags, starting with
this one itself and sorted in order of decreasing specificity.
*/
readonly set: Tag[];
/**
Define a new tag. If `parent` is given, the tag is treated as a
sub-tag of that parent, and
[highlighters](#highlight.tagHighlighter) that don't mention
this tag will try to fall back to the parent tag (or grandparent
tag, etc).
*/
static define(parent?: Tag): Tag;
/**
Define a tag _modifier_, which is a function that, given a tag,
will return a tag that is a subtag of the original. Applying the
same modifier to a twice tag will return the same value (`m1(t1)
== m1(t1)`) and applying multiple modifiers will, regardless or
order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
When multiple modifiers are applied to a given base tag, each
smaller set of modifiers is registered as a parent, so that for
example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
`m1(m3(t1)`, and so on.
*/
static defineModifier(): (tag: Tag) => Tag;
}
/**
This function is used to add a set of tags to a language syntax
via [`NodeSet.extend`](#common.NodeSet.extend) or
[`LRParser.configure`](#lr.LRParser.configure).
The argument object maps node selectors to [highlighting
tags](#highlight.Tag) or arrays of tags.
Node selectors may hold one or more (space-separated) node paths.
Such a path can be a [node name](#common.NodeType.name), or
multiple node names (or `*` wildcards) separated by slash
characters, as in `"Block/Declaration/VariableName"`. Such a path
matches the final node but only if its direct parent nodes are the
other nodes mentioned. A `*` in such a path matches any parent,
but only a single level—wildcards that match multiple parents
aren't supported, both for efficiency reasons and because Lezer
trees make it rather hard to reason about what they would match.)
A path can be ended with `/...` to indicate that the tag assigned
to the node should also apply to all child nodes, even if they
match their own style (by default, only the innermost style is
used).
When a path ends in `!`, as in `Attribute!`, no further matching
happens for the node's child nodes, and the entire node gets the
given style.
In this notation, node names that contain `/`, `!`, `*`, or `...`
must be quoted as JSON strings.
For example:
```javascript
parser.withProps(
styleTags({
// Style Number and BigNumber nodes
"Number BigNumber": tags.number,
// Style Escape nodes whose parent is String
"String/Escape": tags.escape,
// Style anything inside Attributes nodes
"Attributes!": tags.meta,
// Add a style to all content inside Italic nodes
"Italic/...": tags.emphasis,
// Style InvalidString nodes as both `string` and `invalid`
"InvalidString": [tags.string, tags.invalid],
// Style the node named "/" as punctuation
'"/"': tags.punctuation
})
)
```
*/
declare function styleTags(spec: {
[selector: string]: Tag | readonly Tag[];
}): _lezer_common.NodePropSource;
/**
A highlighter defines a mapping from highlighting tags and
language scopes to CSS class names. They are usually defined via
[`tagHighlighter`](#highlight.tagHighlighter) or some wrapper
around that, but it is also possible to implement them from
scratch.
*/
interface Highlighter {
/**
Get the set of classes that should be applied to the given set
of highlighting tags, or null if this highlighter doesn't assign
a style to the tags.
*/
style(tags: readonly Tag[]): string | null;
/**
When given, the highlighter will only be applied to trees on
whose [top](#common.NodeType.isTop) node this predicate returns
true.
*/
scope?(node: NodeType): boolean;
}
/**
Define a [highlighter](#highlight.Highlighter) from an array of
tag/class pairs. Classes associated with more specific tags will
take precedence.
*/
declare function tagHighlighter(tags: readonly {
tag: Tag | readonly Tag[];
class: string;
}[], options?: {
/**
By default, highlighters apply to the entire document. You can
scope them to a single language by providing the tree's
[top](#common.NodeType.isTop) node type here.
*/
scope?: (node: NodeType) => boolean;
/**
Add a style to _all_ tokens. Probably only useful in combination
with `scope`.
*/
all?: string;
}): Highlighter;
/**
Highlight the given [tree](#common.Tree) with the given
[highlighter](#highlight.Highlighter).
*/
declare function highlightTree(tree: Tree, highlighter: Highlighter | readonly Highlighter[],
/**
Assign styling to a region of the text. Will be called, in order
of position, for any ranges where more than zero classes apply.
`classes` is a space separated string of CSS classes.
*/
putStyle: (from: number, to: number, classes: string) => void,
/**
The start of the range to highlight.
*/
from?: number,
/**
The end of the range.
*/
to?: number): void;
/**
Match a syntax node's [highlight rules](#highlight.styleTags). If
there's a match, return its set of tags, and whether it is
opaque (uses a `!`) or applies to all child nodes (`/...`).
*/
declare function getStyleTags(node: SyntaxNodeRef): {
tags: readonly Tag[];
opaque: boolean;
inherit: boolean;
} | null;
/**
The default set of highlighting [tags](#highlight.Tag).
This collection is heavily biased towards programming languages,
and necessarily incomplete. A full ontology of syntactic
constructs would fill a stack of books, and be impractical to
write themes for. So try to make do with this set. If all else
fails, [open an
issue](https://github.com/codemirror/codemirror.next) to propose a
new tag, or [define](#highlight.Tag^define) a local custom tag for
your use case.
Note that it is not obligatory to always attach the most specific
tag possible to an element—if your grammar can't easily
distinguish a certain type of element (such as a local variable),
it is okay to style it as its more general variant (a variable).
For tags that extend some parent tag, the documentation links to
the parent.
*/
declare const tags: {
/**
A comment.
*/
comment: Tag;
/**
A line [comment](#highlight.tags.comment).
*/
lineComment: Tag;
/**
A block [comment](#highlight.tags.comment).
*/
blockComment: Tag;
/**
A documentation [comment](#highlight.tags.comment).
*/
docComment: Tag;
/**
Any kind of identifier.
*/
name: Tag;
/**
The [name](#highlight.tags.name) of a variable.
*/
variableName: Tag;
/**
A type [name](#highlight.tags.name).
*/
typeName: Tag;
/**
A tag name (subtag of [`typeName`](#highlight.tags.typeName)).
*/
tagName: Tag;
/**
A property or field [name](#highlight.tags.name).
*/
propertyName: Tag;
/**
An attribute name (subtag of [`propertyName`](#highlight.tags.propertyName)).
*/
attributeName: Tag;
/**
The [name](#highlight.tags.name) of a class.
*/
className: Tag;
/**
A label [name](#highlight.tags.name).
*/
labelName: Tag;
/**
A namespace [name](#highlight.tags.name).
*/
namespace: Tag;
/**
The [name](#highlight.tags.name) of a macro.
*/
macroName: Tag;
/**
A literal value.
*/
literal: Tag;
/**
A string [literal](#highlight.tags.literal).
*/
string: Tag;
/**
A documentation [string](#highlight.tags.string).
*/
docString: Tag;
/**
A character literal (subtag of [string](#highlight.tags.string)).
*/
character: Tag;
/**
An attribute value (subtag of [string](#highlight.tags.string)).
*/
attributeValue: Tag;
/**
A number [literal](#highlight.tags.literal).
*/
number: Tag;
/**
An integer [number](#highlight.tags.number) literal.
*/
integer: Tag;
/**
A floating-point [number](#highlight.tags.number) literal.
*/
float: Tag;
/**
A boolean [literal](#highlight.tags.literal).
*/
bool: Tag;
/**
Regular expression [literal](#highlight.tags.literal).
*/
regexp: Tag;
/**
An escape [literal](#highlight.tags.literal), for example a
backslash escape in a string.
*/
escape: Tag;
/**
A color [literal](#highlight.tags.literal).
*/
color: Tag;
/**
A URL [literal](#highlight.tags.literal).
*/
url: Tag;
/**
A language keyword.
*/
keyword: Tag;
/**
The [keyword](#highlight.tags.keyword) for the self or this
object.
*/
self: Tag;
/**
The [keyword](#highlight.tags.keyword) for null.
*/
null: Tag;
/**
A [keyword](#highlight.tags.keyword) denoting some atomic value.
*/
atom: Tag;
/**
A [keyword](#highlight.tags.keyword) that represents a unit.
*/
unit: Tag;
/**
A modifier [keyword](#highlight.tags.keyword).
*/
modifier: Tag;
/**
A [keyword](#highlight.tags.keyword) that acts as an operator.
*/
operatorKeyword: Tag;
/**
A control-flow related [keyword](#highlight.tags.keyword).
*/
controlKeyword: Tag;
/**
A [keyword](#highlight.tags.keyword) that defines something.
*/
definitionKeyword: Tag;
/**
A [keyword](#highlight.tags.keyword) related to defining or
interfacing with modules.
*/
moduleKeyword: Tag;
/**
An operator.
*/
operator: Tag;
/**
An [operator](#highlight.tags.operator) that dereferences something.
*/
derefOperator: Tag;
/**
Arithmetic-related [operator](#highlight.tags.operator).
*/
arithmeticOperator: Tag;
/**
Logical [operator](#highlight.tags.operator).
*/
logicOperator: Tag;
/**
Bit [operator](#highlight.tags.operator).
*/
bitwiseOperator: Tag;
/**
Comparison [operator](#highlight.tags.operator).
*/
compareOperator: Tag;
/**
[Operator](#highlight.tags.operator) that updates its operand.
*/
updateOperator: Tag;
/**
[Operator](#highlight.tags.operator) that defines something.
*/
definitionOperator: Tag;
/**
Type-related [operator](#highlight.tags.operator).
*/
typeOperator: Tag;
/**
Control-flow [operator](#highlight.tags.operator).
*/
controlOperator: Tag;
/**
Program or markup punctuation.
*/
punctuation: Tag;
/**
[Punctuation](#highlight.tags.punctuation) that separates
things.
*/
separator: Tag;
/**
Bracket-style [punctuation](#highlight.tags.punctuation).
*/
bracket: Tag;
/**
Angle [brackets](#highlight.tags.bracket) (usually `<` and `>`
tokens).
*/
angleBracket: Tag;
/**
Square [brackets](#highlight.tags.bracket) (usually `[` and `]`
tokens).
*/
squareBracket: Tag;
/**
Parentheses (usually `(` and `)` tokens). Subtag of
[bracket](#highlight.tags.bracket).
*/
paren: Tag;
/**
Braces (usually `{` and `}` tokens). Subtag of
[bracket](#highlight.tags.bracket).
*/
brace: Tag;
/**
Content, for example plain text in XML or markup documents.
*/
content: Tag;
/**
[Content](#highlight.tags.content) that represents a heading.
*/
heading: Tag;
/**
A level 1 [heading](#highlight.tags.heading).
*/
heading1: Tag;
/**
A level 2 [heading](#highlight.tags.heading).
*/
heading2: Tag;
/**
A level 3 [heading](#highlight.tags.heading).
*/
heading3: Tag;
/**
A level 4 [heading](#highlight.tags.heading).
*/
heading4: Tag;
/**
A level 5 [heading](#highlight.tags.heading).
*/
heading5: Tag;
/**
A level 6 [heading](#highlight.tags.heading).
*/
heading6: Tag;
/**
A prose separator (such as a horizontal rule).
*/
contentSeparator: Tag;
/**
[Content](#highlight.tags.content) that represents a list.
*/
list: Tag;
/**
[Content](#highlight.tags.content) that represents a quote.
*/
quote: Tag;
/**
[Content](#highlight.tags.content) that is emphasized.
*/
emphasis: Tag;
/**
[Content](#highlight.tags.content) that is styled strong.
*/
strong: Tag;
/**
[Content](#highlight.tags.content) that is part of a link.
*/
link: Tag;
/**
[Content](#highlight.tags.content) that is styled as code or
monospace.
*/
monospace: Tag;
/**
[Content](#highlight.tags.content) that has a strike-through
style.
*/
strikethrough: Tag;
/**
Inserted text in a change-tracking format.
*/
inserted: Tag;
/**
Deleted text.
*/
deleted: Tag;
/**
Changed text.
*/
changed: Tag;
/**
An invalid or unsyntactic element.
*/
invalid: Tag;
/**
Metadata or meta-instruction.
*/
meta: Tag;
/**
[Metadata](#highlight.tags.meta) that applies to the entire
document.
*/
documentMeta: Tag;
/**
[Metadata](#highlight.tags.meta) that annotates or adds
attributes to a given syntactic element.
*/
annotation: Tag;
/**
Processing instruction or preprocessor directive. Subtag of
[meta](#highlight.tags.meta).
*/
processingInstruction: Tag;
/**
[Modifier](#highlight.Tag^defineModifier) that indicates that a
given element is being defined. Expected to be used with the
various [name](#highlight.tags.name) tags.
*/
definition: (tag: Tag) => Tag;
/**
[Modifier](#highlight.Tag^defineModifier) that indicates that
something is constant. Mostly expected to be used with
[variable names](#highlight.tags.variableName).
*/
constant: (tag: Tag) => Tag;
/**
[Modifier](#highlight.Tag^defineModifier) used to indicate that
a [variable](#highlight.tags.variableName) or [property
name](#highlight.tags.propertyName) is being called or defined
as a function.
*/
function: (tag: Tag) => Tag;
/**
[Modifier](#highlight.Tag^defineModifier) that can be applied to
[names](#highlight.tags.name) to indicate that they belong to
the language's standard environment.
*/
standard: (tag: Tag) => Tag;
/**
[Modifier](#highlight.Tag^defineModifier) that indicates a given
[names](#highlight.tags.name) is local to some scope.
*/
local: (tag: Tag) => Tag;
/**
A generic variant [modifier](#highlight.Tag^defineModifier) that
can be used to tag language-specific alternative variants of
some common tag. It is recommended for themes to define special
forms of at least the [string](#highlight.tags.string) and
[variable name](#highlight.tags.variableName) tags, since those
come up a lot.
*/
special: (tag: Tag) => Tag;
};
/**
This is a highlighter that adds stable, predictable classes to
tokens, for styling with external CSS.
The following tags are mapped to their name prefixed with `"tok-"`
(for example `"tok-comment"`):
* [`link`](#highlight.tags.link)
* [`heading`](#highlight.tags.heading)
* [`emphasis`](#highlight.tags.emphasis)
* [`strong`](#highlight.tags.strong)
* [`keyword`](#highlight.tags.keyword)
* [`atom`](#highlight.tags.atom)
* [`bool`](#highlight.tags.bool)
* [`url`](#highlight.tags.url)
* [`labelName`](#highlight.tags.labelName)
* [`inserted`](#highlight.tags.inserted)
* [`deleted`](#highlight.tags.deleted)
* [`literal`](#highlight.tags.literal)
* [`string`](#highlight.tags.string)
* [`number`](#highlight.tags.number)
* [`variableName`](#highlight.tags.variableName)
* [`typeName`](#highlight.tags.typeName)
* [`namespace`](#highlight.tags.namespace)
* [`className`](#highlight.tags.className)
* [`macroName`](#highlight.tags.macroName)
* [`propertyName`](#highlight.tags.propertyName)
* [`operator`](#highlight.tags.operator)
* [`comment`](#highlight.tags.comment)
* [`meta`](#highlight.tags.meta)
* [`punctuation`](#highlight.tags.punctuation)
* [`invalid`](#highlight.tags.invalid)
In addition, these mappings are provided:
* [`regexp`](#highlight.tags.regexp),
[`escape`](#highlight.tags.escape), and
[`special`](#highlight.tags.special)[`(string)`](#highlight.tags.string)
are mapped to `"tok-string2"`
* [`special`](#highlight.tags.special)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName2"`
* [`local`](#highlight.tags.local)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName tok-local"`
* [`definition`](#highlight.tags.definition)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName tok-definition"`
* [`definition`](#highlight.tags.definition)[`(propertyName)`](#highlight.tags.propertyName)
to `"tok-propertyName tok-definition"`
*/
declare const classHighlighter: Highlighter;
export { Highlighter, Tag, classHighlighter, getStyleTags, highlightTree, styleTags, tagHighlighter, tags };

859
node_modules/@lezer/highlight/dist/index.js generated vendored Normal file
View File

@ -0,0 +1,859 @@
import { NodeProp } from '@lezer/common';
let nextTagID = 0;
/**
Highlighting tags are markers that denote a highlighting category.
They are [associated](#highlight.styleTags) with parts of a syntax
tree by a language mode, and then mapped to an actual CSS style by
a [highlighter](#highlight.Highlighter).
Because syntax tree node types and highlight styles have to be
able to talk the same language, CodeMirror uses a mostly _closed_
[vocabulary](#highlight.tags) of syntax tags (as opposed to
traditional open string-based systems, which make it hard for
highlighting themes to cover all the tokens produced by the
various languages).
It _is_ possible to [define](#highlight.Tag^define) your own
highlighting tags for system-internal use (where you control both
the language package and the highlighter), but such tags will not
be picked up by regular highlighters (though you can derive them
from standard tags to allow highlighters to fall back to those).
*/
class Tag {
/**
@internal
*/
constructor(
/**
The set of this tag and all its parent tags, starting with
this one itself and sorted in order of decreasing specificity.
*/
set,
/**
The base unmodified tag that this one is based on, if it's
modified @internal
*/
base,
/**
The modifiers applied to this.base @internal
*/
modified) {
this.set = set;
this.base = base;
this.modified = modified;
/**
@internal
*/
this.id = nextTagID++;
}
/**
Define a new tag. If `parent` is given, the tag is treated as a
sub-tag of that parent, and
[highlighters](#highlight.tagHighlighter) that don't mention
this tag will try to fall back to the parent tag (or grandparent
tag, etc).
*/
static define(parent) {
if (parent === null || parent === void 0 ? void 0 : parent.base)
throw new Error("Can not derive from a modified tag");
let tag = new Tag([], null, []);
tag.set.push(tag);
if (parent)
for (let t of parent.set)
tag.set.push(t);
return tag;
}
/**
Define a tag _modifier_, which is a function that, given a tag,
will return a tag that is a subtag of the original. Applying the
same modifier to a twice tag will return the same value (`m1(t1)
== m1(t1)`) and applying multiple modifiers will, regardless or
order, produce the same tag (`m1(m2(t1)) == m2(m1(t1))`).
When multiple modifiers are applied to a given base tag, each
smaller set of modifiers is registered as a parent, so that for
example `m1(m2(m3(t1)))` is a subtype of `m1(m2(t1))`,
`m1(m3(t1)`, and so on.
*/
static defineModifier() {
let mod = new Modifier;
return (tag) => {
if (tag.modified.indexOf(mod) > -1)
return tag;
return Modifier.get(tag.base || tag, tag.modified.concat(mod).sort((a, b) => a.id - b.id));
};
}
}
let nextModifierID = 0;
class Modifier {
constructor() {
this.instances = [];
this.id = nextModifierID++;
}
static get(base, mods) {
if (!mods.length)
return base;
let exists = mods[0].instances.find(t => t.base == base && sameArray(mods, t.modified));
if (exists)
return exists;
let set = [], tag = new Tag(set, base, mods);
for (let m of mods)
m.instances.push(tag);
let configs = powerSet(mods);
for (let parent of base.set)
if (!parent.modified.length)
for (let config of configs)
set.push(Modifier.get(parent, config));
return tag;
}
}
function sameArray(a, b) {
return a.length == b.length && a.every((x, i) => x == b[i]);
}
function powerSet(array) {
let sets = [[]];
for (let i = 0; i < array.length; i++) {
for (let j = 0, e = sets.length; j < e; j++) {
sets.push(sets[j].concat(array[i]));
}
}
return sets.sort((a, b) => b.length - a.length);
}
/**
This function is used to add a set of tags to a language syntax
via [`NodeSet.extend`](#common.NodeSet.extend) or
[`LRParser.configure`](#lr.LRParser.configure).
The argument object maps node selectors to [highlighting
tags](#highlight.Tag) or arrays of tags.
Node selectors may hold one or more (space-separated) node paths.
Such a path can be a [node name](#common.NodeType.name), or
multiple node names (or `*` wildcards) separated by slash
characters, as in `"Block/Declaration/VariableName"`. Such a path
matches the final node but only if its direct parent nodes are the
other nodes mentioned. A `*` in such a path matches any parent,
but only a single level—wildcards that match multiple parents
aren't supported, both for efficiency reasons and because Lezer
trees make it rather hard to reason about what they would match.)
A path can be ended with `/...` to indicate that the tag assigned
to the node should also apply to all child nodes, even if they
match their own style (by default, only the innermost style is
used).
When a path ends in `!`, as in `Attribute!`, no further matching
happens for the node's child nodes, and the entire node gets the
given style.
In this notation, node names that contain `/`, `!`, `*`, or `...`
must be quoted as JSON strings.
For example:
```javascript
parser.withProps(
styleTags({
// Style Number and BigNumber nodes
"Number BigNumber": tags.number,
// Style Escape nodes whose parent is String
"String/Escape": tags.escape,
// Style anything inside Attributes nodes
"Attributes!": tags.meta,
// Add a style to all content inside Italic nodes
"Italic/...": tags.emphasis,
// Style InvalidString nodes as both `string` and `invalid`
"InvalidString": [tags.string, tags.invalid],
// Style the node named "/" as punctuation
'"/"': tags.punctuation
})
)
```
*/
function styleTags(spec) {
let byName = Object.create(null);
for (let prop in spec) {
let tags = spec[prop];
if (!Array.isArray(tags))
tags = [tags];
for (let part of prop.split(" "))
if (part) {
let pieces = [], mode = 2 /* Normal */, rest = part;
for (let pos = 0;;) {
if (rest == "..." && pos > 0 && pos + 3 == part.length) {
mode = 1 /* Inherit */;
break;
}
let m = /^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(rest);
if (!m)
throw new RangeError("Invalid path: " + part);
pieces.push(m[0] == "*" ? "" : m[0][0] == '"' ? JSON.parse(m[0]) : m[0]);
pos += m[0].length;
if (pos == part.length)
break;
let next = part[pos++];
if (pos == part.length && next == "!") {
mode = 0 /* Opaque */;
break;
}
if (next != "/")
throw new RangeError("Invalid path: " + part);
rest = part.slice(pos);
}
let last = pieces.length - 1, inner = pieces[last];
if (!inner)
throw new RangeError("Invalid path: " + part);
let rule = new Rule(tags, mode, last > 0 ? pieces.slice(0, last) : null);
byName[inner] = rule.sort(byName[inner]);
}
}
return ruleNodeProp.add(byName);
}
const ruleNodeProp = new NodeProp();
class Rule {
constructor(tags, mode, context, next) {
this.tags = tags;
this.mode = mode;
this.context = context;
this.next = next;
}
get opaque() { return this.mode == 0 /* Opaque */; }
get inherit() { return this.mode == 1 /* Inherit */; }
sort(other) {
if (!other || other.depth < this.depth) {
this.next = other;
return this;
}
other.next = this.sort(other.next);
return other;
}
get depth() { return this.context ? this.context.length : 0; }
}
Rule.empty = new Rule([], 2 /* Normal */, null);
/**
Define a [highlighter](#highlight.Highlighter) from an array of
tag/class pairs. Classes associated with more specific tags will
take precedence.
*/
function tagHighlighter(tags, options) {
let map = Object.create(null);
for (let style of tags) {
if (!Array.isArray(style.tag))
map[style.tag.id] = style.class;
else
for (let tag of style.tag)
map[tag.id] = style.class;
}
let { scope, all = null } = options || {};
return {
style: (tags) => {
let cls = all;
for (let tag of tags) {
for (let sub of tag.set) {
let tagClass = map[sub.id];
if (tagClass) {
cls = cls ? cls + " " + tagClass : tagClass;
break;
}
}
}
return cls;
},
scope
};
}
function highlightTags(highlighters, tags) {
let result = null;
for (let highlighter of highlighters) {
let value = highlighter.style(tags);
if (value)
result = result ? result + " " + value : value;
}
return result;
}
/**
Highlight the given [tree](#common.Tree) with the given
[highlighter](#highlight.Highlighter).
*/
function highlightTree(tree, highlighter,
/**
Assign styling to a region of the text. Will be called, in order
of position, for any ranges where more than zero classes apply.
`classes` is a space separated string of CSS classes.
*/
putStyle,
/**
The start of the range to highlight.
*/
from = 0,
/**
The end of the range.
*/
to = tree.length) {
let builder = new HighlightBuilder(from, Array.isArray(highlighter) ? highlighter : [highlighter], putStyle);
builder.highlightRange(tree.cursor(), from, to, "", builder.highlighters);
builder.flush(to);
}
class HighlightBuilder {
constructor(at, highlighters, span) {
this.at = at;
this.highlighters = highlighters;
this.span = span;
this.class = "";
}
startSpan(at, cls) {
if (cls != this.class) {
this.flush(at);
if (at > this.at)
this.at = at;
this.class = cls;
}
}
flush(to) {
if (to > this.at && this.class)
this.span(this.at, to, this.class);
}
highlightRange(cursor, from, to, inheritedClass, highlighters) {
let { type, from: start, to: end } = cursor;
if (start >= to || end <= from)
return;
if (type.isTop)
highlighters = this.highlighters.filter(h => !h.scope || h.scope(type));
let cls = inheritedClass;
let rule = getStyleTags(cursor) || Rule.empty;
let tagCls = highlightTags(highlighters, rule.tags);
if (tagCls) {
if (cls)
cls += " ";
cls += tagCls;
if (rule.mode == 1 /* Inherit */)
inheritedClass += (inheritedClass ? " " : "") + tagCls;
}
this.startSpan(Math.max(from, start), cls);
if (rule.opaque)
return;
let mounted = cursor.tree && cursor.tree.prop(NodeProp.mounted);
if (mounted && mounted.overlay) {
let inner = cursor.node.enter(mounted.overlay[0].from + start, 1);
let innerHighlighters = this.highlighters.filter(h => !h.scope || h.scope(mounted.tree.type));
let hasChild = cursor.firstChild();
for (let i = 0, pos = start;; i++) {
let next = i < mounted.overlay.length ? mounted.overlay[i] : null;
let nextPos = next ? next.from + start : end;
let rangeFrom = Math.max(from, pos), rangeTo = Math.min(to, nextPos);
if (rangeFrom < rangeTo && hasChild) {
while (cursor.from < rangeTo) {
this.highlightRange(cursor, rangeFrom, rangeTo, inheritedClass, highlighters);
this.startSpan(Math.min(rangeTo, cursor.to), cls);
if (cursor.to >= nextPos || !cursor.nextSibling())
break;
}
}
if (!next || nextPos > to)
break;
pos = next.to + start;
if (pos > from) {
this.highlightRange(inner.cursor(), Math.max(from, next.from + start), Math.min(to, pos), "", innerHighlighters);
this.startSpan(Math.min(to, pos), cls);
}
}
if (hasChild)
cursor.parent();
}
else if (cursor.firstChild()) {
if (mounted)
inheritedClass = "";
do {
if (cursor.to <= from)
continue;
if (cursor.from >= to)
break;
this.highlightRange(cursor, from, to, inheritedClass, highlighters);
this.startSpan(Math.min(to, cursor.to), cls);
} while (cursor.nextSibling());
cursor.parent();
}
}
}
/**
Match a syntax node's [highlight rules](#highlight.styleTags). If
there's a match, return its set of tags, and whether it is
opaque (uses a `!`) or applies to all child nodes (`/...`).
*/
function getStyleTags(node) {
let rule = node.type.prop(ruleNodeProp);
while (rule && rule.context && !node.matchContext(rule.context))
rule = rule.next;
return rule || null;
}
const t = Tag.define;
const comment = t(), name = t(), typeName = t(name), propertyName = t(name), literal = t(), string = t(literal), number = t(literal), content = t(), heading = t(content), keyword = t(), operator = t(), punctuation = t(), bracket = t(punctuation), meta = t();
/**
The default set of highlighting [tags](#highlight.Tag).
This collection is heavily biased towards programming languages,
and necessarily incomplete. A full ontology of syntactic
constructs would fill a stack of books, and be impractical to
write themes for. So try to make do with this set. If all else
fails, [open an
issue](https://github.com/codemirror/codemirror.next) to propose a
new tag, or [define](#highlight.Tag^define) a local custom tag for
your use case.
Note that it is not obligatory to always attach the most specific
tag possible to an element—if your grammar can't easily
distinguish a certain type of element (such as a local variable),
it is okay to style it as its more general variant (a variable).
For tags that extend some parent tag, the documentation links to
the parent.
*/
const tags = {
/**
A comment.
*/
comment,
/**
A line [comment](#highlight.tags.comment).
*/
lineComment: t(comment),
/**
A block [comment](#highlight.tags.comment).
*/
blockComment: t(comment),
/**
A documentation [comment](#highlight.tags.comment).
*/
docComment: t(comment),
/**
Any kind of identifier.
*/
name,
/**
The [name](#highlight.tags.name) of a variable.
*/
variableName: t(name),
/**
A type [name](#highlight.tags.name).
*/
typeName: typeName,
/**
A tag name (subtag of [`typeName`](#highlight.tags.typeName)).
*/
tagName: t(typeName),
/**
A property or field [name](#highlight.tags.name).
*/
propertyName: propertyName,
/**
An attribute name (subtag of [`propertyName`](#highlight.tags.propertyName)).
*/
attributeName: t(propertyName),
/**
The [name](#highlight.tags.name) of a class.
*/
className: t(name),
/**
A label [name](#highlight.tags.name).
*/
labelName: t(name),
/**
A namespace [name](#highlight.tags.name).
*/
namespace: t(name),
/**
The [name](#highlight.tags.name) of a macro.
*/
macroName: t(name),
/**
A literal value.
*/
literal,
/**
A string [literal](#highlight.tags.literal).
*/
string,
/**
A documentation [string](#highlight.tags.string).
*/
docString: t(string),
/**
A character literal (subtag of [string](#highlight.tags.string)).
*/
character: t(string),
/**
An attribute value (subtag of [string](#highlight.tags.string)).
*/
attributeValue: t(string),
/**
A number [literal](#highlight.tags.literal).
*/
number,
/**
An integer [number](#highlight.tags.number) literal.
*/
integer: t(number),
/**
A floating-point [number](#highlight.tags.number) literal.
*/
float: t(number),
/**
A boolean [literal](#highlight.tags.literal).
*/
bool: t(literal),
/**
Regular expression [literal](#highlight.tags.literal).
*/
regexp: t(literal),
/**
An escape [literal](#highlight.tags.literal), for example a
backslash escape in a string.
*/
escape: t(literal),
/**
A color [literal](#highlight.tags.literal).
*/
color: t(literal),
/**
A URL [literal](#highlight.tags.literal).
*/
url: t(literal),
/**
A language keyword.
*/
keyword,
/**
The [keyword](#highlight.tags.keyword) for the self or this
object.
*/
self: t(keyword),
/**
The [keyword](#highlight.tags.keyword) for null.
*/
null: t(keyword),
/**
A [keyword](#highlight.tags.keyword) denoting some atomic value.
*/
atom: t(keyword),
/**
A [keyword](#highlight.tags.keyword) that represents a unit.
*/
unit: t(keyword),
/**
A modifier [keyword](#highlight.tags.keyword).
*/
modifier: t(keyword),
/**
A [keyword](#highlight.tags.keyword) that acts as an operator.
*/
operatorKeyword: t(keyword),
/**
A control-flow related [keyword](#highlight.tags.keyword).
*/
controlKeyword: t(keyword),
/**
A [keyword](#highlight.tags.keyword) that defines something.
*/
definitionKeyword: t(keyword),
/**
A [keyword](#highlight.tags.keyword) related to defining or
interfacing with modules.
*/
moduleKeyword: t(keyword),
/**
An operator.
*/
operator,
/**
An [operator](#highlight.tags.operator) that dereferences something.
*/
derefOperator: t(operator),
/**
Arithmetic-related [operator](#highlight.tags.operator).
*/
arithmeticOperator: t(operator),
/**
Logical [operator](#highlight.tags.operator).
*/
logicOperator: t(operator),
/**
Bit [operator](#highlight.tags.operator).
*/
bitwiseOperator: t(operator),
/**
Comparison [operator](#highlight.tags.operator).
*/
compareOperator: t(operator),
/**
[Operator](#highlight.tags.operator) that updates its operand.
*/
updateOperator: t(operator),
/**
[Operator](#highlight.tags.operator) that defines something.
*/
definitionOperator: t(operator),
/**
Type-related [operator](#highlight.tags.operator).
*/
typeOperator: t(operator),
/**
Control-flow [operator](#highlight.tags.operator).
*/
controlOperator: t(operator),
/**
Program or markup punctuation.
*/
punctuation,
/**
[Punctuation](#highlight.tags.punctuation) that separates
things.
*/
separator: t(punctuation),
/**
Bracket-style [punctuation](#highlight.tags.punctuation).
*/
bracket,
/**
Angle [brackets](#highlight.tags.bracket) (usually `<` and `>`
tokens).
*/
angleBracket: t(bracket),
/**
Square [brackets](#highlight.tags.bracket) (usually `[` and `]`
tokens).
*/
squareBracket: t(bracket),
/**
Parentheses (usually `(` and `)` tokens). Subtag of
[bracket](#highlight.tags.bracket).
*/
paren: t(bracket),
/**
Braces (usually `{` and `}` tokens). Subtag of
[bracket](#highlight.tags.bracket).
*/
brace: t(bracket),
/**
Content, for example plain text in XML or markup documents.
*/
content,
/**
[Content](#highlight.tags.content) that represents a heading.
*/
heading,
/**
A level 1 [heading](#highlight.tags.heading).
*/
heading1: t(heading),
/**
A level 2 [heading](#highlight.tags.heading).
*/
heading2: t(heading),
/**
A level 3 [heading](#highlight.tags.heading).
*/
heading3: t(heading),
/**
A level 4 [heading](#highlight.tags.heading).
*/
heading4: t(heading),
/**
A level 5 [heading](#highlight.tags.heading).
*/
heading5: t(heading),
/**
A level 6 [heading](#highlight.tags.heading).
*/
heading6: t(heading),
/**
A prose separator (such as a horizontal rule).
*/
contentSeparator: t(content),
/**
[Content](#highlight.tags.content) that represents a list.
*/
list: t(content),
/**
[Content](#highlight.tags.content) that represents a quote.
*/
quote: t(content),
/**
[Content](#highlight.tags.content) that is emphasized.
*/
emphasis: t(content),
/**
[Content](#highlight.tags.content) that is styled strong.
*/
strong: t(content),
/**
[Content](#highlight.tags.content) that is part of a link.
*/
link: t(content),
/**
[Content](#highlight.tags.content) that is styled as code or
monospace.
*/
monospace: t(content),
/**
[Content](#highlight.tags.content) that has a strike-through
style.
*/
strikethrough: t(content),
/**
Inserted text in a change-tracking format.
*/
inserted: t(),
/**
Deleted text.
*/
deleted: t(),
/**
Changed text.
*/
changed: t(),
/**
An invalid or unsyntactic element.
*/
invalid: t(),
/**
Metadata or meta-instruction.
*/
meta,
/**
[Metadata](#highlight.tags.meta) that applies to the entire
document.
*/
documentMeta: t(meta),
/**
[Metadata](#highlight.tags.meta) that annotates or adds
attributes to a given syntactic element.
*/
annotation: t(meta),
/**
Processing instruction or preprocessor directive. Subtag of
[meta](#highlight.tags.meta).
*/
processingInstruction: t(meta),
/**
[Modifier](#highlight.Tag^defineModifier) that indicates that a
given element is being defined. Expected to be used with the
various [name](#highlight.tags.name) tags.
*/
definition: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) that indicates that
something is constant. Mostly expected to be used with
[variable names](#highlight.tags.variableName).
*/
constant: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) used to indicate that
a [variable](#highlight.tags.variableName) or [property
name](#highlight.tags.propertyName) is being called or defined
as a function.
*/
function: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) that can be applied to
[names](#highlight.tags.name) to indicate that they belong to
the language's standard environment.
*/
standard: Tag.defineModifier(),
/**
[Modifier](#highlight.Tag^defineModifier) that indicates a given
[names](#highlight.tags.name) is local to some scope.
*/
local: Tag.defineModifier(),
/**
A generic variant [modifier](#highlight.Tag^defineModifier) that
can be used to tag language-specific alternative variants of
some common tag. It is recommended for themes to define special
forms of at least the [string](#highlight.tags.string) and
[variable name](#highlight.tags.variableName) tags, since those
come up a lot.
*/
special: Tag.defineModifier()
};
/**
This is a highlighter that adds stable, predictable classes to
tokens, for styling with external CSS.
The following tags are mapped to their name prefixed with `"tok-"`
(for example `"tok-comment"`):
* [`link`](#highlight.tags.link)
* [`heading`](#highlight.tags.heading)
* [`emphasis`](#highlight.tags.emphasis)
* [`strong`](#highlight.tags.strong)
* [`keyword`](#highlight.tags.keyword)
* [`atom`](#highlight.tags.atom)
* [`bool`](#highlight.tags.bool)
* [`url`](#highlight.tags.url)
* [`labelName`](#highlight.tags.labelName)
* [`inserted`](#highlight.tags.inserted)
* [`deleted`](#highlight.tags.deleted)
* [`literal`](#highlight.tags.literal)
* [`string`](#highlight.tags.string)
* [`number`](#highlight.tags.number)
* [`variableName`](#highlight.tags.variableName)
* [`typeName`](#highlight.tags.typeName)
* [`namespace`](#highlight.tags.namespace)
* [`className`](#highlight.tags.className)
* [`macroName`](#highlight.tags.macroName)
* [`propertyName`](#highlight.tags.propertyName)
* [`operator`](#highlight.tags.operator)
* [`comment`](#highlight.tags.comment)
* [`meta`](#highlight.tags.meta)
* [`punctuation`](#highlight.tags.punctuation)
* [`invalid`](#highlight.tags.invalid)
In addition, these mappings are provided:
* [`regexp`](#highlight.tags.regexp),
[`escape`](#highlight.tags.escape), and
[`special`](#highlight.tags.special)[`(string)`](#highlight.tags.string)
are mapped to `"tok-string2"`
* [`special`](#highlight.tags.special)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName2"`
* [`local`](#highlight.tags.local)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName tok-local"`
* [`definition`](#highlight.tags.definition)[`(variableName)`](#highlight.tags.variableName)
to `"tok-variableName tok-definition"`
* [`definition`](#highlight.tags.definition)[`(propertyName)`](#highlight.tags.propertyName)
to `"tok-propertyName tok-definition"`
*/
const classHighlighter = tagHighlighter([
{ tag: tags.link, class: "tok-link" },
{ tag: tags.heading, class: "tok-heading" },
{ tag: tags.emphasis, class: "tok-emphasis" },
{ tag: tags.strong, class: "tok-strong" },
{ tag: tags.keyword, class: "tok-keyword" },
{ tag: tags.atom, class: "tok-atom" },
{ tag: tags.bool, class: "tok-bool" },
{ tag: tags.url, class: "tok-url" },
{ tag: tags.labelName, class: "tok-labelName" },
{ tag: tags.inserted, class: "tok-inserted" },
{ tag: tags.deleted, class: "tok-deleted" },
{ tag: tags.literal, class: "tok-literal" },
{ tag: tags.string, class: "tok-string" },
{ tag: tags.number, class: "tok-number" },
{ tag: [tags.regexp, tags.escape, tags.special(tags.string)], class: "tok-string2" },
{ tag: tags.variableName, class: "tok-variableName" },
{ tag: tags.local(tags.variableName), class: "tok-variableName tok-local" },
{ tag: tags.definition(tags.variableName), class: "tok-variableName tok-definition" },
{ tag: tags.special(tags.variableName), class: "tok-variableName2" },
{ tag: tags.definition(tags.propertyName), class: "tok-propertyName tok-definition" },
{ tag: tags.typeName, class: "tok-typeName" },
{ tag: tags.namespace, class: "tok-namespace" },
{ tag: tags.className, class: "tok-className" },
{ tag: tags.macroName, class: "tok-macroName" },
{ tag: tags.propertyName, class: "tok-propertyName" },
{ tag: tags.operator, class: "tok-operator" },
{ tag: tags.comment, class: "tok-comment" },
{ tag: tags.meta, class: "tok-meta" },
{ tag: tags.invalid, class: "tok-invalid" },
{ tag: tags.punctuation, class: "tok-punctuation" }
]);
export { Tag, classHighlighter, getStyleTags, highlightTree, styleTags, tagHighlighter, tags };

31
node_modules/@lezer/highlight/package.json generated vendored Normal file
View File

@ -0,0 +1,31 @@
{
"name": "@lezer/highlight",
"version": "1.1.6",
"description": "Highlighting system for Lezer parse trees",
"main": "dist/index.cjs",
"type": "module",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"module": "dist/index.js",
"types": "dist/index.d.ts",
"author": "Marijn Haverbeke <marijn@haverbeke.berlin>",
"license": "MIT",
"devDependencies": {
"@marijn/buildtool": "0.1.3",
"typescript": "^5.0.0"
},
"dependencies": {
"@lezer/common": "^1.0.0"
},
"files": ["dist"],
"repository": {
"type" : "git",
"url" : "https://github.com/lezer-parser/highlight.git"
},
"scripts": {
"watch": "node build.js --watch",
"prepare": "node build.js"
}
}

1
node_modules/@lezer/javascript/.tern-port generated vendored Normal file
View File

@ -0,0 +1 @@
34881

329
node_modules/@lezer/javascript/CHANGELOG.md generated vendored Normal file
View File

@ -0,0 +1,329 @@
## 1.4.4 (2023-07-03)
### Bug fixes
Add support for `using` syntax.
Make the package work with new TS resolution styles.
## 1.4.3 (2023-04-24)
### Bug fixes
Properly parse `this: Type` within parameter lists for TypeScript.
## 1.4.2 (2023-03-29)
### Bug fixes
Properly parse `declare` in front of class properties and methods in TypeScript.
## 1.4.1 (2023-01-09)
### Bug fixes
Fix a bug where something like `yield [1]` (or `await`) was parsed as a member expression.
Add support for `yield*` syntax.
Escapes in strings are now parsed as their own tokens (and styled with the `escape` tag).
## 1.4.0 (2022-12-19)
### New features
The new `"SingleClassItem"` top-level rule can be used to parse only a class item (method, property, or static block).
## 1.3.2 (2022-12-14)
### Bug fixes
Typescript allows `override` on all class elements, not just methods.
Allow expressions in class extends clauses in TypeScript.
## 1.3.1 (2022-11-29)
### Bug fixes
Actually emit a tree node for the `@` characters in decorators.
## 1.3.0 (2022-11-28)
### New features
Add support for decorator syntax.
## 1.2.0 (2022-11-24)
### New features
The grammar now supports `top: "SingleExpression"` to parse an expression rather than a script.
## 1.1.1 (2022-11-19)
### Bug fixes
Fix parsing of computed properties in class declarations.
## 1.1.0 (2022-11-17)
### Bug fixes
Fix parsing of 'null' as type in TypeScript.
Allow computed properties in object destructuring patterns.
Add TypeScript 4.9's `satisfies` operator.
Support `accessor` syntax on class properties.
### New features
Add support for optional call syntax.
Distinguish lower-case JSX element names syntactically, give them a `standard(tagName)` highlight tag.
## 1.0.2 (2022-07-21)
### Bug fixes
Properly assign a highlighting tag to the `super` keyword.
## 1.0.1 (2022-06-27)
### Bug fixes
Fix parsing of TypeScript conditional types.
Support type parameters in TypeScript function type syntax.
## 1.0.0 (2022-06-06)
### New features
First stable version.
## 0.16.0 (2022-04-20)
### Breaking changes
Move to 0.16 serialized parser format.
### Bug fixes
Allow commas as separators in TypeScript object type syntax.
### New features
Add `CatchClause` and `FinallyClause` nodes wrapping parts of `TryStatement`.
The parser now includes syntax highlighting information in its node types.
## 0.15.3 (2022-01-26)
### Bug fixes
Support missing values in array pattern syntax.
Support quoted module export names.
### New features
Template string interpolations now get their own nodes in the syntax tree.
## 0.15.2 (2021-12-08)
### Bug fixes
Fix a typo in the `TaggedTemplateExpression` node name. Support n suffixes after non-decimal integers
Add support for non-decimal bignum literals ().
Add support for static class initialization blocks.
## 0.15.1 (2021-11-12)
### Bug fixes
Add support for TypeScript `import {type X} from y` syntax.
Indexed TypeScript types can now take type parameters.
Add support for private field syntax.
Rename PropertyNameDefinition node to PropertyDefinition for consistency with other names.
### New features
Recognize TypeScript 4.3's `override` keyword.
## 0.15.0 (2021-08-11)
### Breaking changes
The module's name changed from `lezer-javascript` to `@lezer/javascript`.
Upgrade to the 0.15.0 lezer interfaces.
## 0.13.4 (2021-04-30)
### Bug fixes
Fixes a bug where arrow functions with expression bodies would include commas after the expression.
## 0.13.3 (2021-02-15)
### Bug fixes
Wrap escaped JSX attribute values in a `JSXEscape` node.
## 0.13.2 (2021-01-18)
### Bug fixes
Fix parsing of async function expressions.
## 0.13.1 (2020-12-04)
### Bug fixes
Fix versions of lezer packages depended on.
## 0.13.0 (2020-12-04)
## 0.12.0 (2020-10-23)
### Breaking changes
Adjust to changed serialized parser format.
## 0.11.1 (2020-09-26)
### Bug fixes
Fix lezer depencency versions
## 0.11.0 (2020-09-26)
### Breaking changes
Follow change in serialized parser format.
## 0.10.1 (2020-09-02)
### Bug fixes
Fix associativity of `else` and ternary operators.
Work around accidental ambiguity of TypeScript method and constructor signatures.
Properly parse `??=` as an update operator.
## 0.10.0 (2020-08-07)
### Breaking changes
Upgrade to 0.10 parser serialization
### New features
The gammar now supports TypeScript (use the `"ts"` dialect).
The grammar can now parse JSX syntax (use the `"jsx"` dialect).
## 0.9.1 (2020-06-29)
### Bug fixes
Fix accidental use of non-ES5 library methods.
## 0.9.0 (2020-06-08)
### Breaking changes
Upgrade to 0.9 parser serialization
## 0.8.4 (2020-05-30)
### Bug fixes
Fix the package.json `main` field pointing at the wrong file, breaking the library in node versions older than 13.
## 0.8.3 (2020-04-09)
### Bug fixes
Regenerate parser with a fix in lezer-generator so that the top node prop is properly assigned.
## 0.8.2 (2020-04-01)
### Bug fixes
Make the package load as an ES module on node
## 0.8.1 (2020-02-28)
### New features
Provide an ES module file.
## 0.8.0 (2020-02-03)
### Bug fixes
Add support for the spread ... operator in array literals.
### New features
Follow 0.8.0 release of the library.
Add support for nullish coalescing and optional chaining.
## 0.7.0 (2020-01-20)
### Breaking changes
Use the lezer 0.7.0 parser format.
## 0.5.2 (2020-01-15)
### Bug fixes
Regenerate with lezer-generator 0.5.2 to avoid cyclic forced reductions.
## 0.5.1 (2019-10-22)
### Bug fixes
Fix top prop missing from build output.
## 0.5.0 (2019-10-22)
### Breaking changes
Move from `lang` to `top` prop on document node.
## 0.4.0 (2019-09-10)
### Breaking changes
Adjust to 0.4.0 parse table format.
## 0.3.0 (2019-08-22)
### New features
Go back to node names, add props, follow changes in grammar syntax.
## 0.2.0 (2019-08-02)
### New features
Use tags rather than names.
## 0.1.0 (2019-07-09)
### New Features
First documented release.

21
node_modules/@lezer/javascript/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (C) 2018 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

14
node_modules/@lezer/javascript/README.md generated vendored Normal file
View File

@ -0,0 +1,14 @@
# @lezer/javascript
This is a JavaScript grammar for the
[lezer](https://lezer.codemirror.net/) parser system.
It parses ES2020, and supports a `"ts"`
[dialect](https://lezer.codemirror.net/docs/guide/#dialects) to parse
TypeScript, and a `"jsx"` dialect to parse JSX.
The `top` option can be set to `"SingleExpression"` or
`"SingleClassItem"` to parse an expression or class item instead of a
full program.
The code is licensed under an MIT license.

149
node_modules/@lezer/javascript/dist/index.cjs generated vendored Normal file

File diff suppressed because one or more lines are too long

3
node_modules/@lezer/javascript/dist/index.d.cts generated vendored Normal file
View File

@ -0,0 +1,3 @@
import {LRParser} from "@lezer/lr"
export const parser: LRParser

3
node_modules/@lezer/javascript/dist/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,3 @@
import {LRParser} from "@lezer/lr"
export const parser: LRParser

145
node_modules/@lezer/javascript/dist/index.js generated vendored Normal file

File diff suppressed because one or more lines are too long

35
node_modules/@lezer/javascript/package.json generated vendored Normal file
View File

@ -0,0 +1,35 @@
{
"name": "@lezer/javascript",
"version": "1.4.4",
"description": "lezer-based JavaScript grammar",
"main": "dist/index.cjs",
"type": "module",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"module": "dist/index.js",
"types": "dist/index.d.ts",
"author": "Marijn Haverbeke <marijn@haverbeke.berlin>",
"license": "MIT",
"devDependencies": {
"@lezer/generator": "^1.0.0",
"mocha": "^9.0.1",
"rollup": "^2.52.2",
"@rollup/plugin-node-resolve": "^9.0.0"
},
"dependencies": {
"@lezer/lr": "^1.3.0",
"@lezer/highlight": "^1.1.3"
},
"repository": {
"type": "git",
"url": "https://github.com/lezer-parser/javascript.git"
},
"scripts": {
"build": "lezer-generator src/javascript.grammar -o src/parser && rollup -c",
"build-debug": "lezer-generator src/javascript.grammar --names -o src/parser && rollup -c",
"prepare": "npm run build",
"test": "mocha test/test-*.js"
}
}

16
node_modules/@lezer/javascript/rollup.config.js generated vendored Normal file
View File

@ -0,0 +1,16 @@
import {nodeResolve} from "@rollup/plugin-node-resolve"
export default {
input: "./src/parser.js",
output: [{
format: "cjs",
file: "./dist/index.cjs"
}, {
format: "es",
file: "./dist/index.js"
}],
external(id) { return !/^[\.\/]/.test(id) },
plugins: [
nodeResolve()
]
}

61
node_modules/@lezer/javascript/src/highlight.js generated vendored Normal file
View File

@ -0,0 +1,61 @@
import {styleTags, tags as t} from "@lezer/highlight"
export const jsHighlight = styleTags({
"get set async static": t.modifier,
"for while do if else switch try catch finally return throw break continue default case": t.controlKeyword,
"in of await yield void typeof delete instanceof": t.operatorKeyword,
"let var const function class extends": t.definitionKeyword,
"import export from": t.moduleKeyword,
"with debugger as new": t.keyword,
TemplateString: t.special(t.string),
super: t.atom,
BooleanLiteral: t.bool,
this: t.self,
null: t.null,
Star: t.modifier,
VariableName: t.variableName,
"CallExpression/VariableName TaggedTemplateExpression/VariableName": t.function(t.variableName),
VariableDefinition: t.definition(t.variableName),
Label: t.labelName,
PropertyName: t.propertyName,
PrivatePropertyName: t.special(t.propertyName),
"CallExpression/MemberExpression/PropertyName": t.function(t.propertyName),
"FunctionDeclaration/VariableDefinition": t.function(t.definition(t.variableName)),
"ClassDeclaration/VariableDefinition": t.definition(t.className),
PropertyDefinition: t.definition(t.propertyName),
PrivatePropertyDefinition: t.definition(t.special(t.propertyName)),
UpdateOp: t.updateOperator,
LineComment: t.lineComment,
BlockComment: t.blockComment,
Number: t.number,
String: t.string,
Escape: t.escape,
ArithOp: t.arithmeticOperator,
LogicOp: t.logicOperator,
BitOp: t.bitwiseOperator,
CompareOp: t.compareOperator,
RegExp: t.regexp,
Equals: t.definitionOperator,
Arrow: t.function(t.punctuation),
": Spread": t.punctuation,
"( )": t.paren,
"[ ]": t.squareBracket,
"{ }": t.brace,
"InterpolationStart InterpolationEnd": t.special(t.brace),
".": t.derefOperator,
", ;": t.separator,
"@": t.meta,
TypeName: t.typeName,
TypeDefinition: t.definition(t.typeName),
"type enum interface implements namespace module declare": t.definitionKeyword,
"abstract global Privacy readonly override": t.modifier,
"is keyof unique infer": t.operatorKeyword,
JSXAttributeValue: t.attributeValue,
JSXText: t.content,
"JSXStartTag JSXStartCloseTag JSXSelfCloseEndTag JSXEndTag": t.angleBracket,
"JSXIdentifier JSXNameSpacedName": t.tagName,
"JSXAttribute/JSXIdentifier JSXAttribute/JSXNameSpacedName": t.attributeName,
"JSXBuiltin/JSXIdentifier": t.standard(t.tagName)
})

701
node_modules/@lezer/javascript/src/javascript.grammar generated vendored Normal file
View File

@ -0,0 +1,701 @@
@dialects { jsx, ts }
@precedence {
typeargs,
typeMember,
typePrefix,
intersection @left,
union @left,
typeExtends @right,
else @right,
member,
readonly,
newArgs,
call,
taggedTemplate,
prefix,
postfix,
typeof,
exp @left,
times @left,
plus @left,
shift @left,
loop,
rel @left,
satisfies,
equal @left,
bitOr @left,
bitXor @left,
bitAnd @left,
and @left,
or @left,
ternary @right,
assign @right,
comma @left,
statement @cut,
predicate
}
@top Script { statement+ }
@top SingleExpression { expression }
@top SingleClassItem { classItem }
statement[@isGroup=Statement] {
ExportDeclaration |
ImportDeclaration |
ForStatement { kw<"for"> ckw<"await">? (ForSpec | ForInSpec | ForOfSpec) statement } |
WhileStatement { kw<"while"> ParenthesizedExpression statement } |
WithStatement { kw<"with"> ParenthesizedExpression statement } |
DoStatement { kw<"do"> statement kw<"while"> ParenthesizedExpression semi } |
IfStatement { kw<"if"> ParenthesizedExpression statement (!else kw<"else"> statement)? } |
SwitchStatement { kw<"switch"> ParenthesizedExpression SwitchBody { "{" switchItem* "}" } } |
TryStatement {
kw<"try"> Block
CatchClause { kw<"catch"> ("(" pattern ")")? Block }?
FinallyClause { kw<"finally"> Block }?
} |
ReturnStatement { kw<"return"> (noSemi expression)? semi } |
ThrowStatement { kw<"throw"> expression semi } |
BreakStatement { kw<"break"> (noSemi Label)? semi } |
ContinueStatement { kw<"continue"> (noSemi Label)? semi } |
DebuggerStatement { kw<"debugger"> semi } |
Block |
LabeledStatement { Label ":" statement } |
declaration |
ExpressionStatement { expression semi } |
";"
}
ExportDeclaration {
kw<"export"> Star (ckw<"as"> (VariableName | String))? ckw<"from"> String semi |
kw<"export"> kw<"default"> (FunctionDeclaration | ClassDeclaration | expression semi) |
kw<"export"> tskw<"type">? declaration |
kw<"export"> tskw<"type">? ExportGroup (ckw<"from"> String)? semi |
kw<"export"> "=" expression semi
}
ExportGroup {
"{" commaSep<VariableName (ckw<"as"> (VariableName { word } | String))?> "}"
}
ImportDeclaration {
kw<"import"> tskw<"type">? (Star ckw<"as"> VariableDefinition | commaSep<VariableDefinition | ImportGroup>)
ckw<"from"> String semi |
kw<"import"> String semi
}
ImportGroup {
"{" commaSep<tskw<"type">? (VariableDefinition | (VariableName | String) ckw<"as"> VariableDefinition)> "}"
}
ForSpec {
"("
(VariableDeclaration | expression ";" | ";") expression? ";" expression?
")"
}
forXSpec<op> {
"("
(variableDeclarationKeyword pattern | VariableName | MemberExpression | ArrayPattern | ObjectPattern)
!loop op expression
")"
}
ForInSpec { forXSpec<kw<"in">> }
ForOfSpec { forXSpec<ckw<"of">> }
declaration {
FunctionDeclaration |
ClassDeclaration |
VariableDeclaration |
TypeAliasDeclaration |
InterfaceDeclaration |
EnumDeclaration |
NamespaceDeclaration |
AmbientDeclaration
}
FunctionDeclaration {
async? !statement kw<"function"> Star? VariableDefinition? functionSignature (Block | semi)
}
ClassDeclaration {
!statement Decorator* tskw<"abstract">? kw<"class"> VariableDefinition TypeParamList?
(kw<"extends"> ((VariableName | MemberExpression) !typeargs TypeArgList | expression))?
(tskw<"implements"> commaSep1<type>)?
ClassBody
}
classItem { MethodDeclaration | PropertyDeclaration | StaticBlock | ";" }
ClassBody { "{" classItem* "}" }
privacy {
@extend[@name=Privacy,@dialect=ts]<word, "public" | "private" | "protected">
}
privacyArg {
@extend[@name=Privacy,@dialect=ts]<identifier, "public" | "private" | "protected">
}
propModifier {
Decorator |
tsPkwMod<"declare"> |
privacy |
pkwMod<"static"> |
tsPkwMod<"abstract"> |
tsPkwMod<"override">
}
MethodDeclaration[group=ClassItem] {
propModifier*
pkwMod<"async">?
(pkwMod<"get"> | pkwMod<"set"> | Star)?
(propName | PrivatePropertyDefinition)
functionSignature
(Block | semi)
}
StaticBlock[group=ClassItem] {
pkwMod<"static"> Block
}
PropertyDeclaration[group=ClassItem] {
propModifier*
(tsPkwMod<"readonly"> | pkwMod<"accessor">)?
(propName | PrivatePropertyDefinition)
(Optional | LogicOp<"!">)?
TypeAnnotation?
("=" expressionNoComma)?
semi
}
variableDeclarationKeyword {
kw<"let"> | kw<"var"> | kw<"const"> | ckw<"await">? ckw<"using">
}
VariableDeclaration {
variableDeclarationKeyword commaSep1<patternAssignTyped> semi
}
TypeAliasDeclaration {
tskw<"type"> TypeDefinition TypeParamList? "=" type semi
}
InterfaceDeclaration {
tskw<"interface"> TypeDefinition TypeParamList? (kw<"extends"> type)? ObjectType
}
EnumDeclaration {
kw<"const">? tskw<"enum"> TypeDefinition EnumBody { "{" commaSep<PropertyName ("=" expressionNoComma)?> "}" }
}
NamespaceDeclaration {
(tskw<"namespace"> | tskw<"module">) VariableDefinition ("." PropertyDefinition)* Block
}
AmbientDeclaration {
tskw<"declare"> (
VariableDeclaration |
TypeAliasDeclaration |
EnumDeclaration |
InterfaceDeclaration |
NamespaceDeclaration |
GlobalDeclaration { tskw<"global"> Block } |
ClassDeclaration {
tskw<"abstract">? kw<"class"> VariableDefinition TypeParamList?
(kw<"extends"> expression)?
(tskw<"implements"> commaSep1<type>)?
ClassBody { "{" (
MethodDeclaration |
PropertyDeclaration |
IndexSignature semi
)* "}" }
} |
AmbientFunctionDeclaration {
async? kw<"function"> Star? VariableDefinition? TypeParamList? ParamList (TypeAnnotation | TypePredicate) semi
}
)
}
decoratorExpression {
VariableName |
MemberExpression { decoratorExpression !member ("." | "?.") (PropertyName | PrivatePropertyName) } |
CallExpression { decoratorExpression !call TypeArgList? "?."? ArgList } |
ParenthesizedExpression
}
Decorator { "@" decoratorExpression }
pattern { VariableDefinition | ArrayPattern | ObjectPattern }
ArrayPattern { "[" commaSep<("..."? patternAssign)?> ~destructure "]" }
ObjectPattern { "{" commaSep<PatternProperty> ~destructure "}" }
patternAssign {
pattern ("=" expressionNoComma)?
}
TypeAnnotation { ":" type }
TypePredicate { ":" (VariableName | kw<"this">) !predicate tskw<"is"> type }
patternAssignTyped {
pattern Optional? TypeAnnotation? ("=" expressionNoComma)?
}
ParamList {
"(" commaSep<"..." patternAssignTyped | Decorator* privacyArg? tskw<"readonly">? patternAssignTyped | kw<"this"> TypeAnnotation> ")"
}
Block {
!statement "{" statement* "}"
}
switchItem {
CaseLabel { kw<"case"> expression ":" } |
DefaultLabel { kw<"default"> ":" } |
statement
}
expression[@isGroup=Expression] {
expressionNoComma | SequenceExpression
}
SequenceExpression {
expressionNoComma !comma ("," expressionNoComma)+
}
expressionNoComma {
Number |
String |
TemplateString |
VariableName |
boolean |
kw<"this"> |
kw<"null"> |
kw<"super"> |
RegExp |
ArrayExpression |
ObjectExpression { "{" commaSep<Property> ~destructure "}" } |
NewExpression { kw<"new"> expressionNoComma (!newArgs TypeArgList? ArgList)? } |
UnaryExpression |
YieldExpression |
AwaitExpression |
ParenthesizedExpression |
ClassExpression |
FunctionExpression |
ArrowFunction |
MemberExpression |
BinaryExpression |
ConditionalExpression { expressionNoComma !ternary questionOp expressionNoComma LogicOp<":"> expressionNoComma } |
AssignmentExpression |
PostfixExpression { expressionNoComma !postfix (incdec | LogicOp<"!">) } |
CallExpression { expressionNoComma !call TypeArgList? "?."? ArgList } |
TaggedTemplateExpression { expressionNoComma !taggedTemplate TemplateString } |
DynamicImport { kw<"import"> "(" expressionNoComma ")" } |
ImportMeta { kw<"import"> "." PropertyName } |
JSXElement |
PrefixCast { tsAngleOpen type ~tsAngle ">" expressionNoComma } |
ArrowFunction[@dynamicPrecedence=1] {
TypeParamList { tsAngleOpen commaSep<typeParam> ">" } ParamList TypeAnnotation? "=>" (Block | expressionNoComma)
}
}
ParenthesizedExpression { "(" expression ")" }
ArrayExpression {
"[" commaSep1<"..."? expressionNoComma | ""> ~destructure "]"
}
propName { PropertyDefinition | "[" expression "]" | Number | String }
Property {
pkwMod<"async">? (pkwMod<"get"> | pkwMod<"set"> | Star)? propName functionSignature Block |
propName ~destructure (":" expressionNoComma)? |
"..." expressionNoComma
}
PatternProperty {
"..." patternAssign |
((PropertyName | Number | String) ~destructure (":" pattern)? |
("[" expression "]" ~destructure ":" pattern)) ("=" expressionNoComma)?
}
ClassExpression {
kw<"class"> VariableDefinition? (kw<"extends"> expression)? ClassBody
}
functionSignature { TypeParamList? ParamList (TypeAnnotation | TypePredicate)? }
FunctionExpression {
async? kw<"function"> Star? VariableDefinition? functionSignature Block
}
YieldExpression[@dynamicPrecedence=1] {
!prefix ckw<"yield"> Star? expressionNoComma
}
AwaitExpression[@dynamicPrecedence=1] {
!prefix ckw<"await"> expressionNoComma
}
UnaryExpression {
!prefix (kw<"void"> | kw<"typeof"> | kw<"delete"> |
LogicOp<"!"> | BitOp<"~"> | incdec | incdecPrefix | ArithOp<"+" | "-">)
expressionNoComma
}
BinaryExpression {
expressionNoComma !exp ArithOp<"**"> expressionNoComma |
expressionNoComma !times (divide | ArithOp<"%"> | ArithOp<"*">) expressionNoComma |
expressionNoComma !plus ArithOp<"+" | "-"> expressionNoComma |
expressionNoComma !shift BitOp<">>" ">"? | "<<"> expressionNoComma |
expressionNoComma !rel (LessThan | CompareOp<"<=" | ">" "="?> | kw<"instanceof">) expressionNoComma |
expressionNoComma !satisfies tskw<"satisfies"> type |
(expressionNoComma | PrivatePropertyName) !rel ~tsIn kw<"in"> expressionNoComma |
expressionNoComma !rel ckw<"as"> (kw<"const"> | type) |
expressionNoComma !equal CompareOp<"==" "="? | "!=" "="?> expressionNoComma |
expressionNoComma !bitOr BitOp { "|" } expressionNoComma |
expressionNoComma !bitXor BitOp<"^"> expressionNoComma |
expressionNoComma !bitAnd BitOp { "&" } expressionNoComma |
expressionNoComma !and LogicOp<"&&"> expressionNoComma |
expressionNoComma !or LogicOp<"||" | "??"> expressionNoComma
}
AssignmentExpression {
(VariableName | MemberExpression) !assign UpdateOp<($[+\-/%^] | "*" "*"? | "|" "|"? | "&" "&"? | "<<" | ">>" ">"? | "??") "=">
expressionNoComma |
(VariableName | MemberExpression | ArrayPattern | ObjectPattern) !assign "=" expressionNoComma
}
MemberExpression {
expressionNoComma !member (("." | "?.") (PropertyName | PrivatePropertyName) | "?."? "[" expression "]")
}
ArgList {
"(" commaSep<"..."? expressionNoComma> ")"
}
ArrowFunction {
async? (ParamList { VariableDefinition } | ParamList TypeAnnotation?) "=>" (Block | expressionNoComma)
}
TypeArgList {
@extend[@dialect=ts,@name="<"]<LessThan, "<"> commaSep<type> ">"
}
TypeParamList {
"<" commaSep<typeParam> ">"
}
typeParam { TypeDefinition ~tsAngle (kw<"extends"> type)? ("=" type)? }
typeofMemberExpression[@name=MemberExpression] {
VariableName !member (("." | "?.") PropertyName | "[" expression "]")
}
type[@isGroup=Type] {
ThisType { kw<"this"> } |
LiteralType {
ArithOp<"+" | "-">? Number |
boolean |
String
} |
TemplateType |
NullType { kw<"null"> } |
VoidType { kw<"void"> } |
TypeofType { kw<"typeof"> (VariableName | typeofMemberExpression) } |
KeyofType { !typePrefix tskw<"keyof"> type } |
UniqueType { !typePrefix tskw<"unique"> type } |
ImportType { kw<"import"> "(" String ")" } |
InferredType { tskw<"infer"> TypeName } |
ParenthesizedType { "(" type ")" } |
FunctionSignature { TypeParamList? ParamTypeList "=>" type } |
NewSignature { kw<"new"> ParamTypeList "=>" type } |
IndexedType |
TupleType { "[" commaSep<(Label ":")? type | "..." type> "]" } |
ArrayType { type "[" "]" | type "[" "]" } |
ReadonlyType { tskw<"readonly"> !readonly type } |
ObjectType |
UnionType { type !union LogicOp { "|" } type } |
IntersectionType { type !intersection LogicOp { "&" } type } |
ConditionalType { type !typeExtends kw<"extends"> type questionOp ~arrow type LogicOp<":"> type } |
ParameterizedType { (TypeName | IndexedType) !typeargs TypeArgList } |
TypeName
}
IndexedType {
type !typeMember ("." TypeName | "[" (String | Number) "]")+
}
ObjectType {
"{" (
(MethodType |
PropertyType |
IndexSignature |
CallSignature { ParamTypeList (TypeAnnotation | TypePredicate) } |
NewSignature[@dynamicPrecedence=1] { @extend[@name=new]<word, "new"> ParamTypeList TypeAnnotation })
("," | semi)
)* "}"
}
IndexSignature {
tsPkwMod<"readonly">? "[" PropertyDefinition { identifier } (TypeAnnotation | ~tsIn kw<"in"> type) "]" TypeAnnotation
}
MethodType {
pkwMod<"async">?
(pkwMod<"get"> | pkwMod<"set"> | Star)?
PropertyDefinition
functionSignature
}
PropertyType {
(ArithOp<"+" | "-">? tsPkwMod<"readonly">)?
PropertyDefinition
(ArithOp<"+" | "-">? Optional)?
TypeAnnotation
}
ParamTypeList[@name=ParamList] {
"(" commaSep<"..."? VariableDefinition ~arrow Optional? ~arrow TypeAnnotation?> ")"
}
@skip {} {
TemplateString {
templateStart (templateEscape | templateContent | templateExpr)* templateEnd
}
TemplateType {
templateStart (templateContent | templateType)* templateEnd
}
String {
'"' (stringContentDouble | Escape)* ('"' | "\n") |
"'" (stringContentSingle | Escape)* ("'" | "\n")
}
BlockComment { "/*" (blockCommentContent | blockCommentNewline)* blockCommentEnd }
}
templateExpr[@name=Interpolation] { InterpolationStart expression InterpolationEnd }
templateType[@name=Interpolation] { InterpolationStart type InterpolationEnd }
@skip {} {
JSXElement {
JSXSelfClosingTag |
(JSXOpenTag | JSXFragmentTag) (JSXText | JSXElement | JSXEscape)* JSXCloseTag
}
}
JSXSelfClosingTag { JSXStartTag jsxElementName jsxAttribute* JSXSelfCloseEndTag }
JSXOpenTag { JSXStartTag jsxElementName jsxAttribute* JSXEndTag }
JSXFragmentTag { JSXStartTag JSXEndTag }
JSXCloseTag { JSXStartCloseTag jsxElementName? JSXEndTag }
jsxElementName {
JSXIdentifier |
JSXBuiltin { JSXLowerIdentifier } |
JSXNamespacedName |
JSXMemberExpression
}
JSXMemberExpression { (JSXMemberExpression | JSXIdentifier | JSXLowerIdentifier) "." (JSXIdentifier | JSXLowerIdentifier) }
JSXNamespacedName { (JSXIdentifier | JSXNamespacedName | JSXLowerIdentifier) ":" (JSXIdentifier | JSXLowerIdentifier) }
jsxAttribute {
JSXSpreadAttribute { "{" "..." expression "}" } |
JSXAttribute { (JSXIdentifier | JSXNamespacedName | JSXLowerIdentifier) ("=" jsxAttributeValue)? }
}
jsxAttributeValue {
JSXAttributeValue |
JSXEscape { "{" expression "}" } |
JSXElement
}
JSXEscape { "{" "..."? expression "}" }
commaSep<content> {
"" | content ("," content?)*
}
commaSep1<content> {
content ("," content)*
}
// Keywords
kw<term> { @specialize[@name={term}]<identifier, term> }
// Contextual keywords
ckw<term> { @extend[@name={term}]<identifier, term> }
tskw<term> { @extend[@name={term},@dialect=ts]<identifier, term> }
async { @extend[@name=async]<identifier, "async"> }
// Contextual keyword in property context
pkwMod<term> { @extend[@name={term}]<word, term> }
tsPkwMod<term> { @extend[@name={term},@dialect=ts]<word, term> }
semi { ";" | insertSemi }
boolean { @specialize[@name=BooleanLiteral]<identifier, "true" | "false"> }
Star { "*" }
VariableName { identifier ~arrow }
VariableDefinition { identifier ~arrow }
TypeDefinition { identifier }
TypeName { identifier ~arrow }
Label { identifier }
PropertyName { word }
PropertyDefinition { word }
PrivatePropertyName { privateIdentifier }
PrivatePropertyDefinition { privateIdentifier }
Optional { "?" }
questionOp[@name=LogicOp] { "?" }
@skip { spaces | newline | LineComment | BlockComment }
@context trackNewline from "./tokens.js"
@external tokens noSemicolon from "./tokens" { noSemi }
@external tokens incdecToken from "./tokens" {
incdec[@name=ArithOp],
incdecPrefix[@name=ArithOp]
}
@local tokens {
InterpolationStart[closedBy=InterpolationEnd] { "${" }
templateEnd { "`" }
templateEscape[@name=Escape] { Escape }
@else templateContent
}
@local tokens {
blockCommentEnd { "*/" }
blockCommentNewline { "\n" }
@else blockCommentContent
}
@tokens {
spaces[@export] { $[\u0009 \u000b\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+ }
newline[@export] { $[\r\n\u2028\u2029] }
LineComment { "//" ![\n]* }
divide[@name=ArithOp] { "/" }
@precedence { "/*", LineComment, divide }
@precedence { "/*", LineComment, RegExp }
identifierChar { @asciiLetter | $[_$\u{a1}-\u{10ffff}] }
word { identifierChar (identifierChar | @digit)* }
identifier { word }
privateIdentifier { "#" word }
@precedence { spaces, newline, identifier }
@precedence { spaces, newline, JSXIdentifier, JSXLowerIdentifier }
@precedence { spaces, newline, word }
hex { @digit | $[a-fA-F] }
Number {
(@digit ("_" | @digit)* ("." ("_" | @digit)*)? | "." @digit ("_" | @digit)*)
(("e" | "E") ("+" | "-")? ("_" | @digit)+)? |
@digit ("_" | @digit)* "n" |
"0x" (hex | "_")+ "n"? |
"0b" $[01_]+ "n"? |
"0o" $[0-7_]+ "n"?
}
@precedence { Number "." }
Escape {
"\\" ("x" hex hex | "u" ("{" hex+ "}" | hex hex hex hex) | ![xu])
}
stringContentSingle { ![\\\n']+ }
stringContentDouble { ![\\\n"]+ }
templateStart { "`" }
InterpolationEnd[openedBy=InterpolationStart] { "}" }
ArithOp<expr> { expr }
LogicOp<expr> { expr }
BitOp<expr> { expr }
CompareOp<expr> { expr }
UpdateOp<expr> { expr }
@precedence { "*", ArithOp }
RegExp { "/" (![/\\\n[] | "\\" ![\n] | "[" (![\n\\\]] | "\\" ![\n])* "]")+ ("/" $[gimsuy]*)? }
LessThan[@name=CompareOp] { "<" }
"="[@name=Equals]
"..."[@name=Spread]
"=>"[@name=Arrow]
"(" ")" "[" "]" "{" "}" ">"
"?." "." "," ";" ":" "@"
JSXIdentifier { $[A-Z_$\u{a1}-\u{10ffff}] (identifierChar | @digit | "-")* }
JSXLowerIdentifier[@name=JSXIdentifier] { $[a-z] (identifierChar | @digit | "-")* }
JSXAttributeValue { '"' !["]* '"' | "'" ![']* "'" }
JSXStartTag[@dialect=jsx] { "<" }
JSXStartCloseTag { "</" }
JSXEndTag { ">" }
JSXSelfCloseEndTag { "/>" }
JSXText { ![<{]+ }
tsAngleOpen[@dialect=ts] { "<" }
@precedence { JSXStartTag, tsAngleOpen }
}
@external tokens insertSemicolon from "./tokens" { insertSemi }
@external propSource jsHighlight from "./highlight"
@detectDelim

32
node_modules/@lezer/javascript/src/parser.js generated vendored Normal file

File diff suppressed because one or more lines are too long

106
node_modules/@lezer/javascript/src/parser.terms.js generated vendored Normal file
View File

@ -0,0 +1,106 @@
// This file was generated by lezer-generator. You probably shouldn't edit it.
export const
noSemi = 303,
incdec = 1,
incdecPrefix = 2,
insertSemi = 304,
spaces = 306,
newline = 307,
LineComment = 3,
BlockComment = 4,
Script = 5,
ExportDeclaration = 6,
Star = 8,
VariableName = 10,
String = 11,
Escape = 12,
FunctionDeclaration = 16,
VariableDefinition = 19,
TypeParamList = 21,
TypeDefinition = 22,
Number = 28,
TemplateType = 30,
InterpolationEnd = 31,
templateType = 32,
InterpolationStart = 33,
typeofMemberExpression = 40,
PropertyName = 43,
TemplateString = 45,
templateEscape = 46,
templateExpr = 47,
RegExp = 49,
ArrayExpression = 51,
Property = 57,
PropertyDefinition = 61,
Block = 62,
TypeArgList = 66,
LessThan = 67,
ArgList = 71,
UnaryExpression = 72,
YieldExpression = 76,
AwaitExpression = 78,
ParenthesizedExpression = 80,
ClassExpression = 81,
ClassBody = 83,
MethodDeclaration = 84,
Decorator = 85,
PrivatePropertyName = 88,
PrivatePropertyDefinition = 95,
PropertyDeclaration = 96,
Optional = 99,
TypeAnnotation = 100,
StaticBlock = 102,
FunctionExpression = 103,
ArrowFunction = 104,
ParamList = 106,
ArrayPattern = 107,
ObjectPattern = 108,
PatternProperty = 109,
MemberExpression = 113,
BinaryExpression = 114,
divide = 116,
questionOp = 132,
AssignmentExpression = 134,
JSXElement = 142,
JSXSelfCloseEndTag = 143,
JSXStartTag = 144,
JSXSelfClosingTag = 145,
JSXIdentifier = 146,
JSXLowerIdentifier = 148,
JSXNamespacedName = 149,
JSXMemberExpression = 150,
JSXAttributeValue = 153,
JSXEndTag = 155,
JSXOpenTag = 156,
JSXFragmentTag = 157,
JSXText = 158,
JSXEscape = 159,
JSXStartCloseTag = 160,
JSXCloseTag = 161,
SequenceExpression = 165,
TypeName = 173,
ParamTypeList = 176,
IndexedType = 178,
Label = 180,
ObjectType = 183,
MethodType = 184,
PropertyType = 185,
IndexSignature = 186,
TypePredicate = 189,
ClassDeclaration = 199,
VariableDeclaration = 203,
TypeAliasDeclaration = 207,
InterfaceDeclaration = 208,
EnumDeclaration = 210,
NamespaceDeclaration = 213,
AmbientDeclaration = 216,
ExportGroup = 223,
ImportDeclaration = 226,
ImportGroup = 227,
ForSpec = 230,
ForInSpec = 231,
ForOfSpec = 232,
SingleExpression = 267,
SingleClassItem = 268,
Dialect_jsx = 0,
Dialect_ts = 1

45
node_modules/@lezer/javascript/src/tokens.js generated vendored Normal file
View File

@ -0,0 +1,45 @@
/* Hand-written tokenizers for JavaScript tokens that can't be
expressed by lezer's built-in tokenizer. */
import {ExternalTokenizer, ContextTracker} from "@lezer/lr"
import {insertSemi, noSemi, incdec, incdecPrefix,
spaces, newline, BlockComment, LineComment} from "./parser.terms.js"
const space = [9, 10, 11, 12, 13, 32, 133, 160, 5760, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200,
8201, 8202, 8232, 8233, 8239, 8287, 12288]
const braceR = 125, semicolon = 59, slash = 47, star = 42, plus = 43, minus = 45
export const trackNewline = new ContextTracker({
start: false,
shift(context, term) {
return term == LineComment || term == BlockComment || term == spaces ? context : term == newline
},
strict: false
})
export const insertSemicolon = new ExternalTokenizer((input, stack) => {
let {next} = input
if (next == braceR || next == -1 || stack.context)
input.acceptToken(insertSemi)
}, {contextual: true, fallback: true})
export const noSemicolon = new ExternalTokenizer((input, stack) => {
let {next} = input, after
if (space.indexOf(next) > -1) return
if (next == slash && ((after = input.peek(1)) == slash || after == star)) return
if (next != braceR && next != semicolon && next != -1 && !stack.context)
input.acceptToken(noSemi)
}, {contextual: true})
export const incdecToken = new ExternalTokenizer((input, stack) => {
let {next} = input
if (next == plus || next == minus) {
input.advance()
if (next == input.next) {
input.advance()
let mayPostfix = !stack.context && stack.canShift(incdec)
input.acceptToken(mayPostfix ? incdec : incdecPrefix)
}
}
}, {contextual: true})

1
node_modules/@lezer/javascript/test/.tern-port generated vendored Normal file
View File

@ -0,0 +1 @@
46625

64
node_modules/@lezer/javascript/test/decorator.txt generated vendored Normal file
View File

@ -0,0 +1,64 @@
# Decorators on classes and class fields
@d1 class Foo {
@d2 bar() {}
@d3 get baz() { return 1 }
@d4 quux = 1
}
==>
Script(ClassDeclaration(
Decorator(VariableName),
class,VariableDefinition,ClassBody(
MethodDeclaration(Decorator(VariableName),PropertyDefinition,ParamList,Block),
MethodDeclaration(Decorator(VariableName),get,PropertyDefinition,ParamList,Block(
ReturnStatement(return,Number))),
PropertyDeclaration(Decorator(VariableName),PropertyDefinition,Equals,Number))))
# Multiple decorators
@d1 @d2 class Y {}
==>
Script(ClassDeclaration(Decorator(VariableName),Decorator(VariableName),class,VariableDefinition,ClassBody))
# Member decorators
@one.two class X {}
==>
Script(ClassDeclaration(Decorator(MemberExpression(VariableName,PropertyName)),class,VariableDefinition,ClassBody))
# Call decorators
@d(2) @a.b() class Z {}
==>
Script(ClassDeclaration(
Decorator(CallExpression(VariableName,ArgList(Number))),
Decorator(CallExpression(MemberExpression(VariableName,PropertyName),ArgList)),
class,VariableDefinition,ClassBody))
# Parenthesized decorators
@(a instanceof Array ? x : y)(2) class P {}
==>
Script(ClassDeclaration(
Decorator(CallExpression(ParenthesizedExpression(
ConditionalExpression(BinaryExpression(VariableName,instanceof,VariableName),LogicOp,VariableName,LogicOp,VariableName)),
ArgList(Number))),
class,VariableDefinition,ClassBody))
# Parameter decorators
function foo(@d bar) {}
==>
Script(FunctionDeclaration(function,VariableDefinition,ParamList(Decorator(VariableName),VariableDefinition),Block))

678
node_modules/@lezer/javascript/test/expression.txt generated vendored Normal file
View File

@ -0,0 +1,678 @@
# Minimal
0
==>
Script(ExpressionStatement(Number))
# Strings
"A string with \"double\" and 'single' quotes";
'A string with "double" and \'single\' quotes';
'\\';
"\\";
'A string with new \
line';
==>
Script(ExpressionStatement(String(Escape,Escape)),
ExpressionStatement(String(Escape,Escape)),
ExpressionStatement(String(Escape)),
ExpressionStatement(String(Escape)),
ExpressionStatement(String(Escape)))
# Numbers
101;
3.14;
3.14e+1;
0x1ABCDEFabcdef;
0o7632157312;
0b1010101001;
1e+3;
==>
Script(
ExpressionStatement(Number),
ExpressionStatement(Number),
ExpressionStatement(Number),
ExpressionStatement(Number),
ExpressionStatement(Number),
ExpressionStatement(Number),
ExpressionStatement(Number))
# Identifiers
theVar;
theVar2;
$_;
é象𫝄;
últimaVez;
県;
==>
Script(
ExpressionStatement(VariableName),
ExpressionStatement(VariableName),
ExpressionStatement(VariableName),
ExpressionStatement(VariableName),
ExpressionStatement(VariableName),
ExpressionStatement(VariableName))
# RegExps
/one\\/;
/one/g;
/one/i;
/one/gim;
/on\/e/gim;
/on[^/]afe/gim;
/[\]/]/;
==>
Script(
ExpressionStatement(RegExp),
ExpressionStatement(RegExp),
ExpressionStatement(RegExp),
ExpressionStatement(RegExp),
ExpressionStatement(RegExp),
ExpressionStatement(RegExp),
ExpressionStatement(RegExp))
# Arrays
[];
[ "item1" ];
[ "item1", ];
[ "item1", item2 ];
[ , item2 ];
[ item2 = 5 ];
[ a, ...b, c ];
==>
Script(
ExpressionStatement(ArrayExpression),
ExpressionStatement(ArrayExpression(String)),
ExpressionStatement(ArrayExpression(String)),
ExpressionStatement(ArrayExpression(String,VariableName)),
ExpressionStatement(ArrayExpression(VariableName)),
ExpressionStatement(ArrayExpression(AssignmentExpression(VariableName,Equals,Number))),
ExpressionStatement(ArrayExpression(VariableName, Spread, VariableName, VariableName)))
# Functions
[
function() {},
function(arg1, ...arg2) {
arg2;
},
function stuff() {},
function trailing(a,) {},
function trailing(a,b,) {}
]
==>
Script(ExpressionStatement(ArrayExpression(
FunctionExpression(function,ParamList,Block),
FunctionExpression(function,ParamList(VariableDefinition,Spread,VariableDefinition), Block(ExpressionStatement(VariableName))),
FunctionExpression(function,VariableDefinition,ParamList,Block),
FunctionExpression(function,VariableDefinition,ParamList(VariableDefinition), Block),
FunctionExpression(function,VariableDefinition,ParamList(VariableDefinition,VariableDefinition),Block))))
# Arrow functions
a => 1;
() => 2;
(d, e) => 3;
(f, g,) => {
return h;
};
async () => 4;
==>
Script(
ExpressionStatement(ArrowFunction(ParamList(VariableDefinition),Arrow,Number)),
ExpressionStatement(ArrowFunction(ParamList,Arrow,Number)),
ExpressionStatement(ArrowFunction(ParamList(VariableDefinition,VariableDefinition),Arrow,Number)),
ExpressionStatement(ArrowFunction(ParamList(VariableDefinition,VariableDefinition),Arrow,Block(ReturnStatement(return,VariableName)))),
ExpressionStatement(ArrowFunction(async,ParamList,Arrow,Number)))
# Arrow function followed by comma
({
a: () => 1,
b: "x"
})
==>
Script(ExpressionStatement(ParenthesizedExpression(ObjectExpression(
Property(PropertyDefinition,ArrowFunction(ParamList,Arrow,Number)),
Property(PropertyDefinition,String)))))
# Long potential arrow function
(assign = [to, from], from = assign[0], to = assign[1]);
==>
Script(ExpressionStatement(ParenthesizedExpression(SequenceExpression(
AssignmentExpression(VariableName,Equals,ArrayExpression(VariableName,VariableName)),
AssignmentExpression(VariableName,Equals,MemberExpression(VariableName,Number)),
AssignmentExpression(VariableName,Equals,MemberExpression(VariableName,Number))))))
# Ternary operator
condition ? case1 : case2;
x.y = some.condition ? 2**x : 1 - 2;
==>
Script(
ExpressionStatement(ConditionalExpression(VariableName,LogicOp,VariableName,LogicOp,VariableName)),
ExpressionStatement(AssignmentExpression(
MemberExpression(VariableName,PropertyName),Equals,
ConditionalExpression(
MemberExpression(VariableName,PropertyName),LogicOp,
BinaryExpression(Number,ArithOp,VariableName),LogicOp,
BinaryExpression(Number,ArithOp,Number)))))
# Type operators
typeof x;
x instanceof String;
==>
Script(ExpressionStatement(UnaryExpression(typeof,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,instanceof,VariableName)))
# Delete
delete thing['prop'];
true ? delete thing.prop : null;
==>
Script(
ExpressionStatement(UnaryExpression(delete,MemberExpression(VariableName,String))),
ExpressionStatement(ConditionalExpression(BooleanLiteral,LogicOp,
UnaryExpression(delete,MemberExpression(VariableName,PropertyName)),LogicOp,null)))
# Void
a = void b();
==>
Script(ExpressionStatement(AssignmentExpression(VariableName,Equals,UnaryExpression(void,CallExpression(VariableName,ArgList)))))
# Augmented assignment
s |= 1;
t %= 2;
w ^= 3;
x += 4;
y.z *= 5;
z += 1;
a >>= 1;
b >>>= 1;
c <<= 1;
==>
Script(
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,PropertyName),UpdateOp,Number)),
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)))
# Operator precedence
a <= b && c >= d;
a.b = c ? d : e;
a && b(c) && d;
a && new b(c) && d;
typeof a == b && c instanceof d;
==>
Script(
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,CompareOp,VariableName),LogicOp,
BinaryExpression(VariableName,CompareOp,VariableName))),
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,PropertyName),Equals,
ConditionalExpression(VariableName,LogicOp,VariableName,LogicOp,VariableName))),
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,LogicOp,CallExpression(VariableName,ArgList(VariableName))),LogicOp,
VariableName)),
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,LogicOp,NewExpression(new,VariableName,ArgList(VariableName))),LogicOp,
VariableName)),
ExpressionStatement(BinaryExpression(BinaryExpression(UnaryExpression(typeof,VariableName),CompareOp,VariableName),LogicOp,
BinaryExpression(VariableName,instanceof,VariableName))))
# Rest args
foo(...rest);
==>
Script(ExpressionStatement(CallExpression(VariableName,ArgList(Spread,VariableName))))
# Forward slashes after parenthesized expressions
(foo - bar) / baz;
if (foo - bar) /baz/;
(this.a() / this.b() - 1) / 2;
==>
Script(
ExpressionStatement(BinaryExpression(ParenthesizedExpression(BinaryExpression(VariableName,ArithOp,VariableName)),ArithOp,VariableName)),
IfStatement(if,ParenthesizedExpression(BinaryExpression(VariableName,ArithOp,VariableName)),
ExpressionStatement(RegExp)),
ExpressionStatement(BinaryExpression(ParenthesizedExpression(
BinaryExpression(
BinaryExpression(
CallExpression(MemberExpression(this,PropertyName),ArgList),ArithOp,
CallExpression(MemberExpression(this,PropertyName),ArgList)),ArithOp,Number)),ArithOp,Number)))
# Yield expressions
yield db.users.where('[endpoint+email]');
yield* a;
yield [22];
==>
Script(
ExpressionStatement(YieldExpression(yield,
CallExpression(MemberExpression(MemberExpression(VariableName,PropertyName),PropertyName),ArgList(String)))),
ExpressionStatement(YieldExpression(yield,Star,VariableName)),
ExpressionStatement(YieldExpression(yield,ArrayExpression(Number))))
# Template strings
`one line`;
`multi
line`;
`multi
${2 + 2}
hello
${1, 2}
line`;
`$$$$`;
`$`;
`$$$$${ async }`;
`\\\``;
`one${`two${`three`}`}`;
f`hi${there}`;
==>
Script(
ExpressionStatement(TemplateString),
ExpressionStatement(TemplateString),
ExpressionStatement(TemplateString(
Interpolation(InterpolationStart,BinaryExpression(Number,ArithOp,Number),InterpolationEnd),
Interpolation(InterpolationStart,SequenceExpression(Number,Number),InterpolationEnd))),
ExpressionStatement(TemplateString),
ExpressionStatement(TemplateString),
ExpressionStatement(TemplateString(Interpolation(InterpolationStart,VariableName,InterpolationEnd))),
ExpressionStatement(TemplateString(Escape,Escape)),
ExpressionStatement(TemplateString(Interpolation(InterpolationStart,TemplateString(
Interpolation(InterpolationStart,TemplateString,InterpolationEnd)),InterpolationEnd))),
ExpressionStatement(TaggedTemplateExpression(VariableName,TemplateString(
Interpolation(InterpolationStart,VariableName,InterpolationEnd)))))
# Atoms
this;
null;
undefined;
true;
false;
==>
Script(
ExpressionStatement(this),
ExpressionStatement(null),
ExpressionStatement(VariableName),
ExpressionStatement(BooleanLiteral),
ExpressionStatement(BooleanLiteral))
# Objects
foo({},
{ a: "b" },
{ c: "d", "e": f, 1: 2 },
{
g,
[methodName]() {}
},
{b, get},
{a,});
==>
Script(ExpressionStatement(CallExpression(VariableName,ArgList(
ObjectExpression,
ObjectExpression(Property(PropertyDefinition,String)),
ObjectExpression(Property(PropertyDefinition,String),Property(String,VariableName),Property(Number,Number)),
ObjectExpression(Property(PropertyDefinition),Property(VariableName,ParamList,Block)),
ObjectExpression(Property(PropertyDefinition),Property(PropertyDefinition)),
ObjectExpression(Property(PropertyDefinition))))))
# Method definitions
({
foo: true,
add(a, b) {
return a + b;
},
get bar() { return c; },
set bar(a) { c = a; },
*barGenerator() { yield c; },
get() { return 1; }
});
==>
Script(ExpressionStatement(ParenthesizedExpression(ObjectExpression(
Property(PropertyDefinition,BooleanLiteral),
Property(PropertyDefinition,ParamList(VariableDefinition,VariableDefinition),
Block(ReturnStatement(return,BinaryExpression(VariableName,ArithOp,VariableName)))),
Property(get,PropertyDefinition,ParamList,Block(ReturnStatement(return,VariableName))),
Property(set,PropertyDefinition,ParamList(VariableDefinition),
Block(ExpressionStatement(AssignmentExpression(VariableName,Equals,VariableName)))),
Property(Star,PropertyDefinition,ParamList,Block(ExpressionStatement(YieldExpression(yield,VariableName)))),
Property(PropertyDefinition,ParamList,Block(ReturnStatement(return,Number)))))))
# Keyword property names
({
finally() {},
catch() {},
get: function () {},
set() {},
static: true,
async: true,
});
==>
Script(ExpressionStatement(ParenthesizedExpression(ObjectExpression(
Property(PropertyDefinition,ParamList,Block),
Property(PropertyDefinition,ParamList,Block),
Property(PropertyDefinition,FunctionExpression(function,ParamList,Block)),
Property(PropertyDefinition,ParamList,Block),
Property(PropertyDefinition,BooleanLiteral),
Property(PropertyDefinition,BooleanLiteral)))))
# Generator functions
[
function *() {},
function *generateStuff(arg1, arg2) {
yield;
yield arg2;
}
];
==>
Script(ExpressionStatement(ArrayExpression(
FunctionExpression(function,Star,ParamList,Block),
FunctionExpression(function,Star,VariableDefinition,ParamList(VariableDefinition,VariableDefinition),Block(
ExpressionStatement(VariableName),
ExpressionStatement(YieldExpression(yield,VariableName)))))))
# Member expressions
x.someProperty;
x?.other;
x[someVariable];
f()["some-string"];
return returned.promise().done(a).fail(b);
==>
Script(
ExpressionStatement(MemberExpression(VariableName,PropertyName)),
ExpressionStatement(MemberExpression(VariableName,PropertyName)),
ExpressionStatement(MemberExpression(VariableName,VariableName)),
ExpressionStatement(MemberExpression(CallExpression(VariableName,ArgList),String)),
ReturnStatement(return,CallExpression(MemberExpression(CallExpression(MemberExpression(CallExpression(
MemberExpression(VariableName,PropertyName),ArgList),PropertyName),ArgList(VariableName)),PropertyName),ArgList(VariableName))))
# Callback chain
return this.map(function (a) {
return a.b;
})
// a comment
.filter(function (c) {
return 2;
});
==>
Script(ReturnStatement(return,CallExpression(MemberExpression(CallExpression(MemberExpression(this,PropertyName),
ArgList(FunctionExpression(function,ParamList(VariableDefinition),Block(ReturnStatement(return,MemberExpression(VariableName,PropertyName)))))),
LineComment,PropertyName),ArgList(FunctionExpression(function,ParamList(VariableDefinition),Block(ReturnStatement(return,Number)))))))
# Function calls
x.someMethod(arg1, "arg2");
(function(x, y) {
}(a, b));
f(new foo.bar(1), 2);
==>
Script(
ExpressionStatement(CallExpression(MemberExpression(VariableName,PropertyName),ArgList(VariableName,String))),
ExpressionStatement(ParenthesizedExpression(CallExpression(FunctionExpression(function,ParamList(VariableDefinition,VariableDefinition),Block),
ArgList(VariableName,VariableName)))),
ExpressionStatement(CallExpression(VariableName,ArgList(NewExpression(new,MemberExpression(VariableName,PropertyName),ArgList(Number)),Number))))
# Constructor calls
new foo(1);
new module.Klass(1, "two");
new Thing;
==>
Script(
ExpressionStatement(NewExpression(new,VariableName,ArgList(Number))),
ExpressionStatement(NewExpression(new,MemberExpression(VariableName,PropertyName),ArgList(Number,String))),
ExpressionStatement(NewExpression(new,VariableName)))
# Await Expressions
await asyncFunction();
await asyncPromise;
==>
Script(
ExpressionStatement(AwaitExpression(await,CallExpression(VariableName,ArgList))),
ExpressionStatement(AwaitExpression(await,VariableName)))
# Numeric operators
i++;
i--;
i + j * 3 - j % 5;
2 ** i * 3;
2 * i ** 3;
+x;
-x;
==>
Script(
ExpressionStatement(PostfixExpression(VariableName,ArithOp)),
ExpressionStatement(PostfixExpression(VariableName,ArithOp)),
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,ArithOp,BinaryExpression(VariableName,ArithOp,Number)),ArithOp,BinaryExpression(VariableName,ArithOp,Number))),
ExpressionStatement(BinaryExpression(BinaryExpression(Number,ArithOp,VariableName),ArithOp,Number)),
ExpressionStatement(BinaryExpression(Number,ArithOp,BinaryExpression(VariableName,ArithOp,Number))),
ExpressionStatement(UnaryExpression(ArithOp,VariableName)),
ExpressionStatement(UnaryExpression(ArithOp,VariableName)))
# Boolean operators
i || j;
i && j;
i ?? j;
!a && !b || !c && !d;
==>
Script(
ExpressionStatement(BinaryExpression(VariableName,LogicOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,LogicOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,LogicOp,VariableName)),
ExpressionStatement(BinaryExpression(BinaryExpression(UnaryExpression(LogicOp,VariableName),LogicOp,
UnaryExpression(LogicOp,VariableName)),LogicOp,BinaryExpression(UnaryExpression(LogicOp,VariableName),LogicOp,
UnaryExpression(LogicOp,VariableName)))))
# Bitwise operators
i >> j;
i >>> j;
i << j;
i & j;
i | j;
~i ^ ~j;
==>
Script(
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
ExpressionStatement(BinaryExpression(UnaryExpression(BitOp,VariableName),BitOp,UnaryExpression(BitOp,VariableName))))
# Relational operators
x < y;
x <= y;
x == y;
x === y;
x != y;
x !== y;
x > y;
x >= y;
==>
Script(
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)))
# Word operators
x in y;
x instanceof y;
!x instanceof y;
==>
Script(
ExpressionStatement(BinaryExpression(VariableName,in,VariableName)),
ExpressionStatement(BinaryExpression(VariableName,instanceof,VariableName)),
ExpressionStatement(BinaryExpression(UnaryExpression(LogicOp,VariableName),instanceof,VariableName)))
# Assignments
x = 0;
x.y = 0;
x["y"] = 0;
async = 0;
[a, b = 2] = foo;
({a, b, ...d} = c);
==>
Script(
ExpressionStatement(AssignmentExpression(VariableName,Equals,Number)),
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,PropertyName),Equals,Number)),
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,String),Equals,Number)),
ExpressionStatement(AssignmentExpression(VariableName,Equals,Number)),
ExpressionStatement(AssignmentExpression(ArrayPattern(VariableDefinition,VariableDefinition,Equals,Number),Equals,VariableName)),
ExpressionStatement(ParenthesizedExpression(AssignmentExpression(ObjectPattern(
PatternProperty(PropertyName),PatternProperty(PropertyName),PatternProperty(Spread,VariableDefinition)),Equals,VariableName))))
# Comma operator
a = 1, b = 2;
c = {d: (3, 4 + 5)};
==>
Script(
ExpressionStatement(SequenceExpression(AssignmentExpression(VariableName,Equals,Number),AssignmentExpression(VariableName,Equals,Number))),
ExpressionStatement(AssignmentExpression(VariableName,Equals,ObjectExpression(
Property(PropertyDefinition,ParenthesizedExpression(SequenceExpression(Number,BinaryExpression(Number,ArithOp,Number))))))))
# Punctuation
(foo(1, 2), bar);
==>
Script(ExpressionStatement(ParenthesizedExpression(
"(",SequenceExpression(CallExpression(VariableName,ArgList("(",Number,Number,")")),",",VariableName),")")))
# Doesn't choke on unfinished ternary operator
1?1
==>
Script(ExpressionStatement(ConditionalExpression(Number,LogicOp,Number,⚠)))
# Can handle unterminated template literals
`f
==>
Script(ExpressionStatement(TemplateString(⚠)))

79
node_modules/@lezer/javascript/test/jsx.txt generated vendored Normal file
View File

@ -0,0 +1,79 @@
# Self-closing element {"dialect": "jsx"}
<img/>
==>
Script(ExpressionStatement(JSXElement(JSXSelfClosingTag(JSXStartTag,JSXBuiltin(JSXIdentifier),JSXSelfCloseEndTag))))
# Regular element {"dialect": "jsx"}
<Foo>bar</Foo>
==>
Script(ExpressionStatement(JSXElement(
JSXOpenTag(JSXStartTag, JSXIdentifier, JSXEndTag),
JSXText,
JSXCloseTag(JSXStartCloseTag, JSXIdentifier, JSXEndTag))))
# Fragment {"dialect": "jsx"}
<>bar</>
==>
Script(ExpressionStatement(JSXElement(
JSXFragmentTag(JSXStartTag, JSXEndTag),
JSXText,
JSXCloseTag(JSXStartCloseTag, JSXEndTag))))
# Namespaced name {"dialect": "jsx"}
<blah-namespace:img/>
==>
Script(ExpressionStatement(JSXElement(
JSXSelfClosingTag(JSXStartTag,JSXNamespacedName(JSXIdentifier, JSXIdentifier),JSXSelfCloseEndTag))))
# Member name {"dialect": "jsx"}
<pkg.Component/>
==>
Script(ExpressionStatement(JSXElement(
JSXSelfClosingTag(JSXStartTag,JSXMemberExpression(JSXIdentifier, JSXIdentifier),JSXSelfCloseEndTag))))
# Nested tags {"dialect": "jsx"}
<a><b.C>text</b.C>{x} {...y}</a>
==>
Script(ExpressionStatement(JSXElement(
JSXOpenTag(JSXStartTag, JSXBuiltin(JSXIdentifier), JSXEndTag),
JSXElement(
JSXOpenTag(JSXStartTag, JSXMemberExpression(JSXIdentifier, JSXIdentifier), JSXEndTag),
JSXText,
JSXCloseTag(JSXStartCloseTag, JSXMemberExpression(JSXIdentifier, JSXIdentifier), JSXEndTag)),
JSXEscape(VariableName),
JSXText,
JSXEscape(Spread, VariableName),
JSXCloseTag(JSXStartCloseTag, JSXBuiltin(JSXIdentifier), JSXEndTag))))
# Attributes {"dialect": "jsx"}
<Foo a="1" b {...attrs} c={c}></Foo>
==>
Script(ExpressionStatement(JSXElement(
JSXOpenTag(JSXStartTag, JSXIdentifier,
JSXAttribute(JSXIdentifier, Equals, JSXAttributeValue),
JSXAttribute(JSXIdentifier),
JSXSpreadAttribute(Spread, VariableName),
JSXAttribute(JSXIdentifier, Equals, JSXEscape(VariableName)),
JSXEndTag),
JSXCloseTag(JSXStartCloseTag, JSXIdentifier, JSXEndTag))))

77
node_modules/@lezer/javascript/test/semicolon.txt generated vendored Normal file
View File

@ -0,0 +1,77 @@
# No semicolons
x
if (a) {
var b = c
d
} else
e
==>
Script(
ExpressionStatement(VariableName),
IfStatement(if,ParenthesizedExpression(VariableName),Block(
VariableDeclaration(var,VariableDefinition,Equals,VariableName),
ExpressionStatement(VariableName)),
else,ExpressionStatement(VariableName)))
# Continued expressions on new line
x
+ 2
foo
(bar)
==>
Script(
ExpressionStatement(BinaryExpression(VariableName,ArithOp,Number)),
ExpressionStatement(CallExpression(VariableName,ArgList(VariableName))))
# Doesn't parse postfix ops on a new line
x
++y
==>
Script(
ExpressionStatement(VariableName),
ExpressionStatement(UnaryExpression(ArithOp,VariableName)))
# Eagerly cut return/break/continue
return 2
return
2
continue foo
continue
foo
break bar
break
bar
==>
Script(
ReturnStatement(return,Number),
ReturnStatement(return),
ExpressionStatement(Number),
ContinueStatement(continue,Label),
ContinueStatement(continue),
ExpressionStatement(VariableName),
BreakStatement(break,Label),
BreakStatement(break),
ExpressionStatement(VariableName))
# Cut return regardless of whitespace
{ return }
return // foo
;
==>
Script(Block(ReturnStatement(return)),ReturnStatement(return,LineComment))

376
node_modules/@lezer/javascript/test/statement.txt generated vendored Normal file
View File

@ -0,0 +1,376 @@
# Variable declaration
var a = b
, c = d;
const [x] = y = 3;
==>
Script(
VariableDeclaration(var,VariableDefinition,Equals,VariableName,VariableDefinition,Equals,VariableName),
VariableDeclaration(const,ArrayPattern(VariableDefinition),Equals,AssignmentExpression(VariableName,Equals,Number)))
# Function declaration
function a(a, b) { return 3; }
function b({b}, c = d, e = f) {}
==>
Script(
FunctionDeclaration(function,VariableDefinition,ParamList(VariableDefinition,VariableDefinition),Block(ReturnStatement(return,Number))),
FunctionDeclaration(function,VariableDefinition,ParamList(
ObjectPattern(PatternProperty(PropertyName)),VariableDefinition,Equals,VariableName,VariableDefinition,Equals,VariableName),Block))
# Async functions
async function foo() {}
class Foo { async bar() {} }
async (a) => { return foo; };
==>
Script(
FunctionDeclaration(async,function,VariableDefinition,ParamList,Block),
ClassDeclaration(class,VariableDefinition,ClassBody(MethodDeclaration(async,PropertyDefinition,ParamList,Block))),
ExpressionStatement(ArrowFunction(async,ParamList(VariableDefinition),Arrow,Block(ReturnStatement(return,VariableName)))))
# If statements
if (x) log(y);
if (a.b) {
d;
}
if (a) {
c;
d;
} else {
e;
}
if (1) if (2) b; else c;
==>
Script(
IfStatement(if,ParenthesizedExpression(VariableName),ExpressionStatement(CallExpression(VariableName,ArgList(VariableName)))),
IfStatement(if,ParenthesizedExpression(MemberExpression(VariableName,PropertyName)),Block(ExpressionStatement(VariableName))),
IfStatement(if,ParenthesizedExpression(VariableName),Block(ExpressionStatement(VariableName),ExpressionStatement(VariableName)),
else,Block(ExpressionStatement(VariableName))),
IfStatement(if,ParenthesizedExpression(Number),IfStatement(if,ParenthesizedExpression(Number),ExpressionStatement(VariableName),
else,ExpressionStatement(VariableName))))
# While loop
while (1) debugger;
while (2) {
a;
b;
}
==>
Script(
WhileStatement(while,ParenthesizedExpression(Number),DebuggerStatement(debugger)),
WhileStatement(while,ParenthesizedExpression(Number),Block(ExpressionStatement(VariableName),ExpressionStatement(VariableName))))
# Labels
foo: 1;
foo: while(2) break foo;
==>
Script(
LabeledStatement(Label,ExpressionStatement(Number)),
LabeledStatement(Label,WhileStatement(while,ParenthesizedExpression(Number),BreakStatement(break,Label))))
# Try
try { throw new Error; } catch {}
try { 1; } catch (x) { 2; } finally { 3; }
==>
Script(
TryStatement(try,Block(ThrowStatement(throw,NewExpression(new,VariableName))),CatchClause(catch,Block)),
TryStatement(try,Block(ExpressionStatement(Number)),
CatchClause(catch,VariableDefinition,Block(ExpressionStatement(Number))),
FinallyClause(finally,Block(ExpressionStatement(Number)))))
# Switch
switch (x) {
case 1:
return true;
case 2:
case 50 * 3:
console.log("ok");
default:
return false;
}
==>
Script(SwitchStatement(switch,ParenthesizedExpression(VariableName),SwitchBody(
CaseLabel(case,Number),
ReturnStatement(return,BooleanLiteral),
CaseLabel(case,Number),
CaseLabel(case,BinaryExpression(Number,ArithOp,Number)),
ExpressionStatement(CallExpression(MemberExpression(VariableName,PropertyName),ArgList(String))),
DefaultLabel(default),
ReturnStatement(return,BooleanLiteral))))
# For
for (let x = 1; x < 10; x++) {}
for (const y of z) {}
for (var m in n) {}
for (q in r) {}
for (var a, b; c; d) continue;
for (i = 0, init(); i < 10; i++) {}
for (;;) {}
for (const {thing} in things) thing;
for await (let x of stream) {}
==>
Script(
ForStatement(for,ForSpec(VariableDeclaration(let,VariableDefinition,Equals,Number),
BinaryExpression(VariableName,CompareOp,Number),PostfixExpression(VariableName,ArithOp)),Block),
ForStatement(for,ForOfSpec(const,VariableDefinition,of,VariableName),Block),
ForStatement(for,ForInSpec(var,VariableDefinition,in,VariableName),Block),
ForStatement(for,ForInSpec(VariableName,in,VariableName),Block),
ForStatement(for,ForSpec(VariableDeclaration(var,VariableDefinition,VariableDefinition),VariableName,VariableName),ContinueStatement(continue)),
ForStatement(for,ForSpec(SequenceExpression(AssignmentExpression(VariableName,Equals,Number),
CallExpression(VariableName,ArgList)),BinaryExpression(VariableName,CompareOp,Number),PostfixExpression(VariableName,ArithOp)),Block),
ForStatement(for,ForSpec,Block),
ForStatement(for,ForInSpec(const,ObjectPattern(PatternProperty(PropertyName)),in,VariableName),ExpressionStatement(VariableName)),
ForStatement(for,await,ForOfSpec(let,VariableDefinition,of,VariableName),Block))
# Labeled statements
theLoop: for (;;) {
if (a) {
break theLoop;
}
}
==>
Script(LabeledStatement(Label,ForStatement(for,ForSpec,Block(
IfStatement(if,ParenthesizedExpression(VariableName),Block(BreakStatement(break,Label)))))))
# Classes
class Foo {
static one(a) { return a; };
two(b) { return b; }
finally() {}
}
class Foo extends require('another-class') {
constructor() { super(); }
bar() { super.a(); }
prop;
etc = 20;
static { f() }
}
==>
Script(
ClassDeclaration(class,VariableDefinition,ClassBody(
MethodDeclaration(static,PropertyDefinition,ParamList(VariableDefinition),Block(ReturnStatement(return,VariableName))),
MethodDeclaration(PropertyDefinition,ParamList(VariableDefinition),Block(ReturnStatement(return,VariableName))),
MethodDeclaration(PropertyDefinition,ParamList,Block))),
ClassDeclaration(class,VariableDefinition,extends,CallExpression(VariableName,ArgList(String)),ClassBody(
MethodDeclaration(PropertyDefinition,ParamList,Block(ExpressionStatement(CallExpression(super,ArgList)))),
MethodDeclaration(PropertyDefinition,ParamList,Block(ExpressionStatement(CallExpression(MemberExpression(super,PropertyName),ArgList)))),
PropertyDeclaration(PropertyDefinition),
PropertyDeclaration(PropertyDefinition,Equals,Number),
StaticBlock(static, Block(ExpressionStatement(CallExpression(VariableName,ArgList)))))))
# Private properties
class Foo {
#bar() { this.#a() + this?.#prop == #prop in this; }
#prop;
#etc = 20;
}
==>
Script(ClassDeclaration(class,VariableDefinition,ClassBody(
MethodDeclaration(PrivatePropertyDefinition,ParamList,Block(
ExpressionStatement(BinaryExpression(
BinaryExpression(
CallExpression(MemberExpression(this,PrivatePropertyName),ArgList),
ArithOp,
MemberExpression(this,PrivatePropertyName)),
CompareOp,
BinaryExpression(PrivatePropertyName, in, this))))),
PropertyDeclaration(PrivatePropertyDefinition),
PropertyDeclaration(PrivatePropertyDefinition,Equals,Number))))
# Computed properties
class Foo {
[x] = 44;
[Symbol.iterator]() {}
}
==>
Script(ClassDeclaration(class,VariableDefinition,ClassBody(
PropertyDeclaration(VariableName,Equals,Number),
MethodDeclaration(MemberExpression(VariableName,PropertyName),ParamList,Block))))
# Imports
import defaultMember from "module-name";
import * as name from "module-name";
import { member } from "module-name";
import { member1, member2 as alias2 } from "module-name";
import defaultMember, { member1, member2 as alias2, } from "module-name";
import "module-name";
==>
Script(
ImportDeclaration(import,VariableDefinition,from,String),
ImportDeclaration(import,Star,as,VariableDefinition,from,String),
ImportDeclaration(import,ImportGroup(VariableDefinition),from,String),
ImportDeclaration(import,ImportGroup(VariableDefinition,VariableName,as,VariableDefinition),from,String),
ImportDeclaration(import,VariableDefinition,ImportGroup(VariableDefinition,VariableName,as,VariableDefinition),from,String),
ImportDeclaration(import,String))
# Exports
export { name1, name2, name3 as x, nameN };
export let a, b = 2;
export default 2 + 2;
export default function() { }
export default async function name1() { }
export { name1 as default, } from "foo";
export * from 'foo';
==>
Script(
ExportDeclaration(export,ExportGroup(VariableName,VariableName,VariableName,as,VariableName,VariableName)),
ExportDeclaration(export,VariableDeclaration(let,VariableDefinition,VariableDefinition,Equals,Number)),
ExportDeclaration(export,default,BinaryExpression(Number,ArithOp,Number)),
ExportDeclaration(export,default,FunctionDeclaration(function,ParamList,Block)),
ExportDeclaration(export,default,FunctionDeclaration(async,function,VariableDefinition,ParamList,Block)),
ExportDeclaration(export,ExportGroup(VariableName,as,VariableName),from,String),
ExportDeclaration(export,Star,from,String))
# Empty statements
if (true) { ; };;;
==>
Script(IfStatement(if,ParenthesizedExpression(BooleanLiteral),Block))
# Comments
/* a */
one;
/* b **/
two;
/* c ***/
three;
/* d
***/
four;
y // comment
* z;
==>
Script(
BlockComment,
ExpressionStatement(VariableName),
BlockComment,
ExpressionStatement(VariableName),
BlockComment,
ExpressionStatement(VariableName),
BlockComment,
ExpressionStatement(VariableName),
ExpressionStatement(BinaryExpression(VariableName,LineComment,ArithOp,VariableName)))
# Recover from invalid char
const {foobar} = {};
==>
Script(VariableDeclaration(
const,
ObjectPattern("{",PatternProperty(PropertyName,⚠),"}"),
Equals,
ObjectExpression))
# Sync back to statement
function f() {
log(a b --c)
}
function g() {}
==>
Script(
FunctionDeclaration(function,VariableDefinition,ParamList,Block(ExpressionStatement(CallExpression(VariableName,ArgList(...))))),
FunctionDeclaration(function,VariableDefinition,ParamList,Block))
# Destructuring
({x} = y);
[u, v] = w;
let [a,, b = 0] = c;
let {x, y: z = 1} = d;
let {[f]: m} = e;
==>
Script(
ExpressionStatement(ParenthesizedExpression(AssignmentExpression(
ObjectPattern(PatternProperty(PropertyName)),Equals,VariableName))),
ExpressionStatement(AssignmentExpression(ArrayPattern(VariableDefinition,VariableDefinition),Equals,VariableName)),
VariableDeclaration(let,ArrayPattern(VariableDefinition,VariableDefinition,Equals,Number),Equals,VariableName),
VariableDeclaration(let,ObjectPattern(
PatternProperty(PropertyName),
PatternProperty(PropertyName,VariableDefinition,Equals,Number)
),Equals,VariableName),
VariableDeclaration(let,ObjectPattern(PatternProperty(VariableName,VariableDefinition)),Equals,VariableName))
# Generators
function* foo() { yield 1 }
class B {
*method() {}
}
({*x() {}})
==>
Script(
FunctionDeclaration(function,Star,VariableDefinition,ParamList,Block(
ExpressionStatement(YieldExpression(yield,Number)))),
ClassDeclaration(class,VariableDefinition,ClassBody(
MethodDeclaration(Star,PropertyDefinition,ParamList,Block))),
ExpressionStatement(ParenthesizedExpression(ObjectExpression(Property(Star,PropertyDefinition,ParamList,Block)))))

17
node_modules/@lezer/javascript/test/test-javascript.js generated vendored Normal file
View File

@ -0,0 +1,17 @@
import {parser} from "../dist/index.js"
import {fileTests} from "@lezer/generator/dist/test"
import * as fs from "fs"
import * as path from "path"
import {fileURLToPath} from "url"
let caseDir = path.dirname(fileURLToPath(import.meta.url))
for (let file of fs.readdirSync(caseDir)) {
if (!/\.txt$/.test(file)) continue
let name = /^[^\.]*/.exec(file)[0]
describe(name, () => {
for (let {name, run} of fileTests(fs.readFileSync(path.join(caseDir, file), "utf8"), file))
it(name, () => run(parser))
})
}

286
node_modules/@lezer/javascript/test/typescript.txt generated vendored Normal file
View File

@ -0,0 +1,286 @@
# Undefined and Null Type {"dialect": "ts"}
let x: undefined
let y: null
==>
Script(
VariableDeclaration(let,VariableDefinition,TypeAnnotation(
TypeName)),
VariableDeclaration(let,VariableDefinition,TypeAnnotation(
NullType(null))))
# Type declaration {"dialect": "ts"}
function foo(a: number, b: "literal" | Map<number, boolean>): RegExp[] {}
==>
Script(FunctionDeclaration(function, VariableDefinition, ParamList(
VariableDefinition, TypeAnnotation(TypeName),
VariableDefinition, TypeAnnotation(UnionType(LiteralType(String), LogicOp, ParameterizedType(TypeName, TypeArgList(TypeName, TypeName))))
), TypeAnnotation(ArrayType(TypeName)), Block))
# Type predicate {"dialect": "ts"}
function isFoo(foo: any): foo is Foo { return true }
==>
Script(FunctionDeclaration(function, VariableDefinition, ParamList(
VariableDefinition, TypeAnnotation(TypeName)
), TypePredicate(VariableName, is, TypeName), Block(ReturnStatement(return, BooleanLiteral))))
# Type alias {"dialect": "ts"}
type Foo<T extends string> = T[]
==>
Script(TypeAliasDeclaration(type, TypeDefinition, TypeParamList(TypeDefinition, extends, TypeName), Equals, ArrayType(TypeName)))
# Enum declaration {"dialect": "ts"}
const enum Type { Red = 1, Blue, Green }
==>
Script(EnumDeclaration(const, enum, TypeDefinition, EnumBody(PropertyName, Equals, Number, PropertyName, PropertyName)))
# Interface declaration {"dialect": "ts"}
interface Foo {
readonly a: number
b(arg: string): void
(call: number): boolean
new (): Foo
readonly [x: string]: number
}
==>
Script(InterfaceDeclaration(interface, TypeDefinition, ObjectType(
PropertyType(readonly, PropertyDefinition, TypeAnnotation(TypeName)),
MethodType(PropertyDefinition, ParamList(VariableDefinition, TypeAnnotation(TypeName)), TypeAnnotation(VoidType(void))),
CallSignature(ParamList(VariableDefinition, TypeAnnotation(TypeName)), TypeAnnotation(TypeName)),
NewSignature(new,ParamList, TypeAnnotation(TypeName)),
IndexSignature(readonly, PropertyDefinition, TypeAnnotation(TypeName), TypeAnnotation(TypeName)))))
# Call type args {"dialect": "ts"}
foo<number, string>() + new Bar<11>()
x < 10 > 5
==>
Script(
ExpressionStatement(BinaryExpression(
CallExpression(VariableName, TypeArgList(TypeName, TypeName), ArgList),
ArithOp,
NewExpression(new, VariableName, TypeArgList(LiteralType(Number)), ArgList))),
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName, CompareOp, Number), CompareOp, Number)))
# Advanced types {"dialect": "ts"}
let x: typeof X.x | keyof Y & Z["Foo"] | A<string>
let tuple: [a, b]
let f: (x: number) => boolean
==>
Script(
VariableDeclaration(let, VariableDefinition, TypeAnnotation(
UnionType(UnionType(TypeofType(typeof, MemberExpression(VariableName, PropertyName)), LogicOp,
IntersectionType(KeyofType(keyof, TypeName), LogicOp, IndexedType(TypeName, String))),
LogicOp, ParameterizedType(TypeName, TypeArgList(TypeName))))),
VariableDeclaration(let, VariableDefinition, TypeAnnotation(TupleType(TypeName, TypeName))),
VariableDeclaration(let, VariableDefinition, TypeAnnotation(FunctionSignature(
ParamList(VariableDefinition, TypeAnnotation(TypeName)), Arrow, TypeName))))
# Prefix cast {"dialect": "ts"}
<string>foo
==>
Script(ExpressionStatement(PrefixCast(TypeName, VariableName)))
# No prefix cast in JSX {"dialect": "ts jsx"}
<string>foo</string>
==>
Script(ExpressionStatement(JSXElement(
JSXOpenTag(JSXStartTag, JSXBuiltin(JSXIdentifier), JSXEndTag),
JSXText,
JSXCloseTag(JSXStartCloseTag, JSXBuiltin(JSXIdentifier), JSXEndTag))))
# Class definition {"dialect": "ts"}
class Foo<T> extends Bar<T> implements Stuff {
a: number
public readonly b: string = "two"
constructor(readonly x: boolean, public y: number, z: string) {}
private static blah(): void {}
}
==>
Script(ClassDeclaration(
class, VariableDefinition, TypeParamList(TypeDefinition),
extends, VariableName, TypeArgList(TypeName),
implements TypeName,
ClassBody(
PropertyDeclaration(PropertyDefinition, TypeAnnotation(TypeName)),
PropertyDeclaration(Privacy, readonly, PropertyDefinition, TypeAnnotation(TypeName), Equals, String),
MethodDeclaration(PropertyDefinition, ParamList(
readonly, VariableDefinition, TypeAnnotation(TypeName),
Privacy, VariableDefinition, TypeAnnotation(TypeName),
VariableDefinition, TypeAnnotation(TypeName)), Block),
MethodDeclaration(Privacy, static, PropertyDefinition, ParamList, TypeAnnotation(VoidType(void)), Block))))
# Arrow with type params {"dialect": "ts"}
let x = <T>(arg: T): T => arg
==>
Script(VariableDeclaration(let, VariableDefinition, Equals, ArrowFunction(
TypeParamList(TypeDefinition),
ParamList(VariableDefinition, TypeAnnotation(TypeName)),
TypeAnnotation(TypeName),
Arrow,
VariableName)))
# Template types {"dialect": "ts"}
type Tmpl<T> = `${string} ${5}` | `one ${Two}`
==>
Script(TypeAliasDeclaration(type, TypeDefinition, TypeParamList(TypeDefinition), Equals,
UnionType(TemplateType(Interpolation(InterpolationStart,TypeName,InterpolationEnd), Interpolation(InterpolationStart,LiteralType(Number),InterpolationEnd)), LogicOp, TemplateType(Interpolation(InterpolationStart,TypeName,InterpolationEnd)))))
# Extending complex types {"dialect": "ts"}
class Foo extends A.B<Param> {}
==>
Script(ClassDeclaration(class, VariableDefinition,
extends, MemberExpression(VariableName, PropertyName), TypeArgList(TypeName),
ClassBody))
# Object type {"dialect": "ts"}
type A = {a: number, b: number}
type B = {a: number; b: number;}
==>
Script(
TypeAliasDeclaration(type,TypeDefinition,Equals,ObjectType(
PropertyType(PropertyDefinition,TypeAnnotation(TypeName)),
PropertyType(PropertyDefinition,TypeAnnotation(TypeName)))),
TypeAliasDeclaration(type,TypeDefinition,Equals,ObjectType(
PropertyType(PropertyDefinition,TypeAnnotation(TypeName)),
PropertyType(PropertyDefinition,TypeAnnotation(TypeName)))))
# Conditional Type {"dialect": "ts"}
type X<T> = T extends E ? number : A
==>
Script(
TypeAliasDeclaration(type,TypeDefinition,TypeParamList(TypeDefinition),Equals,
ConditionalType(TypeName,extends,TypeName,LogicOp,TypeName,LogicOp,TypeName)))
# Generic Function Type {"dialect": "ts"}
let f: <T>() => T
==>
Script(
VariableDeclaration(let,VariableDefinition,TypeAnnotation(
FunctionSignature(TypeParamList(TypeDefinition),ParamList,Arrow,TypeName))))
# Satisfies operator {"dialect": "ts"}
let x = 1 satisfies number
==>
Script(VariableDeclaration(let,VariableDefinition,Equals,BinaryExpression(Number,satisfies,TypeName)))
# Override modifier on properties {"dialect": "ts"}
class A {
override accessor a;
static override b = 1;
override c = 2;
}
==>
Script(ClassDeclaration(class,VariableDefinition,ClassBody(
PropertyDeclaration(override,accessor,PropertyDefinition),
PropertyDeclaration(static,override,PropertyDefinition,Equals,Number),
PropertyDeclaration(override,PropertyDefinition,Equals,Number))))
# Class extending expression {"dialect": "ts"}
class X extends class {} {}
==>
Script(ClassDeclaration(class,VariableDefinition,extends,ClassExpression(class,ClassBody),ClassBody))
# Declare syntax {"dialect": "ts"}
declare namespace myLib {
function makeGreeting(s: string): string;
let numberOfGreetings: number;
}
declare function greet(setting: GreetingSettings): void;
declare class Greeter {
constructor(greeting: string);
greeting: string;
showGreeting(): void;
}
class X {
declare foo();
declare bar: number;
}
==>
Script(
AmbientDeclaration(declare,NamespaceDeclaration(namespace,VariableDefinition,Block(
FunctionDeclaration(function,VariableDefinition,ParamList(VariableDefinition,TypeAnnotation(TypeName)),
TypeAnnotation(TypeName)),
VariableDeclaration(let,VariableDefinition,TypeAnnotation(TypeName))))),
AmbientDeclaration(declare,AmbientFunctionDeclaration(function,VariableDefinition,
ParamList(VariableDefinition,TypeAnnotation(TypeName)),TypeAnnotation(VoidType(void)))),
AmbientDeclaration(declare,ClassDeclaration(class,VariableDefinition,ClassBody(
MethodDeclaration(PropertyDefinition,ParamList(VariableDefinition,TypeAnnotation(TypeName))),
PropertyDeclaration(PropertyDefinition,TypeAnnotation(TypeName)),
MethodDeclaration(PropertyDefinition,ParamList,TypeAnnotation(VoidType(void)))))),
ClassDeclaration(class,VariableDefinition,ClassBody(
MethodDeclaration(declare,PropertyDefinition,ParamList),
PropertyDeclaration(declare,PropertyDefinition,TypeAnnotation(TypeName)))))
# Declare this in a Function {"dialect": "ts"}
function foo(this: User) {}
==>
Script(FunctionDeclaration(function,VariableDefinition,ParamList(this,TypeAnnotation(TypeName)),Block))

21
node_modules/@lezer/lr/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (C) 2018 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

25
node_modules/@lezer/lr/README.md generated vendored Normal file
View File

@ -0,0 +1,25 @@
# @lezer/lr
[ [**WEBSITE**](http://lezer.codemirror.net) | [**ISSUES**](https://github.com/lezer-parser/lezer/issues) | [**FORUM**](https://discuss.codemirror.net/c/lezer) | [**CHANGELOG**](https://github.com/lezer-parser/lr/blob/master/CHANGELOG.md) ]
Lezer ("reader" in Dutch, pronounced pretty much as laser) is an
incremental GLR parser intended for use in an editor or similar
system, which needs to keep a representation of the program current
during changes and in the face of syntax errors.
It prioritizes speed and compactness (both of parser table files and
of syntax tree) over having a highly usable parse tree—trees nodes are
just blobs with a start, end, tag, and set of child nodes, with no
further labeling of child nodes or extra metadata.
This package contains the run-time LR parser library. It consumes
parsers generated by
[@lezer/generator](https://github.com/lezer-parser/generator).
The parser programming interface is documented on [the
website](https://lezer.codemirror.net/docs/ref/#lr).
The code is licensed under an MIT license.
This project was hugely inspired by
[tree-sitter](http://tree-sitter.github.io/tree-sitter/).

45
node_modules/@lezer/lr/dist/constants.d.ts generated vendored Normal file
View File

@ -0,0 +1,45 @@
export declare const enum Action {
ReduceFlag = 65536,
ValueMask = 65535,
ReduceDepthShift = 19,
RepeatFlag = 131072,
GotoFlag = 131072,
StayFlag = 262144
}
export declare const enum StateFlag {
Skipped = 1,
Accepting = 2
}
export declare const enum Specialize {
Specialize = 0,
Extend = 1
}
export declare const enum Term {
Err = 0
}
export declare const enum Seq {
End = 65535,
Done = 0,
Next = 1,
Other = 2
}
export declare const enum ParseState {
Flags = 0,
Actions = 1,
Skip = 2,
TokenizerMask = 3,
DefaultReduce = 4,
ForcedReduce = 5,
Size = 6
}
export declare const enum Encode {
BigValCode = 126,
BigVal = 65535,
Start = 32,
Gap1 = 34,
Gap2 = 92,
Base = 46
}
export declare const enum File {
Version = 14
}

5
node_modules/@lezer/lr/dist/decode.d.ts generated vendored Normal file
View File

@ -0,0 +1,5 @@
export declare function decodeArray<T extends {
[i: number]: number;
} = Uint16Array>(input: string | T, Type?: {
new (n: number): T;
}): T;

1740
node_modules/@lezer/lr/dist/index.cjs generated vendored Normal file

File diff suppressed because it is too large Load Diff

3
node_modules/@lezer/lr/dist/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,3 @@
export { LRParser, ParserConfig, ContextTracker } from "./parse";
export { InputStream, ExternalTokenizer, LocalTokenGroup } from "./token";
export { Stack } from "./stack";

1731
node_modules/@lezer/lr/dist/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

110
node_modules/@lezer/lr/dist/parse.d.ts generated vendored Normal file
View File

@ -0,0 +1,110 @@
import { Tree, TreeFragment, NodeSet, NodeType, NodePropSource, Input, PartialParse, Parser, ParseWrapper } from "@lezer/common";
import { Stack } from "./stack";
import { Tokenizer, ExternalTokenizer, CachedToken, InputStream } from "./token";
declare class FragmentCursor {
readonly fragments: readonly TreeFragment[];
readonly nodeSet: NodeSet;
i: number;
fragment: TreeFragment | null;
safeFrom: number;
safeTo: number;
trees: Tree[];
start: number[];
index: number[];
nextStart: number;
constructor(fragments: readonly TreeFragment[], nodeSet: NodeSet);
nextFragment(): void;
nodeAt(pos: number): Tree | null;
}
declare class TokenCache {
readonly stream: InputStream;
tokens: CachedToken[];
mainToken: CachedToken | null;
actions: number[];
constructor(parser: LRParser, stream: InputStream);
getActions(stack: Stack): number[];
getMainToken(stack: Stack): CachedToken;
updateCachedToken(token: CachedToken, tokenizer: Tokenizer, stack: Stack): void;
putAction(action: number, token: number, end: number, index: number): number;
addActions(stack: Stack, token: number, end: number, index: number): number;
}
export declare class Parse implements PartialParse {
readonly parser: LRParser;
readonly input: Input;
readonly ranges: readonly {
from: number;
to: number;
}[];
stacks: Stack[];
recovering: number;
fragments: FragmentCursor | null;
nextStackID: number;
minStackPos: number;
reused: Tree[];
stream: InputStream;
tokens: TokenCache;
topTerm: number;
stoppedAt: null | number;
lastBigReductionStart: number;
lastBigReductionSize: number;
bigReductionCount: number;
constructor(parser: LRParser, input: Input, fragments: readonly TreeFragment[], ranges: readonly {
from: number;
to: number;
}[]);
get parsedPos(): number;
advance(): Tree;
stopAt(pos: number): void;
private advanceStack;
private advanceFully;
private runRecovery;
stackToTree(stack: Stack): Tree;
private stackID;
}
export declare class Dialect {
readonly source: string | undefined;
readonly flags: readonly boolean[];
readonly disabled: null | Uint8Array;
constructor(source: string | undefined, flags: readonly boolean[], disabled: null | Uint8Array);
allows(term: number): boolean;
}
export declare class ContextTracker<T> {
constructor(spec: {
start: T;
shift?(context: T, term: number, stack: Stack, input: InputStream): T;
reduce?(context: T, term: number, stack: Stack, input: InputStream): T;
reuse?(context: T, node: Tree, stack: Stack, input: InputStream): T;
hash?(context: T): number;
strict?: boolean;
});
}
export interface ParserConfig {
props?: readonly NodePropSource[];
top?: string;
dialect?: string;
tokenizers?: {
from: ExternalTokenizer;
to: ExternalTokenizer;
}[];
specializers?: {
from: (value: string, stack: Stack) => number;
to: (value: string, stack: Stack) => number;
}[];
contextTracker?: ContextTracker<any>;
strict?: boolean;
wrap?: ParseWrapper;
bufferLength?: number;
}
export declare class LRParser extends Parser {
readonly nodeSet: NodeSet;
createParse(input: Input, fragments: readonly TreeFragment[], ranges: readonly {
from: number;
to: number;
}[]): PartialParse;
configure(config: ParserConfig): LRParser;
hasWrappers(): boolean;
getName(term: number): string;
get topNode(): NodeType;
static deserialize(spec: any): LRParser;
}
export {};

35
node_modules/@lezer/lr/dist/stack.d.ts generated vendored Normal file
View File

@ -0,0 +1,35 @@
import { BufferCursor } from "@lezer/common";
export declare class Stack {
pos: number;
get context(): any;
canShift(term: number): boolean;
get parser(): import("./parse").LRParser;
dialectEnabled(dialectID: number): boolean;
private shiftContext;
private reduceContext;
private updateContext;
}
export declare const enum Recover {
Insert = 200,
Delete = 190,
Reduce = 100,
MaxNext = 4,
MaxInsertStackDepth = 300,
DampenInsertStackDepth = 120,
MinBigReduction = 2000
}
export declare class StackBufferCursor implements BufferCursor {
stack: Stack;
pos: number;
index: number;
buffer: number[];
constructor(stack: Stack, pos: number, index: number);
static create(stack: Stack, pos?: number): StackBufferCursor;
maybeNext(): void;
get id(): number;
get start(): number;
get end(): number;
get size(): number;
next(): void;
fork(): StackBufferCursor;
}

45
node_modules/@lezer/lr/dist/token.d.ts generated vendored Normal file
View File

@ -0,0 +1,45 @@
import { Stack } from "./stack";
export declare class CachedToken {
start: number;
value: number;
end: number;
extended: number;
lookAhead: number;
mask: number;
context: number;
}
export declare class InputStream {
private chunk2;
private chunk2Pos;
next: number;
pos: number;
private rangeIndex;
private range;
peek(offset: number): any;
acceptToken(token: number, endOffset?: number): void;
private getChunk;
private readNext;
advance(n?: number): number;
private setDone;
}
export interface Tokenizer {
}
export declare class LocalTokenGroup implements Tokenizer {
readonly precTable: number;
readonly elseToken?: number;
contextual: boolean;
fallback: boolean;
extend: boolean;
readonly data: Readonly<Uint16Array>;
constructor(data: Readonly<Uint16Array> | string, precTable: number, elseToken?: number);
token(input: InputStream, stack: Stack): void;
}
interface ExternalOptions {
contextual?: boolean;
fallback?: boolean;
extend?: boolean;
}
export declare class ExternalTokenizer {
constructor(token: (input: InputStream, stack: Stack) => void, options?: ExternalOptions);
}
export {};

35
node_modules/@lezer/lr/package.json generated vendored Normal file
View File

@ -0,0 +1,35 @@
{
"name": "@lezer/lr",
"version": "1.3.9",
"description": "Incremental parser",
"main": "dist/index.cjs",
"type": "module",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"module": "dist/index.js",
"types": "dist/index.d.ts",
"author": "Marijn Haverbeke <marijn@haverbeke.berlin>",
"license": "MIT",
"repository": {
"type" : "git",
"url" : "https://github.com/lezer-parser/lr.git"
},
"devDependencies": {
"rollup": "^2.52.2",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"rollup-plugin-typescript2": "^0.34.1",
"typescript": "^4.3.4"
},
"dependencies": {
"@lezer/common": "^1.0.0"
},
"files": ["dist"],
"scripts": {
"test": "echo 'Tests are in @lezer/generator'",
"watch": "rollup -w -c rollup.config.js",
"prepare": "rollup -c rollup.config.js"
}
}