Comparing version 0.8.0 to 0.8.1
@@ -0,1 +1,7 @@ | ||
## 0.8.1 (2020-02-26) | ||
### New features | ||
You can now find the top node type parsed by the parser through its `topType` property. | ||
## 0.8.0 (2020-02-03) | ||
@@ -2,0 +8,0 @@ |
@@ -779,3 +779,3 @@ 'use strict'; | ||
this.tokenCount = 0; | ||
var topInfo = parser.topRules[top || Object.keys(parser.topRules)[0]]; | ||
var topInfo = top ? parser.topRules[top] : parser.defaultTop; | ||
if (!topInfo) | ||
@@ -925,3 +925,3 @@ throw new RangeError("Invalid top rule name " + top); | ||
else { | ||
var topInfo = nested.topRules[top || Object.keys(nested.topRules)[0]]; | ||
var topInfo = top ? nested.topRules[top] : nested.defaultTop; | ||
var newStack = Stack.start(new StackContext(nested, stack.cx.maxBufferLength, clippedInput, topInfo[1], stack, wrapType), topInfo[0], stack.pos); | ||
@@ -1240,2 +1240,14 @@ if (verbose) | ||
}); | ||
Object.defineProperty(Parser.prototype, "defaultTop", { | ||
/// @internal | ||
get: function () { return this.topRules[Object.keys(this.topRules)[0]]; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Parser.prototype, "topType", { | ||
/// The node type produced by the default top rule. | ||
get: function () { return this.group.types[this.defaultTop[1]]; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/// (Used by the output of the parser generator) @internal | ||
@@ -1242,0 +1254,0 @@ Parser.deserialize = function (spec) { |
import { Stack } from "./stack"; | ||
import { InputStream, Token, Tokenizer, TokenGroup } from "./token"; | ||
import { Tree, TreeBuffer, NodeGroup, NodeProp, NodePropSource } from "lezer-tree"; | ||
import { Tree, TreeBuffer, NodeGroup, NodeType, NodeProp, NodePropSource } from "lezer-tree"; | ||
export declare type NestedGrammar = null | Parser | ((input: InputStream, stack: Stack) => NestedGrammarSpec); | ||
@@ -118,2 +118,4 @@ export interface NestedGrammarSpec { | ||
get hasNested(): boolean; | ||
get defaultTop(): [number, number]; | ||
get topType(): NodeType; | ||
static deserialize(spec: { | ||
@@ -120,0 +122,0 @@ states: string; |
{ | ||
"name": "lezer", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "Incremental parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -239,3 +239,3 @@ import {Stack, Recover} from "./stack" | ||
{cache = undefined, strict = false, bufferLength = DefaultBufferLength, top = undefined}: ParseOptions = {}) { | ||
let topInfo = parser.topRules[top || Object.keys(parser.topRules)[0]] | ||
let topInfo = top ? parser.topRules[top] : parser.defaultTop | ||
if (!topInfo) throw new RangeError(`Invalid top rule name ${top}`) | ||
@@ -370,3 +370,3 @@ this.stacks = [Stack.start(new StackContext(parser, bufferLength, input, topInfo[1]), topInfo[0])] | ||
} else { | ||
let topInfo = nested.topRules[top || Object.keys(nested.topRules)[0]] | ||
let topInfo = top ? nested.topRules[top] : nested.defaultTop | ||
let newStack = Stack.start(new StackContext(nested, stack.cx.maxBufferLength, clippedInput, topInfo[1], stack, wrapType), | ||
@@ -673,2 +673,8 @@ topInfo[0], stack.pos) | ||
/// @internal | ||
get defaultTop() { return this.topRules[Object.keys(this.topRules)[0]] } | ||
/// The node type produced by the default top rule. | ||
get topType() { return this.group.types[this.defaultTop[1]] } | ||
/// (Used by the output of the parser generator) @internal | ||
@@ -675,0 +681,0 @@ static deserialize(spec: { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2467393
256
4302