Initial commit with Advoware proxy

This commit is contained in:
root
2025-10-19 14:57:07 +00:00
commit 273aa8b549
45771 changed files with 5534555 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
/**
* A chunk is either a token tag, a rule tag, or a span of literal text within a
* tree pattern.
*
* The method {@link ParseTreePatternMatcher#split(String)} returns a list of
* chunks in preparation for creating a token stream by
* {@link ParseTreePatternMatcher#tokenize(String)}. From there, we get a parse
* tree from with {@link ParseTreePatternMatcher#compile(String, int)}. These
* chunks are converted to {@link RuleTagToken}, {@link TokenTagToken}, or the
* regular tokens of the text surrounding the tags.
*/
export declare abstract class Chunk {
}

View File

@@ -0,0 +1,23 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Chunk = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:45.2799060-07:00
/**
* A chunk is either a token tag, a rule tag, or a span of literal text within a
* tree pattern.
*
* The method {@link ParseTreePatternMatcher#split(String)} returns a list of
* chunks in preparation for creating a token stream by
* {@link ParseTreePatternMatcher#tokenize(String)}. From there, we get a parse
* tree from with {@link ParseTreePatternMatcher#compile(String, int)}. These
* chunks are converted to {@link RuleTagToken}, {@link TokenTagToken}, or the
* regular tokens of the text surrounding the tags.
*/
class Chunk {
}
exports.Chunk = Chunk;
//# sourceMappingURL=Chunk.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Chunk.js","sourceRoot":"","sources":["../../../../src/tree/pattern/Chunk.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,wDAAwD;AAExD;;;;;;;;;;GAUG;AACH,MAAsB,KAAK;CAC1B;AADD,sBACC","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-04T11:26:45.2799060-07:00\r\n\r\n/**\r\n * A chunk is either a token tag, a rule tag, or a span of literal text within a\r\n * tree pattern.\r\n *\r\n * The method {@link ParseTreePatternMatcher#split(String)} returns a list of\r\n * chunks in preparation for creating a token stream by\r\n * {@link ParseTreePatternMatcher#tokenize(String)}. From there, we get a parse\r\n * tree from with {@link ParseTreePatternMatcher#compile(String, int)}. These\r\n * chunks are converted to {@link RuleTagToken}, {@link TokenTagToken}, or the\r\n * regular tokens of the text surrounding the tags.\r\n */\r\nexport abstract class Chunk {\r\n}\r\n"]}

View File

@@ -0,0 +1,124 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { MultiMap } from "../../misc/MultiMap";
import { ParseTree } from "../ParseTree";
import { ParseTreePattern } from "./ParseTreePattern";
/**
* Represents the result of matching a {@link ParseTree} against a tree pattern.
*/
export declare class ParseTreeMatch {
/**
* This is the backing field for `tree`.
*/
private _tree;
/**
* This is the backing field for `pattern`.
*/
private _pattern;
/**
* This is the backing field for `labels`.
*/
private _labels;
/**
* This is the backing field for `mismatchedNode`.
*/
private _mismatchedNode?;
/**
* Constructs a new instance of {@link ParseTreeMatch} from the specified
* parse tree and pattern.
*
* @param tree The parse tree to match against the pattern.
* @param pattern The parse tree pattern.
* @param labels A mapping from label names to collections of
* {@link ParseTree} objects located by the tree pattern matching process.
* @param mismatchedNode The first node which failed to match the tree
* pattern during the matching process.
*
* @throws {@link Error} if `tree` is not defined
* @throws {@link Error} if `pattern` is not defined
* @throws {@link Error} if `labels` is not defined
*/
constructor(tree: ParseTree, pattern: ParseTreePattern, labels: MultiMap<string, ParseTree>, mismatchedNode: ParseTree | undefined);
/**
* Get the last node associated with a specific `label`.
*
* For example, for pattern `<id:ID>`, `get("id")` returns the
* node matched for that `ID`. If more than one node
* matched the specified label, only the last is returned. If there is
* no node associated with the label, this returns `undefined`.
*
* Pattern tags like `<ID>` and `<expr>` without labels are
* considered to be labeled with `ID` and `expr`, respectively.
*
* @param label The label to check.
*
* @returns The last {@link ParseTree} to match a tag with the specified
* label, or `undefined` if no parse tree matched a tag with the label.
*/
get(label: string): ParseTree | undefined;
/**
* Return all nodes matching a rule or token tag with the specified label.
*
* If the `label` is the name of a parser rule or token in the
* grammar, the resulting list will contain both the parse trees matching
* rule or tags explicitly labeled with the label and the complete set of
* parse trees matching the labeled and unlabeled tags in the pattern for
* the parser rule or token. For example, if `label` is `"foo"`,
* the result will contain *all* of the following.
*
* * Parse tree nodes matching tags of the form `<foo:anyRuleName>` and
* `<foo:AnyTokenName>`.
* * Parse tree nodes matching tags of the form `<anyLabel:foo>`.
* * Parse tree nodes matching tags of the form `<foo>`.
*
* @param label The label.
*
* @returns A collection of all {@link ParseTree} nodes matching tags with
* the specified `label`. If no nodes matched the label, an empty list
* is returned.
*/
getAll(label: string): ParseTree[];
/**
* Return a mapping from label &rarr; [list of nodes].
*
* The map includes special entries corresponding to the names of rules and
* tokens referenced in tags in the original pattern. For additional
* information, see the description of {@link #getAll(String)}.
*
* @returns A mapping from labels to parse tree nodes. If the parse tree
* pattern did not contain any rule or token tags, this map will be empty.
*/
get labels(): MultiMap<string, ParseTree>;
/**
* Get the node at which we first detected a mismatch.
*
* @returns the node at which we first detected a mismatch, or `undefined`
* if the match was successful.
*/
get mismatchedNode(): ParseTree | undefined;
/**
* Gets a value indicating whether the match operation succeeded.
*
* @returns `true` if the match operation succeeded; otherwise,
* `false`.
*/
get succeeded(): boolean;
/**
* Get the tree pattern we are matching against.
*
* @returns The tree pattern we are matching against.
*/
get pattern(): ParseTreePattern;
/**
* Get the parse tree we are trying to match to a pattern.
*
* @returns The {@link ParseTree} we are trying to match to a pattern.
*/
get tree(): ParseTree;
/**
* {@inheritDoc}
*/
toString(): string;
}

View File

