Comparing version 0.5.3 to 0.6.0
@@ -288,6 +288,3 @@ /** | ||
} | ||
export interface MachineRule<T> extends Array<RegExp | MachineCallback<T>> { | ||
0: RegExp; | ||
1: MachineCallback<T>; | ||
} | ||
export declare type MachineRule<T> = [RegExp, MachineCallback<T>]; | ||
export declare function MachineRule<T>(regexp: RegExp, callback: MachineCallback<T>): MachineRule<T>; | ||
@@ -298,14 +295,5 @@ export interface MachineStateConstructor<T, I> { | ||
/** | ||
Every MachineState has: | ||
Every MachineState should declare a list of rules, at least one of which should | ||
call this.pop() or return a value. | ||
* value: I | ||
An internal value, which is incrementally built based on the input. | ||
* read(): T | ||
This derives a value of type T from the input. | ||
* rules: MachineRule[] | ||
Each MachineRule maps a string pattern to an instance method, which returns | ||
a value of type T (or null). If a rule matches the input and the corresponding | ||
instance method returns a non-null value, we should exit (pop) this state by | ||
returning from read(). | ||
`T` is the result Type | ||
@@ -317,10 +305,29 @@ `I` is the internal Type | ||
protected peek_length: number; | ||
/** An internal value, which is incrementally built based on the input. */ | ||
protected value: I; | ||
/** | ||
Each MachineRule maps a string pattern to an instance method, which returns | ||
a value of type T (or null). If a rule matches the input and the corresponding | ||
instance method returns a non-null value, we should exit (pop) this state by | ||
returning from read(). | ||
*/ | ||
protected rules: MachineRule<T>[]; | ||
constructor(iterable: StringIterable, peek_length?: number); | ||
private name; | ||
/** | ||
pop() returns the value of this state. When used as a rule's callback, this | ||
consumes nothing from the input iterable, but triggers the end of this state | ||
by returning a value. | ||
*/ | ||
pop(): T; | ||
/** | ||
ignore() returns undefined, which instructs the state to keep parsing. | ||
*/ | ||
ignore(): T; | ||
attachState<SubT, SubI>(SubState: MachineStateConstructor<SubT, SubI>): MachineState<SubT, SubI>; | ||
/** | ||
This derives a value of type T from the input, terminating with the first rule | ||
that returns a value. | ||
*/ | ||
read(): T; | ||
} |
26
index.js
@@ -465,14 +465,5 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
/** | ||
Every MachineState has: | ||
Every MachineState should declare a list of rules, at least one of which should | ||
call this.pop() or return a value. | ||
* value: I | ||
An internal value, which is incrementally built based on the input. | ||
* read(): T | ||
This derives a value of type T from the input. | ||
* rules: MachineRule[] | ||
Each MachineRule maps a string pattern to an instance method, which returns | ||
a value of type T (or null). If a rule matches the input and the corresponding | ||
instance method returns a non-null value, we should exit (pop) this state by | ||
returning from read(). | ||
`T` is the result Type | ||
@@ -494,6 +485,13 @@ `I` is the internal Type | ||
}); | ||
// generic callbacks | ||
/** | ||
pop() returns the value of this state. When used as a rule's callback, this | ||
consumes nothing from the input iterable, but triggers the end of this state | ||
by returning a value. | ||
*/ | ||
MachineState.prototype.pop = function () { | ||
return this.value; | ||
}; | ||
/** | ||
ignore() returns undefined, which instructs the state to keep parsing. | ||
*/ | ||
MachineState.prototype.ignore = function () { | ||
@@ -505,2 +503,6 @@ return undefined; | ||
}; | ||
/** | ||
This derives a value of type T from the input, terminating with the first rule | ||
that returns a value. | ||
*/ | ||
MachineState.prototype.read = function () { | ||
@@ -507,0 +509,0 @@ while (1) { |
{ | ||
"name": "lexing", | ||
"version": "0.5.3", | ||
"version": "0.6.0", | ||
"description": "Regex-based lexer", | ||
@@ -18,3 +18,6 @@ "keywords": [ | ||
"babel-core": "^5.0.0", | ||
"coveralls": "*", | ||
"istanbul": "*", | ||
"mocha": "*", | ||
"mocha-lcov-reporter": "*", | ||
"typescript": "*" | ||
@@ -21,0 +24,0 @@ }, |
# lexing | ||
[![npm version](https://badge.fury.io/js/lexing.svg)](https://www.npmjs.com/package/lexing) | ||
[![Travis CI Build Status](https://travis-ci.org/chbrown/lexing.svg)](https://travis-ci.org/chbrown/lexing) | ||
[![Coverage Status](https://coveralls.io/repos/chbrown/lexing/badge.svg)](https://coveralls.io/github/chbrown/lexing) | ||
Lexing vs. Parsing: lexers make only a single pass (no back-tracking); parsers have transition tables and do lookahead. The lexer can have state, but it should only make state transitions based on the current input, and not look at old input while processing new input. | ||
@@ -4,0 +8,0 @@ |
import assert from 'assert'; | ||
import {describe, it} from 'mocha'; | ||
import * as lexing from '../'; | ||
var Token = lexing.Token; | ||
import lexing from '../'; | ||
const Token = lexing.Token; | ||
@@ -7,0 +7,0 @@ function readToEOF<T>(iterable: lexing.Iterable<lexing.Token<T>>): lexing.Token<T>[] { |
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
49198
9
1072
139
6