Comparing version 0.13.0 to 0.13.1
# Changelog | ||
## v0.13.0 - February 24, 2017 | ||
### Notable changes: | ||
**Big stuff** | ||
- Ohm now supports incremental parsing! See the new Matcher class, which | ||
can be instantiated for a grammar `g` via `g.matcher()`. | ||
**Language** | ||
- [75d1bc8] Update built-in `lower`, `upper`, and `unicodeLtmo` rules to be | ||
consistent with unicode-9.0.0 | ||
- [4f864a0] Add built-in rule `caseInsensitive` rule for case-insensitive | ||
string matching (fixes #162) | ||
**API** | ||
- [b63aa84] Remove MatchResult.prototype.getDiscardedSpaces() | ||
- [7b455d2] Remove `children` and `childOffset` from TerminalNodes (fixes #176) | ||
**Misc** | ||
- [865c948] Add Typescript type declarations (#187) | ||
- [798ea77] Show action call stack when a semantic action is missing (fixes #53) | ||
- [482b693] Add VisitorFamily to extras (#156) | ||
## v0.12.0 - August 16, 2016 | ||
@@ -4,0 +27,0 @@ |
@@ -12,1 +12,8 @@ "use strict"; | ||
console.log(s(matchResult).getName()); | ||
var matcher = g.matcher(); | ||
matcher.setInput('foo'); | ||
matcher.replaceInputRange(0, 1, 'g') | ||
.replaceInputRange(2, 4, 'ah'); | ||
if (matcher.match('Greeting').succeeded()) { | ||
console.log('input:', matcher.getInput()); | ||
} |
@@ -43,10 +43,14 @@ API Reference | ||
<b><pre class="api">g.match(obj: string|object, optStartRule?: string) → MatchResult</pre></b> | ||
<a name="Grammar.match"><b><pre class="api">g.match(str: string, optStartRule?: string) → MatchResult</pre></b></a> | ||
Try to match `obj` against `g`, returning a MatchResult. If `optStartRule` is given, it specifies the rule on which to start matching. By default, the start rule is inherited from the supergrammar, or if there is no supergrammar specified, it is the first rule in `g`'s definition. | ||
Try to match `str` against `g`, returning a MatchResult. If `optStartRule` is given, it specifies the rule on which to start matching. By default, the start rule is inherited from the supergrammar, or if there is no supergrammar specified, it is the first rule in `g`'s definition. | ||
<b><pre class="api" id="trace">g.trace(obj: string|object, optStartRule?: string) → Trace</pre></b> | ||
<b><pre class="api">g.matcher()</pre></b> | ||
Try to match `obj` against `g`, returning a Trace object. `optNamespace` has the same meaning as in `ohm.grammar`. Trace objects have a `toString()` method, which returns a string which summarizes each parsing step (useful for debugging). | ||
Create a new [Matcher](#matcher-objects) object which supports incrementally matching `g` against a changing input string. | ||
<a name="Grammar.trace"><b><pre class="api" id="trace">g.trace(str: string, optStartRule?: string) → Trace</pre></b></a> | ||
Try to match `str` against `g`, returning a Trace object. `optNamespace` has the same meaning as in `ohm.grammar`. Trace objects have a `toString()` method, which returns a string which summarizes each parsing step (useful for debugging). | ||
<b><pre class="api">g.createSemantics() → Semantics</pre></b> | ||
@@ -60,2 +64,29 @@ | ||
Matcher objects | ||
--------------- | ||
Matcher objects can be used to incrementally match a changing input against the Matcher's grammar, e.g. in an editor or IDE. When a Matcher's input is modified via `replaceInputRange`, further calls to `match` will reuse the partial results of previous calls wherever possible. Generally, this means that small changes to the input will result in very short match times. | ||
A Matcher instance `m` has the following methods: | ||
<b><pre class="api">m.getInput() → string</pre></b> | ||
Return the current input string. | ||
<b><pre class="api">m.setInput(str: string)</pre></b> | ||
Set the input string to `str`. | ||
<b><pre class="api">m.replaceInputRange(startIdx: number, endIdx: number, str: string)</pre></b> | ||
Edit the current input string, replacing the characters between `startIdx` and `endIdx` with `str`. | ||
<b><pre class="api">m.match(optStartRule?: string) → MatchResult</pre></b> | ||
Like [Grammar's `match` method](#Grammar.match), but operates incrementally. | ||
<b><pre class="api">m.trace(optStartRule?: string) → Trace</pre></b> | ||
Like [Grammar's `trace` method](#Grammar.trace), but operates incrementally. | ||
MatchResult objects | ||
@@ -213,3 +244,3 @@ ------------------- | ||
<b><pre class="api">n.primitiveValue: number|string|...</pre></b> | ||
<b><pre class="api">n.primitiveValue: string</pre></b> | ||
@@ -216,0 +247,0 @@ For a terminal node, the raw value that was consumed from the input stream. |
@@ -10,10 +10,2 @@ declare namespace ohm { | ||
/** | ||
* Create a new Namespace containing Grammar instances for all of the | ||
* grammars defined in source. | ||
* If namespace is specified, it will be the prototype of the new | ||
* Namespace. | ||
*/ | ||
export function grammars(source: string, namespace?: Namespace): Namespace; | ||
/** | ||
* Create a Grammar instance from the contents of a <script> tag. | ||
@@ -30,2 +22,10 @@ * node, if specified, is a script tag with the attribute | ||
* Create a new Namespace containing Grammar instances for all of the | ||
* grammars defined in source. | ||
* If namespace is specified, it will be the prototype of the new | ||
* Namespace. | ||
*/ | ||
export function grammars(source: string, namespace?: Namespace): Namespace; | ||
/** | ||
* Create a new Namespace containing Grammar instances for all of the | ||
* grammars defined in the <script> tags in nodeList. If nodeList is | ||
@@ -61,3 +61,3 @@ * not specified, the result of | ||
/** | ||
* An ohm Grammar. | ||
* An Ohm Grammar. | ||
*/ | ||
@@ -75,2 +75,8 @@ interface Grammar { | ||
/** | ||
* Create a new Matcher object which supports incrementally matching | ||
* this grammar against a changing input string. | ||
*/ | ||
matcher(): Matcher; | ||
/** | ||
* Like match() except returns a trace object whose toString() returns | ||
@@ -96,2 +102,36 @@ * a summary of each parsing step useful for debugging. | ||
/** | ||
* Matcher objects are used to incrementally match a changing input | ||
* against a Grammar, e.g. in an editor or IDE. | ||
*/ | ||
interface Matcher { | ||
/** | ||
* Return the current input string. | ||
*/ | ||
getInput(): string; | ||
/** | ||
* Set the input string to `str`. | ||
*/ | ||
setInput(str: string); | ||
/** | ||
* Edit the current input string, replacing the characters between | ||
* `startIdx` and `endIdx` with `str`. | ||
*/ | ||
replaceInputRange(startIdx: number, endIdx: number, str: string): Matcher; | ||
/** | ||
* Like Grammar#match, but operates incrementally. | ||
*/ | ||
match(optStartRule?: string): MatchResult; | ||
/** | ||
* Like Grammar#trace, but operates incrementally. | ||
*/ | ||
trace(optStartRule?: string): Object; | ||
} | ||
/** | ||
* Result of Grammar#match | ||
@@ -173,4 +213,2 @@ */ | ||
/** | ||
@@ -247,3 +285,3 @@ * A dictionary is indexed by strings. | ||
*/ | ||
primitiveValue: any; | ||
primitiveValue: string; | ||
@@ -250,0 +288,0 @@ /** |
{ | ||
"name": "ohm-js", | ||
"version": "0.13.0", | ||
"version": "0.13.1", | ||
"description": "An object-oriented language for parsing and pattern matching", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/harc/ohm", |
@@ -18,1 +18,9 @@ import ohm from '..'; | ||
console.log(s(matchResult).getName()); | ||
const matcher = g.matcher(); | ||
matcher.setInput('foo'); | ||
matcher.replaceInputRange(0, 1, 'g') | ||
.replaceInputRange(2, 4, 'ah'); | ||
if (matcher.match('Greeting').succeeded()) { | ||
console.log('input:', matcher.getInput()); | ||
} |
3498142
46667