@@ -0,0 +1,179 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParseTreeMatch = void 0;
const Decorators_1 = require("../../Decorators");
/**
* Represents the result of matching a {@link ParseTree} against a tree pattern.
*/
let ParseTreeMatch = class ParseTreeMatch {
/**
* Constructs a new instance of {@link ParseTreeMatch} from the specified
* parse tree and pattern.
*
* @param tree The parse tree to match against the pattern.
* @param pattern The parse tree pattern.
* @param labels A mapping from label names to collections of
* {@link ParseTree} objects located by the tree pattern matching process.
* @param mismatchedNode The first node which failed to match the tree
* pattern during the matching process.
*
* @throws {@link Error} if `tree` is not defined
* @throws {@link Error} if `pattern` is not defined
* @throws {@link Error} if `labels` is not defined
*/
constructor(tree, pattern, labels, mismatchedNode) {
if (!tree) {
throw new Error("tree cannot be null");
}
if (!pattern) {
throw new Error("pattern cannot be null");
}
if (!labels) {
throw new Error("labels cannot be null");
}
this._tree = tree;
this._pattern = pattern;
this._labels = labels;
this._mismatchedNode = mismatchedNode;
}
/**
* Get the last node associated with a specific `label`.
*
* For example, for pattern `<id:ID>`, `get("id")` returns the
* node matched for that `ID`. If more than one node
* matched the specified label, only the last is returned. If there is
* no node associated with the label, this returns `undefined`.
*
* Pattern tags like `<ID>` and `<expr>` without labels are
* considered to be labeled with `ID` and `expr`, respectively.
*
* @param label The label to check.
*
* @returns The last {@link ParseTree} to match a tag with the specified
* label, or `undefined` if no parse tree matched a tag with the label.
*/
get(label) {
let parseTrees = this._labels.get(label);
if (!parseTrees || parseTrees.length === 0) {
return undefined;
}
return parseTrees[parseTrees.length - 1]; // return last if multiple
}
/**
* Return all nodes matching a rule or token tag with the specified label.
*
* If the `label` is the name of a parser rule or token in the
* grammar, the resulting list will contain both the parse trees matching
* rule or tags explicitly labeled with the label and the complete set of
* parse trees matching the labeled and unlabeled tags in the pattern for
* the parser rule or token. For example, if `label` is `"foo"`,
* the result will contain *all* of the following.
*
* * Parse tree nodes matching tags of the form `<foo:anyRuleName>` and
* `<foo:AnyTokenName>`.
* * Parse tree nodes matching tags of the form `<anyLabel:foo>`.
* * Parse tree nodes matching tags of the form `<foo>`.
*
* @param label The label.
*
* @returns A collection of all {@link ParseTree} nodes matching tags with
* the specified `label`. If no nodes matched the label, an empty list
* is returned.
*/
getAll(label) {
const nodes = this._labels.get(label);
if (!nodes) {
return [];
}
return nodes;
}
/**
* Return a mapping from label &rarr; [list of nodes].
*
* The map includes special entries corresponding to the names of rules and
* tokens referenced in tags in the original pattern. For additional
* information, see the description of {@link #getAll(String)}.
*
* @returns A mapping from labels to parse tree nodes. If the parse tree
* pattern did not contain any rule or token tags, this map will be empty.
*/
get labels() {
return this._labels;
}
/**
* Get the node at which we first detected a mismatch.
*
* @returns the node at which we first detected a mismatch, or `undefined`
* if the match was successful.
*/
get mismatchedNode() {
return this._mismatchedNode;
}
/**
* Gets a value indicating whether the match operation succeeded.
*
* @returns `true` if the match operation succeeded; otherwise,
* `false`.
*/
get succeeded() {
return !this._mismatchedNode;
}
/**
* Get the tree pattern we are matching against.
*
* @returns The tree pattern we are matching against.
*/
get pattern() {
return this._pattern;
}
/**
* Get the parse tree we are trying to match to a pattern.
*
* @returns The {@link ParseTree} we are trying to match to a pattern.
*/
get tree() {
return this._tree;
}
/**
* {@inheritDoc}
*/
toString() {
return `Match ${this.succeeded ? "succeeded" : "failed"}; found ${this.labels.size} labels`;
}
};
__decorate([
Decorators_1.NotNull,
__param(0, Decorators_1.NotNull)
], ParseTreeMatch.prototype, "getAll", null);
__decorate([
Decorators_1.NotNull
], ParseTreeMatch.prototype, "labels", null);
__decorate([
Decorators_1.NotNull
], ParseTreeMatch.prototype, "pattern", null);
__decorate([
Decorators_1.NotNull
], ParseTreeMatch.prototype, "tree", null);
__decorate([
Decorators_1.Override
], ParseTreeMatch.prototype, "toString", null);
ParseTreeMatch = __decorate([
__param(0, Decorators_1.NotNull),
__param(1, Decorators_1.NotNull),
__param(2, Decorators_1.NotNull)
], ParseTreeMatch);
exports.ParseTreeMatch = ParseTreeMatch;
//# sourceMappingURL=ParseTreeMatch.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,98 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { ParseTree } from "../ParseTree";
import { ParseTreeMatch } from "./ParseTreeMatch";
import { ParseTreePatternMatcher } from "./ParseTreePatternMatcher";
/**
* A pattern like `<ID> = <expr>;` converted to a {@link ParseTree} by
* {@link ParseTreePatternMatcher#compile(String, int)}.
*/
export declare class ParseTreePattern {
/**
* This is the backing field for `patternRuleIndex`.
*/
private _patternRuleIndex;
/**
* This is the backing field for `pattern`.
*/
private _pattern;
/**
* This is the backing field for `patternTree`.
*/
private _patternTree;
/**
* This is the backing field for `matcher`.
*/
private _matcher;
/**
* Construct a new instance of the {@link ParseTreePattern} class.
*
* @param matcher The {@link ParseTreePatternMatcher} which created this
* tree pattern.
* @param pattern The tree pattern in concrete syntax form.
* @param patternRuleIndex The parser rule which serves as the root of the
* tree pattern.
* @param patternTree The tree pattern in {@link ParseTree} form.
*/
constructor(matcher: ParseTreePatternMatcher, pattern: string, patternRuleIndex: number, patternTree: ParseTree);
/**
* Match a specific parse tree against this tree pattern.
*
* @param tree The parse tree to match against this tree pattern.
* @returns A {@link ParseTreeMatch} object describing the result of the
* match operation. The `ParseTreeMatch.succeeded` method can be
* used to determine whether or not the match was successful.
*/
match(tree: ParseTree): ParseTreeMatch;
/**
* Determine whether or not a parse tree matches this tree pattern.
*
* @param tree The parse tree to match against this tree pattern.
* @returns `true` if `tree` is a match for the current tree
* pattern; otherwise, `false`.
*/
matches(tree: ParseTree): boolean;
/**
* Find all nodes using XPath and then try to match those subtrees against
* this tree pattern.
*
* @param tree The {@link ParseTree} to match against this pattern.
* @param xpath An expression matching the nodes
*
* @returns A collection of {@link ParseTreeMatch} objects describing the
* successful matches. Unsuccessful matches are omitted from the result,
* regardless of the reason for the failure.
*/
findAll(tree: ParseTree, xpath: string): ParseTreeMatch[];
/**
* Get the {@link ParseTreePatternMatcher} which created this tree pattern.
*
* @returns The {@link ParseTreePatternMatcher} which created this tree
* pattern.
*/
get matcher(): ParseTreePatternMatcher;
/**
* Get the tree pattern in concrete syntax form.
*
* @returns The tree pattern in concrete syntax form.
*/
get pattern(): string;
/**
* Get the parser rule which serves as the outermost rule for the tree
* pattern.
*
* @returns The parser rule which serves as the outermost rule for the tree
* pattern.
*/
get patternRuleIndex(): number;
/**
* Get the tree pattern as a {@link ParseTree}. The rule and token tags from
* the pattern are present in the parse tree as terminal nodes with a symbol
* of type {@link RuleTagToken} or {@link TokenTagToken}.
*
* @returns The tree pattern as a {@link ParseTree}.
*/
get patternTree(): ParseTree;
}

View File

