diff --git a/crates/codegen/runtime/npm/package/src/runtime/cst/index.mts b/crates/codegen/runtime/npm/package/src/runtime/cst/index.mts index a22005f1ce..4ad2bc383b 100644 --- a/crates/codegen/runtime/npm/package/src/runtime/cst/index.mts +++ b/crates/codegen/runtime/npm/package/src/runtime/cst/index.mts @@ -14,8 +14,8 @@ export type EdgeLabel = generated.cst.EdgeLabel; export type Node = generated.cst.Node; -export const NodeVariant = generated.cst.NodeVariant; -export type NodeVariant = generated.cst.NodeVariant; +export const NodeType = generated.cst.NodeType; +export type NodeType = generated.cst.NodeType; export const NonterminalNode = generated.cst.NonterminalNode; export type NonterminalNode = generated.cst.NonterminalNode; diff --git a/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts b/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts index 138e7f7f89..f73857b6a4 100644 --- a/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts +++ b/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts @@ -7,7 +7,6 @@ import type { Node } from "./nomic-foundation-slang-cst.js"; export { Node }; import type { NonterminalNode } from "./nomic-foundation-slang-cst.js"; export { NonterminalNode }; - export class Selectors { static sequence(node: NonterminalNode): (Node | undefined)[]; static choice(node: NonterminalNode): Node; diff --git a/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts b/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts index 8c5babbfdd..d851d5ca9d 100644 --- a/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts +++ b/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts @@ -13,7 +13,7 @@ export namespace NomicFoundationSlangCst { export { TerminalKind }; export { EdgeLabel }; export { Node }; - export { NodeVariant }; + export { NodeType }; } /** * Represents different kinds of nonterminal nodes in the syntax tree. @@ -90,7 +90,7 @@ export declare enum EdgeLabel { * The super type of all nodes in a tree. */ export type Node = NonterminalNode | TerminalNode; -export enum NodeVariant { +export enum NodeType { NonterminalNode = "NonterminalNode", TerminalNode = "TerminalNode", } @@ -181,6 +181,9 @@ export interface TextRange { end: TextIndex; } +/** + * Iterator over all ancestors of the current node, starting with the immediate parent, and moving upwards, ending with the root node. + */ export class AncestorsIterator { [Symbol.iterator](): Iterator; /** @@ -189,6 +192,9 @@ export class AncestorsIterator { next(): NonterminalNode | undefined; } +/** + * Provides navigation and traversal capabilities over the syntax tree. + */ export class Cursor { /** * Resets the cursor to its initial position. @@ -316,6 +322,9 @@ export class Cursor { query(queries: Query[]): QueryMatchIterator; } +/** + * Iterator over all the remaining nodes in the current tree, moving in pre-order traversal, until the tree is completed. + */ export class CursorIterator { [Symbol.iterator](): Iterator; /** @@ -324,13 +333,34 @@ export class CursorIterator { next(): Edge | undefined; } +/** + * Represents a non-terminal node in the syntax tree. + * These nodes can have child nodes and represent language constructs. + */ export class NonterminalNode { - readonly nodeVariant = NodeVariant.NonterminalNode; + /** + * The variant of `NodeType` that corresponds to this class. + */ + readonly type = NodeType.NonterminalNode; + /** + * Coerce this variant to a `NonterminalNode`, or `undefined` if this is not the correct type. + */ asNonterminalNode(): this; + + /** + * Return `true` if this object is an instance of `NonterminalNode`. + */ isNonterminalNode(): this is NonterminalNode; + /** + * Coerce this variant to a `TerminalNode`, or `undefined` if this is not the correct type. + */ asTerminalNode(): undefined; + + /** + * Return `true` if this object is an instance of `TerminalNode`. + */ isTerminalNode(): false; /** @@ -369,6 +399,9 @@ export class NonterminalNode { createCursor(textOffset: TextIndex): Cursor; } +/** + * Represents a tree query for pattern matching in the syntax tree. + */ export class Query { /** * Parses a query string into a query object. @@ -377,6 +410,9 @@ export class Query { static parse(text: string): Query; } +/** + * Iterator over query matches in the syntax tree. + */ export class QueryMatchIterator { [Symbol.iterator](): Iterator; /** @@ -385,6 +421,9 @@ export class QueryMatchIterator { next(): QueryMatch | undefined; } +/** + * Useful extension methods for working with terminals and terminal kinds. + */ export class TerminalKindExtensions { /** * Returns true if the terminal is a trivia token. i.e. whitespace, comments, etc... @@ -396,13 +435,34 @@ export class TerminalKindExtensions { static isValid(kind: TerminalKind): boolean; } +/** + * Represents a terminal node in the syntax tree. + * These are leaf nodes that represent actual tokens from the source code. + */ export class TerminalNode { - readonly nodeVariant = NodeVariant.TerminalNode; + /** + * The variant of `NodeType` that corresponds to this class. + */ + readonly type = NodeType.TerminalNode; + /** + * Coerce this variant to a `TerminalNode`, or `undefined` if this is not the correct type. + */ asTerminalNode(): this; + + /** + * Return `true` if this object is an instance of `TerminalNode`. + */ isTerminalNode(): this is TerminalNode; + /** + * Coerce this variant to a `NonterminalNode`, or `undefined` if this is not the correct type. + */ asNonterminalNode(): undefined; + + /** + * Return `true` if this object is an instance of `NonterminalNode`. + */ isNonterminalNode(): false; /** diff --git a/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts b/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts index 9d24311b88..bc99b8e132 100644 --- a/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts +++ b/crates/codegen/runtime/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts @@ -14,6 +14,9 @@ export { NonterminalKind }; import type { TextRange } from "./nomic-foundation-slang-cst.js"; export { TextRange }; +/** + * Contains information about where the error occurred and what went wrong. + */ export class ParseError { /** * Returns the text range where the error occurred in the source code. @@ -25,6 +28,10 @@ export class ParseError { get message(): string; } +/** + * The output of a parsing operation. + * Contains the resulting syntax tree and any errors encountered during parsing. + */ export class ParseOutput { /** * Returns the root node of the parsed syntax tree. @@ -48,6 +55,10 @@ export class ParseOutput { createTreeCursor(): Cursor; } +/** + * A parser instance that can parse source code into syntax trees. + * Each parser is configured for a specific language version and grammar. + */ export class Parser { /** * Returns the root nonterminal kind for this parser's grammar. diff --git a/crates/solidity/outputs/npm/package/src/generated/cst/index.mts b/crates/solidity/outputs/npm/package/src/generated/cst/index.mts index 39bc7cfd94..9ceb7c6f40 100644 --- a/crates/solidity/outputs/npm/package/src/generated/cst/index.mts +++ b/crates/solidity/outputs/npm/package/src/generated/cst/index.mts @@ -16,8 +16,8 @@ export type EdgeLabel = generated.cst.EdgeLabel; export type Node = generated.cst.Node; -export const NodeVariant = generated.cst.NodeVariant; -export type NodeVariant = generated.cst.NodeVariant; +export const NodeType = generated.cst.NodeType; +export type NodeType = generated.cst.NodeType; export const NonterminalNode = generated.cst.NonterminalNode; export type NonterminalNode = generated.cst.NonterminalNode; diff --git a/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts b/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts index 138e7f7f89..f73857b6a4 100644 --- a/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts +++ b/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts @@ -7,7 +7,6 @@ import type { Node } from "./nomic-foundation-slang-cst.js"; export { Node }; import type { NonterminalNode } from "./nomic-foundation-slang-cst.js"; export { NonterminalNode }; - export class Selectors { static sequence(node: NonterminalNode): (Node | undefined)[]; static choice(node: NonterminalNode): Node; diff --git a/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts b/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts index 9e1b37d948..1d8e203320 100644 --- a/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts +++ b/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts @@ -13,7 +13,7 @@ export namespace NomicFoundationSlangCst { export { TerminalKind }; export { EdgeLabel }; export { Node }; - export { NodeVariant }; + export { NodeType }; } /** * Represents different kinds of nonterminal nodes in the syntax tree. @@ -5964,7 +5964,7 @@ export declare enum EdgeLabel { * The super type of all nodes in a tree. */ export type Node = NonterminalNode | TerminalNode; -export enum NodeVariant { +export enum NodeType { NonterminalNode = "NonterminalNode", TerminalNode = "TerminalNode", } @@ -6055,6 +6055,9 @@ export interface TextRange { end: TextIndex; } +/** + * Iterator over all ancestors of the current node, starting with the immediate parent, and moving upwards, ending with the root node. + */ export class AncestorsIterator { [Symbol.iterator](): Iterator; /** @@ -6063,6 +6066,9 @@ export class AncestorsIterator { next(): NonterminalNode | undefined; } +/** + * Provides navigation and traversal capabilities over the syntax tree. + */ export class Cursor { /** * Resets the cursor to its initial position. @@ -6190,6 +6196,9 @@ export class Cursor { query(queries: Query[]): QueryMatchIterator; } +/** + * Iterator over all the remaining nodes in the current tree, moving in pre-order traversal, until the tree is completed. + */ export class CursorIterator { [Symbol.iterator](): Iterator; /** @@ -6198,13 +6207,34 @@ export class CursorIterator { next(): Edge | undefined; } +/** + * Represents a non-terminal node in the syntax tree. + * These nodes can have child nodes and represent language constructs. + */ export class NonterminalNode { - readonly nodeVariant = NodeVariant.NonterminalNode; + /** + * The variant of `NodeType` that corresponds to this class. + */ + readonly type = NodeType.NonterminalNode; + /** + * Coerce this variant to a `NonterminalNode`, or `undefined` if this is not the correct type. + */ asNonterminalNode(): this; + + /** + * Return `true` if this object is an instance of `NonterminalNode`. + */ isNonterminalNode(): this is NonterminalNode; + /** + * Coerce this variant to a `TerminalNode`, or `undefined` if this is not the correct type. + */ asTerminalNode(): undefined; + + /** + * Return `true` if this object is an instance of `TerminalNode`. + */ isTerminalNode(): false; /** @@ -6243,6 +6273,9 @@ export class NonterminalNode { createCursor(textOffset: TextIndex): Cursor; } +/** + * Represents a tree query for pattern matching in the syntax tree. + */ export class Query { /** * Parses a query string into a query object. @@ -6251,6 +6284,9 @@ export class Query { static parse(text: string): Query; } +/** + * Iterator over query matches in the syntax tree. + */ export class QueryMatchIterator { [Symbol.iterator](): Iterator; /** @@ -6259,6 +6295,9 @@ export class QueryMatchIterator { next(): QueryMatch | undefined; } +/** + * Useful extension methods for working with terminals and terminal kinds. + */ export class TerminalKindExtensions { /** * Returns true if the terminal is a trivia token. i.e. whitespace, comments, etc... @@ -6270,13 +6309,34 @@ export class TerminalKindExtensions { static isValid(kind: TerminalKind): boolean; } +/** + * Represents a terminal node in the syntax tree. + * These are leaf nodes that represent actual tokens from the source code. + */ export class TerminalNode { - readonly nodeVariant = NodeVariant.TerminalNode; + /** + * The variant of `NodeType` that corresponds to this class. + */ + readonly type = NodeType.TerminalNode; + /** + * Coerce this variant to a `TerminalNode`, or `undefined` if this is not the correct type. + */ asTerminalNode(): this; + + /** + * Return `true` if this object is an instance of `TerminalNode`. + */ isTerminalNode(): this is TerminalNode; + /** + * Coerce this variant to a `NonterminalNode`, or `undefined` if this is not the correct type. + */ asNonterminalNode(): undefined; + + /** + * Return `true` if this object is an instance of `NonterminalNode`. + */ isNonterminalNode(): false; /** diff --git a/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts b/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts index 9d24311b88..bc99b8e132 100644 --- a/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts +++ b/crates/solidity/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts @@ -14,6 +14,9 @@ export { NonterminalKind }; import type { TextRange } from "./nomic-foundation-slang-cst.js"; export { TextRange }; +/** + * Contains information about where the error occurred and what went wrong. + */ export class ParseError { /** * Returns the text range where the error occurred in the source code. @@ -25,6 +28,10 @@ export class ParseError { get message(): string; } +/** + * The output of a parsing operation. + * Contains the resulting syntax tree and any errors encountered during parsing. + */ export class ParseOutput { /** * Returns the root node of the parsed syntax tree. @@ -48,6 +55,10 @@ export class ParseOutput { createTreeCursor(): Cursor; } +/** + * A parser instance that can parse source code into syntax trees. + * Each parser is configured for a specific language version and grammar. + */ export class Parser { /** * Returns the root nonterminal kind for this parser's grammar. diff --git a/crates/testlang/outputs/npm/package/src/generated/cst/index.mts b/crates/testlang/outputs/npm/package/src/generated/cst/index.mts index 39bc7cfd94..9ceb7c6f40 100644 --- a/crates/testlang/outputs/npm/package/src/generated/cst/index.mts +++ b/crates/testlang/outputs/npm/package/src/generated/cst/index.mts @@ -16,8 +16,8 @@ export type EdgeLabel = generated.cst.EdgeLabel; export type Node = generated.cst.Node; -export const NodeVariant = generated.cst.NodeVariant; -export type NodeVariant = generated.cst.NodeVariant; +export const NodeType = generated.cst.NodeType; +export type NodeType = generated.cst.NodeType; export const NonterminalNode = generated.cst.NonterminalNode; export type NonterminalNode = generated.cst.NonterminalNode; diff --git a/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts b/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts index 138e7f7f89..f73857b6a4 100644 --- a/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts +++ b/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-ast.d.ts @@ -7,7 +7,6 @@ import type { Node } from "./nomic-foundation-slang-cst.js"; export { Node }; import type { NonterminalNode } from "./nomic-foundation-slang-cst.js"; export { NonterminalNode }; - export class Selectors { static sequence(node: NonterminalNode): (Node | undefined)[]; static choice(node: NonterminalNode): Node; diff --git a/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts b/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts index 45a4f18ed3..5e6d97a7dc 100644 --- a/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts +++ b/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-cst.d.ts @@ -13,7 +13,7 @@ export namespace NomicFoundationSlangCst { export { TerminalKind }; export { EdgeLabel }; export { Node }; - export { NodeVariant }; + export { NodeType }; } /** * Represents different kinds of nonterminal nodes in the syntax tree. @@ -302,7 +302,7 @@ export declare enum EdgeLabel { * The super type of all nodes in a tree. */ export type Node = NonterminalNode | TerminalNode; -export enum NodeVariant { +export enum NodeType { NonterminalNode = "NonterminalNode", TerminalNode = "TerminalNode", } @@ -393,6 +393,9 @@ export interface TextRange { end: TextIndex; } +/** + * Iterator over all ancestors of the current node, starting with the immediate parent, and moving upwards, ending with the root node. + */ export class AncestorsIterator { [Symbol.iterator](): Iterator; /** @@ -401,6 +404,9 @@ export class AncestorsIterator { next(): NonterminalNode | undefined; } +/** + * Provides navigation and traversal capabilities over the syntax tree. + */ export class Cursor { /** * Resets the cursor to its initial position. @@ -528,6 +534,9 @@ export class Cursor { query(queries: Query[]): QueryMatchIterator; } +/** + * Iterator over all the remaining nodes in the current tree, moving in pre-order traversal, until the tree is completed. + */ export class CursorIterator { [Symbol.iterator](): Iterator; /** @@ -536,13 +545,34 @@ export class CursorIterator { next(): Edge | undefined; } +/** + * Represents a non-terminal node in the syntax tree. + * These nodes can have child nodes and represent language constructs. + */ export class NonterminalNode { - readonly nodeVariant = NodeVariant.NonterminalNode; + /** + * The variant of `NodeType` that corresponds to this class. + */ + readonly type = NodeType.NonterminalNode; + /** + * Coerce this variant to a `NonterminalNode`, or `undefined` if this is not the correct type. + */ asNonterminalNode(): this; + + /** + * Return `true` if this object is an instance of `NonterminalNode`. + */ isNonterminalNode(): this is NonterminalNode; + /** + * Coerce this variant to a `TerminalNode`, or `undefined` if this is not the correct type. + */ asTerminalNode(): undefined; + + /** + * Return `true` if this object is an instance of `TerminalNode`. + */ isTerminalNode(): false; /** @@ -581,6 +611,9 @@ export class NonterminalNode { createCursor(textOffset: TextIndex): Cursor; } +/** + * Represents a tree query for pattern matching in the syntax tree. + */ export class Query { /** * Parses a query string into a query object. @@ -589,6 +622,9 @@ export class Query { static parse(text: string): Query; } +/** + * Iterator over query matches in the syntax tree. + */ export class QueryMatchIterator { [Symbol.iterator](): Iterator; /** @@ -597,6 +633,9 @@ export class QueryMatchIterator { next(): QueryMatch | undefined; } +/** + * Useful extension methods for working with terminals and terminal kinds. + */ export class TerminalKindExtensions { /** * Returns true if the terminal is a trivia token. i.e. whitespace, comments, etc... @@ -608,13 +647,34 @@ export class TerminalKindExtensions { static isValid(kind: TerminalKind): boolean; } +/** + * Represents a terminal node in the syntax tree. + * These are leaf nodes that represent actual tokens from the source code. + */ export class TerminalNode { - readonly nodeVariant = NodeVariant.TerminalNode; + /** + * The variant of `NodeType` that corresponds to this class. + */ + readonly type = NodeType.TerminalNode; + /** + * Coerce this variant to a `TerminalNode`, or `undefined` if this is not the correct type. + */ asTerminalNode(): this; + + /** + * Return `true` if this object is an instance of `TerminalNode`. + */ isTerminalNode(): this is TerminalNode; + /** + * Coerce this variant to a `NonterminalNode`, or `undefined` if this is not the correct type. + */ asNonterminalNode(): undefined; + + /** + * Return `true` if this object is an instance of `NonterminalNode`. + */ isNonterminalNode(): false; /** diff --git a/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts b/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts index 9d24311b88..bc99b8e132 100644 --- a/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts +++ b/crates/testlang/outputs/npm/package/wasm/generated/interfaces/nomic-foundation-slang-parser.d.ts @@ -14,6 +14,9 @@ export { NonterminalKind }; import type { TextRange } from "./nomic-foundation-slang-cst.js"; export { TextRange }; +/** + * Contains information about where the error occurred and what went wrong. + */ export class ParseError { /** * Returns the text range where the error occurred in the source code. @@ -25,6 +28,10 @@ export class ParseError { get message(): string; } +/** + * The output of a parsing operation. + * Contains the resulting syntax tree and any errors encountered during parsing. + */ export class ParseOutput { /** * Returns the root node of the parsed syntax tree. @@ -48,6 +55,10 @@ export class ParseOutput { createTreeCursor(): Cursor; } +/** + * A parser instance that can parse source code into syntax trees. + * Each parser is configured for a specific language version and grammar. + */ export class Parser { /** * Returns the root nonterminal kind for this parser's grammar. diff --git a/crates/testlang/outputs/npm/tests/src/cst/cursor.test.mts b/crates/testlang/outputs/npm/tests/src/cst/cursor.test.mts index 2a69cfb088..a719094355 100644 --- a/crates/testlang/outputs/npm/tests/src/cst/cursor.test.mts +++ b/crates/testlang/outputs/npm/tests/src/cst/cursor.test.mts @@ -2,7 +2,7 @@ import { Parser } from "@slang-private/testlang-npm-package/parser"; import { Cursor, EdgeLabel, - NodeVariant, + NodeType, assertIsNonterminalNode, assertIsTerminalNode, NonterminalKind, @@ -112,10 +112,7 @@ test("access the node using its name", () => { const node = innerCursor.node; const label = innerCursor.label; - if ( - node.nodeVariant == NodeVariant.TerminalNode && - (label == EdgeLabel.OpenBracket || label == EdgeLabel.CloseBracket) - ) { + if (node.type == NodeType.TerminalNode && (label == EdgeLabel.OpenBracket || label == EdgeLabel.CloseBracket)) { names.push(node.unparse()); } } diff --git a/submodules/jco b/submodules/jco index 51b184c43b..0e0a0b2cfc 160000 --- a/submodules/jco +++ b/submodules/jco @@ -1 +1 @@ -Subproject commit 51b184c43b35ad350989a55e4a8983ebf4861088 +Subproject commit 0e0a0b2cfc01ecfa65ef86becfff58de2ce4535f