parser-combinator
Version:
Parser combinators
35 lines (29 loc) • 670 B
JavaScript
/*
* Parsec
* https://github.com/d-plaindoux/parsec
*
* Copyright (c) 2016 Didier Plaindoux
* Licensed under the LGPL2 license.
*/
import Stream from './stream';
/**
* Array stream class
*/
class ArrayStream extends Stream {
constructor(source) {
super();
this.source = source;
}
// ArrayStream 'a => unit -> boolean
endOfStream(index) {
return this.source.length <= index;
}
// ArrayStream 'a => number -> 'a <+> error
unsafeGet(index) {
return this.source[index];
}
}
function factory(source) {
return new ArrayStream(source);
}
export default factory;