@@ -0,0 +1,157 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParseTreePattern = void 0;
// CONVERSTION complete, Burt Harris 10/14/2016
const Decorators_1 = require("../../Decorators");
const XPath_1 = require("../xpath/XPath");
/**
* A pattern like `<ID> = <expr>;` converted to a {@link ParseTree} by
* {@link ParseTreePatternMatcher#compile(String, int)}.
*/
let ParseTreePattern = class ParseTreePattern {
/**
* Construct a new instance of the {@link ParseTreePattern} class.
*
* @param matcher The {@link ParseTreePatternMatcher} which created this
* tree pattern.
* @param pattern The tree pattern in concrete syntax form.
* @param patternRuleIndex The parser rule which serves as the root of the
* tree pattern.
* @param patternTree The tree pattern in {@link ParseTree} form.
*/
constructor(matcher, pattern, patternRuleIndex, patternTree) {
this._matcher = matcher;
this._patternRuleIndex = patternRuleIndex;
this._pattern = pattern;
this._patternTree = patternTree;
}
/**
* Match a specific parse tree against this tree pattern.
*
* @param tree The parse tree to match against this tree pattern.
* @returns A {@link ParseTreeMatch} object describing the result of the
* match operation. The `ParseTreeMatch.succeeded` method can be
* used to determine whether or not the match was successful.
*/
match(tree) {
return this._matcher.match(tree, this);
}
/**
* Determine whether or not a parse tree matches this tree pattern.
*
* @param tree The parse tree to match against this tree pattern.
* @returns `true` if `tree` is a match for the current tree
* pattern; otherwise, `false`.
*/
matches(tree) {
return this._matcher.match(tree, this).succeeded;
}
/**
* Find all nodes using XPath and then try to match those subtrees against
* this tree pattern.
*
* @param tree The {@link ParseTree} to match against this pattern.
* @param xpath An expression matching the nodes
*
* @returns A collection of {@link ParseTreeMatch} objects describing the
* successful matches. Unsuccessful matches are omitted from the result,
* regardless of the reason for the failure.
*/
findAll(tree, xpath) {
let subtrees = XPath_1.XPath.findAll(tree, xpath, this._matcher.parser);
let matches = [];
for (let t of subtrees) {
let match = this.match(t);
if (match.succeeded) {
matches.push(match);
}
}
return matches;
}
/**
* Get the {@link ParseTreePatternMatcher} which created this tree pattern.
*
* @returns The {@link ParseTreePatternMatcher} which created this tree
* pattern.
*/
get matcher() {
return this._matcher;
}
/**
* Get the tree pattern in concrete syntax form.
*
* @returns The tree pattern in concrete syntax form.
*/
get pattern() {
return this._pattern;
}
/**
* Get the parser rule which serves as the outermost rule for the tree
* pattern.
*
* @returns The parser rule which serves as the outermost rule for the tree
* pattern.
*/
get patternRuleIndex() {
return this._patternRuleIndex;
}
/**
* Get the tree pattern as a {@link ParseTree}. The rule and token tags from
* the pattern are present in the parse tree as terminal nodes with a symbol
* of type {@link RuleTagToken} or {@link TokenTagToken}.
*
* @returns The tree pattern as a {@link ParseTree}.
*/
get patternTree() {
return this._patternTree;
}
};
__decorate([
Decorators_1.NotNull
], ParseTreePattern.prototype, "_pattern", void 0);
__decorate([
Decorators_1.NotNull
], ParseTreePattern.prototype, "_patternTree", void 0);
__decorate([
Decorators_1.NotNull
], ParseTreePattern.prototype, "_matcher", void 0);
__decorate([
Decorators_1.NotNull,
__param(0, Decorators_1.NotNull)
], ParseTreePattern.prototype, "match", null);
__decorate([
__param(0, Decorators_1.NotNull)
], ParseTreePattern.prototype, "matches", null);
__decorate([
Decorators_1.NotNull,
__param(0, Decorators_1.NotNull), __param(1, Decorators_1.NotNull)
], ParseTreePattern.prototype, "findAll", null);
__decorate([
Decorators_1.NotNull
], ParseTreePattern.prototype, "matcher", null);
__decorate([
Decorators_1.NotNull
], ParseTreePattern.prototype, "pattern", null);
__decorate([
Decorators_1.NotNull
], ParseTreePattern.prototype, "patternTree", null);
ParseTreePattern = __decorate([
__param(0, Decorators_1.NotNull),
__param(1, Decorators_1.NotNull),
__param(3, Decorators_1.NotNull)
], ParseTreePattern);
exports.ParseTreePattern = ParseTreePattern;
//# sourceMappingURL=ParseTreePattern.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,166 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { Chunk } from "./Chunk";
import { Lexer } from "../../Lexer";
import { MultiMap } from "../../misc/MultiMap";
import { Parser } from "../../Parser";
import { ParseTree } from "../ParseTree";
import { ParseTreeMatch } from "./ParseTreeMatch";
import { ParseTreePattern } from "./ParseTreePattern";
import { RuleTagToken } from "./RuleTagToken";
import { Token } from "../../Token";
/**
* A tree pattern matching mechanism for ANTLR {@link ParseTree}s.
*
* Patterns are strings of source input text with special tags representing
* token or rule references such as:
*
* ```
* <ID> = <expr>;
* ```
*
* Given a pattern start rule such as `statement`, this object constructs
* a {@link ParseTree} with placeholders for the `ID` and `expr`
* subtree. Then the {@link #match} routines can compare an actual
* {@link ParseTree} from a parse with this pattern. Tag `<ID>` matches
* any `ID` token and tag `<expr>` references the result of the
* `expr` rule (generally an instance of `ExprContext`.
*
* Pattern `x = 0;` is a similar pattern that matches the same pattern
* except that it requires the identifier to be `x` and the expression to
* be `0`.
*
* The {@link #matches} routines return `true` or `false` based
* upon a match for the tree rooted at the parameter sent in. The
* {@link #match} routines return a {@link ParseTreeMatch} object that
* contains the parse tree, the parse tree pattern, and a map from tag name to
* matched nodes (more below). A subtree that fails to match, returns with
* {@link ParseTreeMatch#mismatchedNode} set to the first tree node that did not
* match.
*
* For efficiency, you can compile a tree pattern in string form to a
* {@link ParseTreePattern} object.
*
* See `TestParseTreeMatcher` for lots of examples.
* {@link ParseTreePattern} has two static helper methods:
* {@link ParseTreePattern#findAll} and {@link ParseTreePattern#match} that
* are easy to use but not super efficient because they create new
* {@link ParseTreePatternMatcher} objects each time and have to compile the
* pattern in string form before using it.
*
* The lexer and parser that you pass into the {@link ParseTreePatternMatcher}
* constructor are used to parse the pattern in string form. The lexer converts
* the `<ID> = <expr>;` into a sequence of four tokens (assuming lexer
* throws out whitespace or puts it on a hidden channel). Be aware that the
* input stream is reset for the lexer (but not the parser; a
* {@link ParserInterpreter} is created to parse the input.). Any user-defined
* fields you have put into the lexer might get changed when this mechanism asks
* it to scan the pattern string.
*
* Normally a parser does not accept token `<expr>` as a valid
* `expr` but, from the parser passed in, we create a special version of
* the underlying grammar representation (an {@link ATN}) that allows imaginary
* tokens representing rules (`<expr>`) to match entire rules. We call
* these *bypass alternatives*.
*
* Delimiters are `<`} and `>`}, with `\` as the escape string
* by default, but you can set them to whatever you want using
* {@link #setDelimiters}. You must escape both start and stop strings
* `\<` and `\>`.
*/
export declare class ParseTreePatternMatcher {
/**
* This is the backing field for `lexer`.
*/
private _lexer;
/**
* This is the backing field for `parser`.
*/
private _parser;
protected start: string;
protected stop: string;
protected escape: string;
/**
* Regular expression corresponding to escape, for global replace
*/
protected escapeRE: RegExp;
/**
* Constructs a {@link ParseTreePatternMatcher} or from a {@link Lexer} and
* {@link Parser} object. The lexer input stream is altered for tokenizing
* the tree patterns. The parser is used as a convenient mechanism to get
* the grammar name, plus token, rule names.
*/
constructor(lexer: Lexer, parser: Parser);
/**
* Set the delimiters used for marking rule and token tags within concrete
* syntax used by the tree pattern parser.
*
* @param start The start delimiter.
* @param stop The stop delimiter.
* @param escapeLeft The escape sequence to use for escaping a start or stop delimiter.
*
* @throws {@link Error} if `start` is not defined or empty.
* @throws {@link Error} if `stop` is not defined or empty.
*/
setDelimiters(start: string, stop: string, escapeLeft: string): void;
/** Does `pattern` matched as rule `patternRuleIndex` match `tree`? */
matches(tree: ParseTree, pattern: string, patternRuleIndex: number): boolean;
/** Does `pattern` matched as rule patternRuleIndex match tree? Pass in a
* compiled pattern instead of a string representation of a tree pattern.
*/
matches(tree: ParseTree, pattern: ParseTreePattern): boolean;
/**
* Compare `pattern` matched as rule `patternRuleIndex` against
* `tree` and return a {@link ParseTreeMatch} object that contains the
* matched elements, or the node at which the match failed.
*/
match(tree: ParseTree, pattern: string, patternRuleIndex: number): ParseTreeMatch;
/**
* Compare `pattern` matched against `tree` and return a
* {@link ParseTreeMatch} object that contains the matched elements, or the
* node at which the match failed. Pass in a compiled pattern instead of a
* string representation of a tree pattern.
*/
match(tree: ParseTree, pattern: ParseTreePattern): ParseTreeMatch;
/**
* For repeated use of a tree pattern, compile it to a
* {@link ParseTreePattern} using this method.
*/
compile(pattern: string, patternRuleIndex: number): ParseTreePattern;
/**
* Used to convert the tree pattern string into a series of tokens. The
* input stream is reset.
*/
get lexer(): Lexer;
/**
* Used to collect to the grammar file name, token names, rule names for
* used to parse the pattern into a parse tree.
*/
get parser(): Parser;
/**
* Recursively walk `tree` against `patternTree`, filling
* `match.`{@link ParseTreeMatch#labels labels}.
*
* @returns the first node encountered in `tree` which does not match
* a corresponding node in `patternTree`, or `undefined` if the match
* was successful. The specific node returned depends on the matching
* algorithm used by the implementation, and may be overridden.
*/
protected matchImpl(tree: ParseTree, patternTree: ParseTree, labels: MultiMap<string, ParseTree>): ParseTree | undefined;
/** Is `t` `(expr <expr>)` subtree? */
protected getRuleTagToken(t: ParseTree): RuleTagToken | undefined;
tokenize(pattern: string): Token[];
/** Split `<ID> = <e:expr> ;` into 4 chunks for tokenizing by {@link #tokenize}. */
split(pattern: string): Chunk[];
}
export declare namespace ParseTreePatternMatcher {
class CannotInvokeStartRule extends Error {
error: Error;
constructor(error: Error);
}
class StartRuleDoesNotConsumeFullPattern extends Error {
constructor();
}
}

View File

@@ -0,0 +1,477 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParseTreePatternMatcher = void 0;
// CONVERSTION complete, Burt Harris 10/14/2016
const BailErrorStrategy_1 = require("../../BailErrorStrategy");
const CharStreams_1 = require("../../CharStreams");
const CommonTokenStream_1 = require("../../CommonTokenStream");
const ListTokenSource_1 = require("../../ListTokenSource");
const MultiMap_1 = require("../../misc/MultiMap");
const Decorators_1 = require("../../Decorators");
const ParseCancellationException_1 = require("../../misc/ParseCancellationException");
const ParserInterpreter_1 = require("../../ParserInterpreter");
const ParserRuleContext_1 = require("../../ParserRuleContext");
const ParseTreeMatch_1 = require("./ParseTreeMatch");
const ParseTreePattern_1 = require("./ParseTreePattern");
const RecognitionException_1 = require("../../RecognitionException");
const RuleNode_1 = require("../RuleNode");
const RuleTagToken_1 = require("./RuleTagToken");
const TagChunk_1 = require("./TagChunk");
const TerminalNode_1 = require("../TerminalNode");
const TextChunk_1 = require("./TextChunk");
const Token_1 = require("../../Token");
const TokenTagToken_1 = require("./TokenTagToken");
/**
* A tree pattern matching mechanism for ANTLR {@link ParseTree}s.
*
* Patterns are strings of source input text with special tags representing
* token or rule references such as:
*
* ```
* <ID> = <expr>;
* ```
*
* Given a pattern start rule such as `statement`, this object constructs
* a {@link ParseTree} with placeholders for the `ID` and `expr`
* subtree. Then the {@link #match} routines can compare an actual
* {@link ParseTree} from a parse with this pattern. Tag `<ID>` matches
* any `ID` token and tag `<expr>` references the result of the
* `expr` rule (generally an instance of `ExprContext`.
*
* Pattern `x = 0;` is a similar pattern that matches the same pattern
* except that it requires the identifier to be `x` and the expression to
* be `0`.
*
* The {@link #matches} routines return `true` or `false` based
* upon a match for the tree rooted at the parameter sent in. The
* {@link #match} routines return a {@link ParseTreeMatch} object that
* contains the parse tree, the parse tree pattern, and a map from tag name to
* matched nodes (more below). A subtree that fails to match, returns with
* {@link ParseTreeMatch#mismatchedNode} set to the first tree node that did not
* match.
*
* For efficiency, you can compile a tree pattern in string form to a
* {@link ParseTreePattern} object.
*
* See `TestParseTreeMatcher` for lots of examples.
* {@link ParseTreePattern} has two static helper methods:
* {@link ParseTreePattern#findAll} and {@link ParseTreePattern#match} that
* are easy to use but not super efficient because they create new
* {@link ParseTreePatternMatcher} objects each time and have to compile the
* pattern in string form before using it.
*
* The lexer and parser that you pass into the {@link ParseTreePatternMatcher}
* constructor are used to parse the pattern in string form. The lexer converts
* the `<ID> = <expr>;` into a sequence of four tokens (assuming lexer
* throws out whitespace or puts it on a hidden channel). Be aware that the
* input stream is reset for the lexer (but not the parser; a
* {@link ParserInterpreter} is created to parse the input.). Any user-defined
* fields you have put into the lexer might get changed when this mechanism asks
* it to scan the pattern string.
*
* Normally a parser does not accept token `<expr>` as a valid
* `expr` but, from the parser passed in, we create a special version of
* the underlying grammar representation (an {@link ATN}) that allows imaginary
* tokens representing rules (`<expr>`) to match entire rules. We call
* these *bypass alternatives*.
*
* Delimiters are `<`} and `>`}, with `\` as the escape string
* by default, but you can set them to whatever you want using
* {@link #setDelimiters}. You must escape both start and stop strings
* `\<` and `\>`.
*/
class ParseTreePatternMatcher {
/**
* Constructs a {@link ParseTreePatternMatcher} or from a {@link Lexer} and
* {@link Parser} object. The lexer input stream is altered for tokenizing
* the tree patterns. The parser is used as a convenient mechanism to get
* the grammar name, plus token, rule names.
*/
constructor(lexer, parser) {
this.start = "<";
this.stop = ">";
this.escape = "\\"; // e.g., \< and \> must escape BOTH!
/**
* Regular expression corresponding to escape, for global replace
*/
this.escapeRE = /\\/g;
this._lexer = lexer;
this._parser = parser;
}
/**
* Set the delimiters used for marking rule and token tags within concrete
* syntax used by the tree pattern parser.
*
* @param start The start delimiter.
* @param stop The stop delimiter.
* @param escapeLeft The escape sequence to use for escaping a start or stop delimiter.
*
* @throws {@link Error} if `start` is not defined or empty.
* @throws {@link Error} if `stop` is not defined or empty.
*/
setDelimiters(start, stop, escapeLeft) {
if (!start) {
throw new Error("start cannot be null or empty");
}
if (!stop) {
throw new Error("stop cannot be null or empty");
}
this.start = start;
this.stop = stop;
this.escape = escapeLeft;
this.escapeRE = new RegExp(escapeLeft.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g");
}
matches(tree, pattern, patternRuleIndex = 0) {
if (typeof pattern === "string") {
let p = this.compile(pattern, patternRuleIndex);
return this.matches(tree, p);
}
else {
let labels = new MultiMap_1.MultiMap();
let mismatchedNode = this.matchImpl(tree, pattern.patternTree, labels);
return !mismatchedNode;
}
}
// Implementation of match
match(tree, pattern, patternRuleIndex = 0) {
if (typeof pattern === "string") {
let p = this.compile(pattern, patternRuleIndex);
return this.match(tree, p);
}
else {
let labels = new MultiMap_1.MultiMap();
let mismatchedNode = this.matchImpl(tree, pattern.patternTree, labels);
return new ParseTreeMatch_1.ParseTreeMatch(tree, pattern, labels, mismatchedNode);
}
}
/**
* For repeated use of a tree pattern, compile it to a
* {@link ParseTreePattern} using this method.
*/
compile(pattern, patternRuleIndex) {
let tokenList = this.tokenize(pattern);
let tokenSrc = new ListTokenSource_1.ListTokenSource(tokenList);
let tokens = new CommonTokenStream_1.CommonTokenStream(tokenSrc);
const parser = this._parser;
let parserInterp = new ParserInterpreter_1.ParserInterpreter(parser.grammarFileName, parser.vocabulary, parser.ruleNames, parser.getATNWithBypassAlts(), tokens);
let tree;
try {
parserInterp.errorHandler = new BailErrorStrategy_1.BailErrorStrategy();
tree = parserInterp.parse(patternRuleIndex);
// System.out.println("pattern tree = "+tree.toStringTree(parserInterp));
}
catch (e) {
if (e instanceof ParseCancellationException_1.ParseCancellationException) {
throw e.getCause();
}
else if (e instanceof RecognitionException_1.RecognitionException) {
throw e;
}
else if (e instanceof Error) {
throw new ParseTreePatternMatcher.CannotInvokeStartRule(e);
}
else {
throw e;
}
}
// Make sure tree pattern compilation checks for a complete parse
if (tokens.LA(1) !== Token_1.Token.EOF) {
throw new ParseTreePatternMatcher.StartRuleDoesNotConsumeFullPattern();
}
return new ParseTreePattern_1.ParseTreePattern(this, pattern, patternRuleIndex, tree);
}
/**
* Used to convert the tree pattern string into a series of tokens. The
* input stream is reset.
*/
get lexer() {
return this._lexer;
}
/**
* Used to collect to the grammar file name, token names, rule names for
* used to parse the pattern into a parse tree.
*/
get parser() {
return this._parser;
}
// ---- SUPPORT CODE ----
/**
* Recursively walk `tree` against `patternTree`, filling
* `match.`{@link ParseTreeMatch#labels labels}.
*
* @returns the first node encountered in `tree` which does not match
* a corresponding node in `patternTree`, or `undefined` if the match
* was successful. The specific node returned depends on the matching
* algorithm used by the implementation, and may be overridden.
*/
matchImpl(tree, patternTree, labels) {
if (!tree) {
throw new TypeError("tree cannot be null");
}
if (!patternTree) {
throw new TypeError("patternTree cannot be null");
}
// x and <ID>, x and y, or x and x; or could be mismatched types
if (tree instanceof TerminalNode_1.TerminalNode && patternTree instanceof TerminalNode_1.TerminalNode) {
let mismatchedNode;
// both are tokens and they have same type
if (tree.symbol.type === patternTree.symbol.type) {
if (patternTree.symbol instanceof TokenTagToken_1.TokenTagToken) { // x and <ID>
let tokenTagToken = patternTree.symbol;
// track label->list-of-nodes for both token name and label (if any)
labels.map(tokenTagToken.tokenName, tree);
const l = tokenTagToken.label;
if (l) {
labels.map(l, tree);
}
}
else if (tree.text === patternTree.text) {
// x and x
}
else {
// x and y
if (!mismatchedNode) {
mismatchedNode = tree;
}
}
}
else {
if (!mismatchedNode) {
mismatchedNode = tree;
}
}
return mismatchedNode;
}
if (tree instanceof ParserRuleContext_1.ParserRuleContext
&& patternTree instanceof ParserRuleContext_1.ParserRuleContext) {
let mismatchedNode;
// (expr ...) and <expr>
let ruleTagToken = this.getRuleTagToken(patternTree);
if (ruleTagToken) {
let m;
if (tree.ruleContext.ruleIndex === patternTree.ruleContext.ruleIndex) {
// track label->list-of-nodes for both rule name and label (if any)
labels.map(ruleTagToken.ruleName, tree);
const l = ruleTagToken.label;
if (l) {
labels.map(l, tree);
}
}
else {
if (!mismatchedNode) {
mismatchedNode = tree;
}
}
return mismatchedNode;
}
// (expr ...) and (expr ...)
if (tree.childCount !== patternTree.childCount) {
if (!mismatchedNode) {
mismatchedNode = tree;
}
return mismatchedNode;
}
let n = tree.childCount;
for (let i = 0; i < n; i++) {
let childMatch = this.matchImpl(tree.getChild(i), patternTree.getChild(i), labels);
if (childMatch) {
return childMatch;
}
}
return mismatchedNode;
}
// if nodes aren't both tokens or both rule nodes, can't match
return tree;
}
/** Is `t` `(expr <expr>)` subtree? */
getRuleTagToken(t) {
if (t instanceof RuleNode_1.RuleNode) {
if (t.childCount === 1 && t.getChild(0) instanceof TerminalNode_1.TerminalNode) {
let c = t.getChild(0);
if (c.symbol instanceof RuleTagToken_1.RuleTagToken) {
// System.out.println("rule tag subtree "+t.toStringTree(parser));
return c.symbol;
}
}
}
return undefined;
}
tokenize(pattern) {
// split pattern into chunks: sea (raw input) and islands (<ID>, <expr>)
let chunks = this.split(pattern);
// create token stream from text and tags
let tokens = [];
for (let chunk of chunks) {
if (chunk instanceof TagChunk_1.TagChunk) {
let tagChunk = chunk;
const firstChar = tagChunk.tag.substr(0, 1);
// add special rule token or conjure up new token from name
if (firstChar === firstChar.toUpperCase()) {
let ttype = this._parser.getTokenType(tagChunk.tag);
if (ttype === Token_1.Token.INVALID_TYPE) {
throw new Error("Unknown token " + tagChunk.tag + " in pattern: " + pattern);
}
let t = new TokenTagToken_1.TokenTagToken(tagChunk.tag, ttype, tagChunk.label);
tokens.push(t);
}
else if (firstChar === firstChar.toLowerCase()) {
let ruleIndex = this._parser.getRuleIndex(tagChunk.tag);
if (ruleIndex === -1) {
throw new Error("Unknown rule " + tagChunk.tag + " in pattern: " + pattern);
}
let ruleImaginaryTokenType = this._parser.getATNWithBypassAlts().ruleToTokenType[ruleIndex];
tokens.push(new RuleTagToken_1.RuleTagToken(tagChunk.tag, ruleImaginaryTokenType, tagChunk.label));
}
else {
throw new Error("invalid tag: " + tagChunk.tag + " in pattern: " + pattern);
}
}
else {
let textChunk = chunk;
this._lexer.inputStream = CharStreams_1.CharStreams.fromString(textChunk.text);
let t = this._lexer.nextToken();
while (t.type !== Token_1.Token.EOF) {
tokens.push(t);
t = this._lexer.nextToken();
}
}
}
// System.out.println("tokens="+tokens);
return tokens;
}
/** Split `<ID> = <e:expr> ;` into 4 chunks for tokenizing by {@link #tokenize}. */
split(pattern) {
let p = 0;
let n = pattern.length;
let chunks = [];
let buf;
// find all start and stop indexes first, then collect
let starts = [];
let stops = [];
while (p < n) {
if (p === pattern.indexOf(this.escape + this.start, p)) {
p += this.escape.length + this.start.length;
}
else if (p === pattern.indexOf(this.escape + this.stop, p)) {
p += this.escape.length + this.stop.length;
}
else if (p === pattern.indexOf(this.start, p)) {
starts.push(p);
p += this.start.length;
}
else if (p === pattern.indexOf(this.stop, p)) {
stops.push(p);
p += this.stop.length;
}
else {
p++;
}
}
// System.out.println("");
// System.out.println(starts);
// System.out.println(stops);
if (starts.length > stops.length) {
throw new Error("unterminated tag in pattern: " + pattern);
}
if (starts.length < stops.length) {
throw new Error("missing start tag in pattern: " + pattern);
}
let ntags = starts.length;
for (let i = 0; i < ntags; i++) {
if (starts[i] >= stops[i]) {
throw new Error("tag delimiters out of order in pattern: " + pattern);
}
}
// collect into chunks now
if (ntags === 0) {
let text = pattern.substring(0, n);
chunks.push(new TextChunk_1.TextChunk(text));
}
if (ntags > 0 && starts[0] > 0) { // copy text up to first tag into chunks
let text = pattern.substring(0, starts[0]);
chunks.push(new TextChunk_1.TextChunk(text));
}
for (let i = 0; i < ntags; i++) {
// copy inside of <tag>
let tag = pattern.substring(starts[i] + this.start.length, stops[i]);
let ruleOrToken = tag;
let label;
let colon = tag.indexOf(":");
if (colon >= 0) {
label = tag.substring(0, colon);
ruleOrToken = tag.substring(colon + 1, tag.length);
}
chunks.push(new TagChunk_1.TagChunk(ruleOrToken, label));
if (i + 1 < ntags) {
// copy from end of <tag> to start of next
let text = pattern.substring(stops[i] + this.stop.length, starts[i + 1]);
chunks.push(new TextChunk_1.TextChunk(text));
}
}
if (ntags > 0) {
let afterLastTag = stops[ntags - 1] + this.stop.length;
if (afterLastTag < n) { // copy text from end of last tag to end
let text = pattern.substring(afterLastTag, n);
chunks.push(new TextChunk_1.TextChunk(text));
}
}
// strip out the escape sequences from text chunks but not tags
for (let i = 0; i < chunks.length; i++) {
let c = chunks[i];
if (c instanceof TextChunk_1.TextChunk) {
let unescaped = c.text.replace(this.escapeRE, "");
if (unescaped.length < c.text.length) {
chunks[i] = new TextChunk_1.TextChunk(unescaped);
}
}
}
return chunks;
}
}
__decorate([
Decorators_1.NotNull,
__param(1, Decorators_1.NotNull)
], ParseTreePatternMatcher.prototype, "match", null);
__decorate([
Decorators_1.NotNull
], ParseTreePatternMatcher.prototype, "lexer", null);
__decorate([
Decorators_1.NotNull
], ParseTreePatternMatcher.prototype, "parser", null);
__decorate([
__param(0, Decorators_1.NotNull),
__param(1, Decorators_1.NotNull),
__param(2, Decorators_1.NotNull)
], ParseTreePatternMatcher.prototype, "matchImpl", null);
exports.ParseTreePatternMatcher = ParseTreePatternMatcher;
(function (ParseTreePatternMatcher) {
class CannotInvokeStartRule extends Error {
constructor(error) {
super(`CannotInvokeStartRule: ${error}`);
this.error = error;
}
}
ParseTreePatternMatcher.CannotInvokeStartRule = CannotInvokeStartRule;
// Fixes https://github.com/antlr/antlr4/issues/413
// "Tree pattern compilation doesn't check for a complete parse"
class StartRuleDoesNotConsumeFullPattern extends Error {
constructor() {
super("StartRuleDoesNotConsumeFullPattern");
}
}
ParseTreePatternMatcher.StartRuleDoesNotConsumeFullPattern = StartRuleDoesNotConsumeFullPattern;
})(ParseTreePatternMatcher = exports.ParseTreePatternMatcher || (exports.ParseTreePatternMatcher = {}));
//# sourceMappingURL=ParseTreePatternMatcher.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,122 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { CharStream } from "../../CharStream";
import { Token } from "../../Token";
import { TokenSource } from "../../TokenSource";
/**
* A {@link Token} object representing an entire subtree matched by a parser
* rule; e.g., `<expr>`. These tokens are created for {@link TagChunk}
* chunks where the tag corresponds to a parser rule.
*/
export declare class RuleTagToken implements Token {
/**
* This is the backing field for `ruleName`.
*/
private _ruleName;
/**
* The token type for the current token. This is the token type assigned to
* the bypass alternative for the rule during ATN deserialization.
*/
private bypassTokenType;
/**
* This is the backing field for `label`.
*/
private _label?;
/**
* Constructs a new instance of {@link RuleTagToken} with the specified rule
* name, bypass token type, and label.
*
* @param ruleName The name of the parser rule this rule tag matches.
* @param bypassTokenType The bypass token type assigned to the parser rule.
* @param label The label associated with the rule tag, or `undefined` if
* the rule tag is unlabeled.
*
* @exception IllegalArgumentException if `ruleName` is not defined
* or empty.
*/
constructor(ruleName: string, bypassTokenType: number, label?: string);
/**
* Gets the name of the rule associated with this rule tag.
*
* @returns The name of the parser rule associated with this rule tag.
*/
get ruleName(): string;
/**
* Gets the label associated with the rule tag.
*
* @returns The name of the label associated with the rule tag, or
* `undefined` if this is an unlabeled rule tag.
*/
get label(): string | undefined;
/**
* {@inheritDoc}
*
* Rule tag tokens are always placed on the {@link #DEFAULT_CHANNEL}.
*/
get channel(): number;
/**
* {@inheritDoc}
*
* This method returns the rule tag formatted with `<` and `>`
* delimiters.
*/
get text(): string;
/**
* {@inheritDoc}
*
* Rule tag tokens have types assigned according to the rule bypass
* transitions created during ATN deserialization.
*/
get type(): number;
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns 0.
*/
get line(): number;
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns -1.
*/
get charPositionInLine(): number;
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns -1.
*/
get tokenIndex(): number;
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns -1.
*/
get startIndex(): number;
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns -1.
*/
get stopIndex(): number;
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns `undefined`.
*/
get tokenSource(): TokenSource | undefined;
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns `undefined`.
*/
get inputStream(): CharStream | undefined;
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} returns a string of the form
* `ruleName:bypassTokenType`.
*/
toString(): string;
}

View File

@@ -0,0 +1,197 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuleTagToken = void 0;
const Decorators_1 = require("../../Decorators");
const Token_1 = require("../../Token");
/**
* A {@link Token} object representing an entire subtree matched by a parser
* rule; e.g., `<expr>`. These tokens are created for {@link TagChunk}
* chunks where the tag corresponds to a parser rule.
*/
let RuleTagToken = class RuleTagToken {
/**
* Constructs a new instance of {@link RuleTagToken} with the specified rule
* name, bypass token type, and label.
*
* @param ruleName The name of the parser rule this rule tag matches.
* @param bypassTokenType The bypass token type assigned to the parser rule.
* @param label The label associated with the rule tag, or `undefined` if
* the rule tag is unlabeled.
*
* @exception IllegalArgumentException if `ruleName` is not defined
* or empty.
*/
constructor(ruleName, bypassTokenType, label) {
if (ruleName == null || ruleName.length === 0) {
throw new Error("ruleName cannot be null or empty.");
}
this._ruleName = ruleName;
this.bypassTokenType = bypassTokenType;
this._label = label;
}
/**
* Gets the name of the rule associated with this rule tag.
*
* @returns The name of the parser rule associated with this rule tag.
*/
get ruleName() {
return this._ruleName;
}
/**
* Gets the label associated with the rule tag.
*
* @returns The name of the label associated with the rule tag, or
* `undefined` if this is an unlabeled rule tag.
*/
get label() {
return this._label;
}
/**
* {@inheritDoc}
*
* Rule tag tokens are always placed on the {@link #DEFAULT_CHANNEL}.
*/
get channel() {
return Token_1.Token.DEFAULT_CHANNEL;
}
/**
* {@inheritDoc}
*
* This method returns the rule tag formatted with `<` and `>`
* delimiters.
*/
get text() {
if (this._label != null) {
return "<" + this._label + ":" + this._ruleName + ">";
}
return "<" + this._ruleName + ">";
}
/**
* {@inheritDoc}
*
* Rule tag tokens have types assigned according to the rule bypass
* transitions created during ATN deserialization.
*/
get type() {
return this.bypassTokenType;
}
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns 0.
*/
get line() {
return 0;
}
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns -1.
*/
get charPositionInLine() {
return -1;
}
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns -1.
*/
get tokenIndex() {
return -1;
}
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns -1.
*/
get startIndex() {
return -1;
}
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns -1.
*/
get stopIndex() {
return -1;
}
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns `undefined`.
*/
get tokenSource() {
return undefined;
}
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} always returns `undefined`.
*/
get inputStream() {
return undefined;
}
/**
* {@inheritDoc}
*
* The implementation for {@link RuleTagToken} returns a string of the form
* `ruleName:bypassTokenType`.
*/
toString() {
return this._ruleName + ":" + this.bypassTokenType;
}
};
__decorate([
Decorators_1.NotNull
], RuleTagToken.prototype, "ruleName", null);
__decorate([
Decorators_1.Override
], RuleTagToken.prototype, "channel", null);
__decorate([
Decorators_1.Override
], RuleTagToken.prototype, "text", null);
__decorate([
Decorators_1.Override
], RuleTagToken.prototype, "type", null);
__decorate([
Decorators_1.Override
], RuleTagToken.prototype, "line", null);
__decorate([
Decorators_1.Override
], RuleTagToken.prototype, "charPositionInLine", null);
__decorate([
Decorators_1.Override
], RuleTagToken.prototype, "tokenIndex", null);
__decorate([
Decorators_1.Override
], RuleTagToken.prototype, "startIndex", null);
__decorate([
Decorators_1.Override
], RuleTagToken.prototype, "stopIndex", null);
__decorate([
Decorators_1.Override
], RuleTagToken.prototype, "tokenSource", null);
__decorate([
Decorators_1.Override
], RuleTagToken.prototype, "inputStream", null);
__decorate([
Decorators_1.Override
], RuleTagToken.prototype, "toString", null);
RuleTagToken = __decorate([
__param(0, Decorators_1.NotNull)
], RuleTagToken);
exports.RuleTagToken = RuleTagToken;
//# sourceMappingURL=RuleTagToken.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,59 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { Chunk } from "./Chunk";
/**
* Represents a placeholder tag in a tree pattern. A tag can have any of the
* following forms.
*
* * `expr`: An unlabeled placeholder for a parser rule `expr`.
* * `ID`: An unlabeled placeholder for a token of type `ID`.
* * `e:expr`: A labeled placeholder for a parser rule `expr`.
* * `id:ID`: A labeled placeholder for a token of type `ID`.
*
* This class does not perform any validation on the tag or label names aside
* from ensuring that the tag is a defined, non-empty string.
*/
export declare class TagChunk extends Chunk {
/**
* This is the backing field for `tag`.
*/
private _tag;
/**
* This is the backing field for `label`.
*/
private _label?;
/**
* Construct a new instance of {@link TagChunk} using the specified label
* and tag.
*
* @param label The label for the tag. If this is `undefined`, the
* {@link TagChunk} represents an unlabeled tag.
* @param tag The tag, which should be the name of a parser rule or token
* type.
*
* @exception IllegalArgumentException if `tag` is not defined or
* empty.
*/
constructor(tag: string, label?: string);
/**
* Get the tag for this chunk.
*
* @returns The tag for the chunk.
*/
get tag(): string;
/**
* Get the label, if any, assigned to this chunk.
*
* @returns The label assigned to this chunk, or `undefined` if no label is
* assigned to the chunk.
*/
get label(): string | undefined;
/**
* This method returns a text representation of the tag chunk. Labeled tags
* are returned in the form `label:tag`, and unlabeled tags are
* returned as just the tag name.
*/
toString(): string;
}

View File

@@ -0,0 +1,86 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TagChunk = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:46.1670669-07:00
const Chunk_1 = require("./Chunk");
const Decorators_1 = require("../../Decorators");
/**
* Represents a placeholder tag in a tree pattern. A tag can have any of the
* following forms.
*
* * `expr`: An unlabeled placeholder for a parser rule `expr`.
* * `ID`: An unlabeled placeholder for a token of type `ID`.
* * `e:expr`: A labeled placeholder for a parser rule `expr`.
* * `id:ID`: A labeled placeholder for a token of type `ID`.
*
* This class does not perform any validation on the tag or label names aside
* from ensuring that the tag is a defined, non-empty string.
*/
class TagChunk extends Chunk_1.Chunk {
/**
* Construct a new instance of {@link TagChunk} using the specified label
* and tag.
*
* @param label The label for the tag. If this is `undefined`, the
* {@link TagChunk} represents an unlabeled tag.
* @param tag The tag, which should be the name of a parser rule or token
* type.
*
* @exception IllegalArgumentException if `tag` is not defined or
* empty.
*/
constructor(tag, label) {
super();
if (tag == null || tag.length === 0) {
throw new Error("tag cannot be null or empty");
}
this._tag = tag;
this._label = label;
}
/**
* Get the tag for this chunk.
*
* @returns The tag for the chunk.
*/
get tag() {
return this._tag;
}
/**
* Get the label, if any, assigned to this chunk.
*
* @returns The label assigned to this chunk, or `undefined` if no label is
* assigned to the chunk.
*/
get label() {
return this._label;
}
/**
* This method returns a text representation of the tag chunk. Labeled tags
* are returned in the form `label:tag`, and unlabeled tags are
* returned as just the tag name.
*/
toString() {
if (this._label != null) {
return this._label + ":" + this._tag;
}
return this._tag;
}
}
__decorate([
Decorators_1.NotNull
], TagChunk.prototype, "tag", null);
__decorate([
Decorators_1.Override
], TagChunk.prototype, "toString", null);
exports.TagChunk = TagChunk;
//# sourceMappingURL=TagChunk.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"TagChunk.js","sourceRoot":"","sources":["../../../../src/tree/pattern/TagChunk.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;AAEH,wDAAwD;AAExD,mCAAgC;AAChC,iDAAqD;AAErD;;;;;;;;;;;GAWG;AACH,MAAa,QAAS,SAAQ,aAAK;IAUlC;;;;;;;;;;;OAWG;IACH,YAAY,GAAW,EAAE,KAAc;QACtC,KAAK,EAAE,CAAC;QAER,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;YACpC,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAC/C;QAED,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;OAIG;IAEH,IAAI,GAAG;QACN,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED;;;;OAIG;IAEI,QAAQ;QACd,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE;YACxB,OAAO,IAAI,CAAC,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;SACrC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;CACD;AA3BA;IADC,oBAAO;mCAGP;AAkBD;IADC,qBAAQ;wCAOR;AAjEF,4BAkEC","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-04T11:26:46.1670669-07:00\r\n\r\nimport { Chunk } from \"./Chunk\";\r\nimport { NotNull, Override } from \"../../Decorators\";\r\n\r\n/**\r\n * Represents a placeholder tag in a tree pattern. A tag can have any of the\r\n * following forms.\r\n *\r\n * * `expr`: An unlabeled placeholder for a parser rule `expr`.\r\n * * `ID`: An unlabeled placeholder for a token of type `ID`.\r\n * * `e:expr`: A labeled placeholder for a parser rule `expr`.\r\n * * `id:ID`: A labeled placeholder for a token of type `ID`.\r\n *\r\n * This class does not perform any validation on the tag or label names aside\r\n * from ensuring that the tag is a defined, non-empty string.\r\n */\r\nexport class TagChunk extends Chunk {\r\n\t/**\r\n\t * This is the backing field for `tag`.\r\n\t */\r\n\tprivate _tag: string;\r\n\t/**\r\n\t * This is the backing field for `label`.\r\n\t */\r\n\tprivate _label?: string;\r\n\r\n\t/**\r\n\t * Construct a new instance of {@link TagChunk} using the specified label\r\n\t * and tag.\r\n\t *\r\n\t * @param label The label for the tag. If this is `undefined`, the\r\n\t * {@link TagChunk} represents an unlabeled tag.\r\n\t * @param tag The tag, which should be the name of a parser rule or token\r\n\t * type.\r\n\t *\r\n\t * @exception IllegalArgumentException if `tag` is not defined or\r\n\t * empty.\r\n\t */\r\n\tconstructor(tag: string, label?: string) {\r\n\t\tsuper();\r\n\r\n\t\tif (tag == null || tag.length === 0) {\r\n\t\t\tthrow new Error(\"tag cannot be null or empty\");\r\n\t\t}\r\n\r\n\t\tthis._tag = tag;\r\n\t\tthis._label = label;\r\n\t}\r\n\r\n\t/**\r\n\t * Get the tag for this chunk.\r\n\t *\r\n\t * @returns The tag for the chunk.\r\n\t */\r\n\t@NotNull\r\n\tget tag(): string {\r\n\t\treturn this._tag;\r\n\t}\r\n\r\n\t/**\r\n\t * Get the label, if any, assigned to this chunk.\r\n\t *\r\n\t * @returns The label assigned to this chunk, or `undefined` if no label is\r\n\t * assigned to the chunk.\r\n\t */\r\n\tget label(): string | undefined {\r\n\t\treturn this._label;\r\n\t}\r\n\r\n\t/**\r\n\t * This method returns a text representation of the tag chunk. Labeled tags\r\n\t * are returned in the form `label:tag`, and unlabeled tags are\r\n\t * returned as just the tag name.\r\n\t */\r\n\t@Override\r\n\tpublic toString(): string {\r\n\t\tif (this._label != null) {\r\n\t\t\treturn this._label + \":\" + this._tag;\r\n\t\t}\r\n\r\n\t\treturn this._tag;\r\n\t}\r\n}\r\n"]}

View File

@@ -0,0 +1,35 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { Chunk } from "./Chunk";
/**
* Represents a span of raw text (concrete syntax) between tags in a tree
* pattern string.
*/
export declare class TextChunk extends Chunk {
/**
* This is the backing field for {@link #getText}.
*/
private _text;
/**
* Constructs a new instance of {@link TextChunk} with the specified text.
*
* @param text The text of this chunk.
* @exception IllegalArgumentException if `text` is not defined.
*/
constructor(text: string);
/**
* Gets the raw text of this chunk.
*
* @returns The text of the chunk.
*/
get text(): string;
/**
* {@inheritDoc}
*
* The implementation for {@link TextChunk} returns the result of
* `text` in single quotes.
*/
toString(): string;
}

View File

@@ -0,0 +1,69 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextChunk = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:46.2521448-07:00
const Chunk_1 = require("./Chunk");
const Decorators_1 = require("../../Decorators");
/**
* Represents a span of raw text (concrete syntax) between tags in a tree
* pattern string.
*/
let TextChunk = class TextChunk extends Chunk_1.Chunk {
/**
* Constructs a new instance of {@link TextChunk} with the specified text.
*
* @param text The text of this chunk.
* @exception IllegalArgumentException if `text` is not defined.
*/
constructor(text) {
super();
if (text == null) {
throw new Error("text cannot be null");
}
this._text = text;
}
/**
* Gets the raw text of this chunk.
*
* @returns The text of the chunk.
*/
get text() {
return this._text;
}
/**
* {@inheritDoc}
*
* The implementation for {@link TextChunk} returns the result of
* `text` in single quotes.
*/
toString() {
return "'" + this._text + "'";
}
};
__decorate([
Decorators_1.NotNull
], TextChunk.prototype, "_text", void 0);
__decorate([
Decorators_1.NotNull
], TextChunk.prototype, "text", null);
__decorate([
Decorators_1.Override
], TextChunk.prototype, "toString", null);
TextChunk = __decorate([
__param(0, Decorators_1.NotNull)
], TextChunk);
exports.TextChunk = TextChunk;
//# sourceMappingURL=TextChunk.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"TextChunk.js","sourceRoot":"","sources":["../../../../src/tree/pattern/TextChunk.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,wDAAwD;AAExD,mCAAgC;AAChC,iDAAqD;AAErD;;;GAGG;AACH,IAAa,SAAS,GAAtB,MAAa,SAAU,SAAQ,aAAK;IAOnC;;;;;OAKG;IACH,YAAqB,IAAY;QAChC,KAAK,EAAE,CAAC;QAER,IAAI,IAAI,IAAI,IAAI,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;SACvC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;OAIG;IAEH,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IAEI,QAAQ;QACd,OAAO,GAAG,GAAG,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;IAC/B,CAAC;CACD,CAAA;AAtCA;IADC,oBAAO;wCACc;AAwBtB;IADC,oBAAO;qCAGP;AASD;IADC,qBAAQ;yCAGR;AA1CW,SAAS;IAaR,WAAA,oBAAO,CAAA;GAbR,SAAS,CA2CrB;AA3CY,8BAAS","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-04T11:26:46.2521448-07:00\r\n\r\nimport { Chunk } from \"./Chunk\";\r\nimport { NotNull, Override } from \"../../Decorators\";\r\n\r\n/**\r\n * Represents a span of raw text (concrete syntax) between tags in a tree\r\n * pattern string.\r\n */\r\nexport class TextChunk extends Chunk {\r\n\t/**\r\n\t * This is the backing field for {@link #getText}.\r\n\t */\r\n\t@NotNull\r\n\tprivate _text: string;\r\n\r\n\t/**\r\n\t * Constructs a new instance of {@link TextChunk} with the specified text.\r\n\t *\r\n\t * @param text The text of this chunk.\r\n\t * @exception IllegalArgumentException if `text` is not defined.\r\n\t */\r\n\tconstructor(@NotNull text: string) {\r\n\t\tsuper();\r\n\r\n\t\tif (text == null) {\r\n\t\t\tthrow new Error(\"text cannot be null\");\r\n\t\t}\r\n\r\n\t\tthis._text = text;\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the raw text of this chunk.\r\n\t *\r\n\t * @returns The text of the chunk.\r\n\t */\r\n\t@NotNull\r\n\tget text(): string {\r\n\t\treturn this._text;\r\n\t}\r\n\r\n\t/**\r\n\t * {@inheritDoc}\r\n\t *\r\n\t * The implementation for {@link TextChunk} returns the result of\r\n\t * `text` in single quotes.\r\n\t */\r\n\t@Override\r\n\tpublic toString(): string {\r\n\t\treturn \"'\" + this._text + \"'\";\r\n\t}\r\n}\r\n"]}

View File

@@ -0,0 +1,56 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
import { CommonToken } from "../../CommonToken";
/**
* A {@link Token} object representing a token of a particular type; e.g.,
* `<ID>`. These tokens are created for {@link TagChunk} chunks where the
* tag corresponds to a lexer rule or token type.
*/
export declare class TokenTagToken extends CommonToken {
/**
* This is the backing field for `tokenName`.
*/
private _tokenName;
/**
* This is the backing field for `label`.
*/
private _label;
/**
* Constructs a new instance of {@link TokenTagToken} with the specified
* token name, type, and label.
*
* @param tokenName The token name.
* @param type The token type.
* @param label The label associated with the token tag, or `undefined` if
* the token tag is unlabeled.
*/
constructor(tokenName: string, type: number, label?: string);
/**
* Gets the token name.
* @returns The token name.
*/
get tokenName(): string;
/**
* Gets the label associated with the rule tag.
*
* @returns The name of the label associated with the rule tag, or
* `undefined` if this is an unlabeled rule tag.
*/
get label(): string | undefined;
/**
* {@inheritDoc}
*
* The implementation for {@link TokenTagToken} returns the token tag
* formatted with `<` and `>` delimiters.
*/
get text(): string;
/**
* {@inheritDoc}
*
* The implementation for {@link TokenTagToken} returns a string of the form
* `tokenName:type`.
*/
toString(): string;
}

View File

@@ -0,0 +1,94 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenTagToken = void 0;
// ConvertTo-TS run at 2016-10-04T11:26:46.3281988-07:00
const CommonToken_1 = require("../../CommonToken");
const Decorators_1 = require("../../Decorators");
/**
* A {@link Token} object representing a token of a particular type; e.g.,
* `<ID>`. These tokens are created for {@link TagChunk} chunks where the
* tag corresponds to a lexer rule or token type.
*/
let TokenTagToken = class TokenTagToken extends CommonToken_1.CommonToken {
/**
* Constructs a new instance of {@link TokenTagToken} with the specified
* token name, type, and label.
*
* @param tokenName The token name.
* @param type The token type.
* @param label The label associated with the token tag, or `undefined` if
* the token tag is unlabeled.
*/
constructor(tokenName, type, label) {
super(type);
this._tokenName = tokenName;
this._label = label;
}
/**
* Gets the token name.
* @returns The token name.
*/
get tokenName() {
return this._tokenName;
}
/**
* Gets the label associated with the rule tag.
*
* @returns The name of the label associated with the rule tag, or
* `undefined` if this is an unlabeled rule tag.
*/
get label() {
return this._label;
}
/**
* {@inheritDoc}
*
* The implementation for {@link TokenTagToken} returns the token tag
* formatted with `<` and `>` delimiters.
*/
get text() {
if (this._label != null) {
return "<" + this._label + ":" + this._tokenName + ">";
}
return "<" + this._tokenName + ">";
}
/**
* {@inheritDoc}
*
* The implementation for {@link TokenTagToken} returns a string of the form
* `tokenName:type`.
*/
toString() {
return this._tokenName + ":" + this.type;
}
};
__decorate([
Decorators_1.NotNull
], TokenTagToken.prototype, "_tokenName", void 0);
__decorate([
Decorators_1.NotNull
], TokenTagToken.prototype, "tokenName", null);
__decorate([
Decorators_1.Override
], TokenTagToken.prototype, "text", null);
__decorate([
Decorators_1.Override
], TokenTagToken.prototype, "toString", null);
TokenTagToken = __decorate([
__param(0, Decorators_1.NotNull)
], TokenTagToken);
exports.TokenTagToken = TokenTagToken;
//# sourceMappingURL=TokenTagToken.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"TokenTagToken.js","sourceRoot":"","sources":["../../../../src/tree/pattern/TokenTagToken.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,wDAAwD;AAExD,mDAAgD;AAChD,iDAAqD;AAErD;;;;GAIG;AACH,IAAa,aAAa,GAA1B,MAAa,aAAc,SAAQ,yBAAW;IAW7C;;;;;;;;OAQG;IACH,YAAqB,SAAiB,EAAE,IAAY,EAAE,KAAc;QACnE,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;OAGG;IAEH,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IAEH,IAAI,IAAI;QACP,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE;YACxB,OAAO,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;SACvD;QAED,OAAO,GAAG,GAAG,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IAEI,QAAQ;QACd,OAAO,IAAI,CAAC,UAAU,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;IAC1C,CAAC;CACD,CAAA;AAjEA;IADC,oBAAO;iDACmB;AA0B3B;IADC,oBAAO;8CAGP;AAmBD;IADC,qBAAQ;yCAOR;AASD;IADC,qBAAQ;6CAGR;AArEW,aAAa;IAoBZ,WAAA,oBAAO,CAAA;GApBR,aAAa,CAsEzB;AAtEY,sCAAa","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-04T11:26:46.3281988-07:00\r\n\r\nimport { CommonToken } from \"../../CommonToken\";\r\nimport { NotNull, Override } from \"../../Decorators\";\r\n\r\n/**\r\n * A {@link Token} object representing a token of a particular type; e.g.,\r\n * `<ID>`. These tokens are created for {@link TagChunk} chunks where the\r\n * tag corresponds to a lexer rule or token type.\r\n */\r\nexport class TokenTagToken extends CommonToken {\r\n\t/**\r\n\t * This is the backing field for `tokenName`.\r\n\t */\r\n\t@NotNull\r\n\tprivate _tokenName: string;\r\n\t/**\r\n\t * This is the backing field for `label`.\r\n\t */\r\n\tprivate _label: string | undefined;\r\n\r\n\t/**\r\n\t * Constructs a new instance of {@link TokenTagToken} with the specified\r\n\t * token name, type, and label.\r\n\t *\r\n\t * @param tokenName The token name.\r\n\t * @param type The token type.\r\n\t * @param label The label associated with the token tag, or `undefined` if\r\n\t * the token tag is unlabeled.\r\n\t */\r\n\tconstructor(@NotNull tokenName: string, type: number, label?: string) {\r\n\t\tsuper(type);\r\n\t\tthis._tokenName = tokenName;\r\n\t\tthis._label = label;\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the token name.\r\n\t * @returns The token name.\r\n\t */\r\n\t@NotNull\r\n\tget tokenName(): string {\r\n\t\treturn this._tokenName;\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the label associated with the rule tag.\r\n\t *\r\n\t * @returns The name of the label associated with the rule tag, or\r\n\t * `undefined` if this is an unlabeled rule tag.\r\n\t */\r\n\tget label(): string | undefined {\r\n\t\treturn this._label;\r\n\t}\r\n\r\n\t/**\r\n\t * {@inheritDoc}\r\n\t *\r\n\t * The implementation for {@link TokenTagToken} returns the token tag\r\n\t * formatted with `<` and `>` delimiters.\r\n\t */\r\n\t@Override\r\n\tget text(): string {\r\n\t\tif (this._label != null) {\r\n\t\t\treturn \"<\" + this._label + \":\" + this._tokenName + \">\";\r\n\t\t}\r\n\r\n\t\treturn \"<\" + this._tokenName + \">\";\r\n\t}\r\n\r\n\t/**\r\n\t * {@inheritDoc}\r\n\t *\r\n\t * The implementation for {@link TokenTagToken} returns a string of the form\r\n\t * `tokenName:type`.\r\n\t */\r\n\t@Override\r\n\tpublic toString(): string {\r\n\t\treturn this._tokenName + \":\" + this.type;\r\n\t}\r\n}\r\n"]}

View File

@@ -0,0 +1,9 @@
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
export * from "./ParseTreeMatch";
export * from "./ParseTreePattern";
export * from "./ParseTreePatternMatcher";
export * from "./RuleTagToken";
export * from "./TokenTagToken";

View File

@@ -0,0 +1,28 @@
"use strict";
/*!
* Copyright 2016 The ANTLR Project. All rights reserved.
* Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./ParseTreeMatch"), exports);
__exportStar(require("./ParseTreePattern"), exports);
__exportStar(require("./ParseTreePatternMatcher"), exports);
__exportStar(require("./RuleTagToken"), exports);
__exportStar(require("./TokenTagToken"), exports);
// The following are "package-private modules" - exported individually but don't need to be part of the public API
// exposed by this file.
//
// export * from "./Chunk";
// export * from "./TagChunk";
// export * from "./TextChunk";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/tree/pattern/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,mDAAiC;AACjC,qDAAmC;AACnC,4DAA0C;AAC1C,iDAA+B;AAC/B,kDAAgC;AAEhC,kHAAkH;AAClH,wBAAwB;AACxB,EAAE;AACF,2BAA2B;AAC3B,8BAA8B;AAC9B,+BAA+B","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\nexport * from \"./ParseTreeMatch\";\r\nexport * from \"./ParseTreePattern\";\r\nexport * from \"./ParseTreePatternMatcher\";\r\nexport * from \"./RuleTagToken\";\r\nexport * from \"./TokenTagToken\";\r\n\r\n// The following are \"package-private modules\" - exported individually but don't need to be part of the public API\r\n// exposed by this file.\r\n//\r\n// export * from \"./Chunk\";\r\n// export * from \"./TagChunk\";\r\n// export * from \"./TextChunk\";\r\n"]}