Skip to content

Commit

Permalink
#88: Almost able to capture imported JS
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-zozol committed Oct 15, 2017
1 parent 708a221 commit bea13b8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
1 change: 1 addition & 0 deletions integration-ts/bundle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

16 changes: 5 additions & 11 deletions integration-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@
*/

import * as masala from './masala';
import {Stream, C, F} from '../src/lib/index'
import {assertArrayEquals, assertEquals} from '../integration-npm/assert';
import Bundle from '../src/lib/index'

let {Stream, F, C}:masala.Bundle = Bundle;

// Only char
let stream:masala.Stream<string> = Stream.ofString('abc');
let start:masala.Parser<string> = C.char('a');
let parser:masala.Parser<string> = C.char('a');
const parsing = parser.parse(stream);
const x = ['a', 'b', 'c'] === parsing.value; //compiling, types are almost OK

const charsParser = start
.then(C.char('b'))
.then(C.char('c'));
//.then(F.eos.drop()); // End Of Stream ; droping its value, just checking it's here
let parsing = charsParser.parse(stream);

const x = ['a', 'b', 'c'] === parsing.value;



Expand Down
19 changes: 15 additions & 4 deletions integration-ts/masala.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Written by Nicolas Zozol
* Based on https://github.com/jon-hanson/parsecj
* Inspired by https://github.com/jon-hanson/parsecj
*/

// Not needed
Expand Down Expand Up @@ -46,7 +46,7 @@ export interface Stream<Data>{
}

export interface StreamFactory{
ofString():Stream<string>;
ofString(string:string):Stream<string>;
ofArray<X>():Stream<Array<X>>;
}

Expand All @@ -63,7 +63,7 @@ export interface Response<T> extends Monoid<T>{
}

export interface Parser<T>{
then<Y>(p:Parser<Y>):Parser<T>;
then<Y>(p:Parser<Y>):Parser<T|Y>;
parse<X>(stream:Stream<X>, index?:number):Response<T>;
flatmap<Y> (f: ()=>Y): Parser<Y>;
map<Y> (f: ()=>Y): Parser<Y>;
Expand All @@ -86,4 +86,15 @@ export interface Response<T> extends Monoid<T>{
map(f):Response<T>;
flatmap(f):Response<T>;
filter(f:(value)=>boolean):Response<T>;
}
}

export interface CharBundle{}
export interface FlowBundle{}

export interface Bundle{
Stream:StreamFactory;
C:CharBundle;
F:FlowBundle
}

//export default Bundle;
10 changes: 10 additions & 0 deletions integration-ts/working.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as masala from './masala';
import {Stream, F, C} from '../src/lib/index'



let stream:masala.Stream<string> = Stream.ofString('abc');
let parser:masala.Parser<string> = C.char('a');
const parsing = parser.parse(stream);
const x = ['a', 'b', 'c'] === parsing.value; //compiling, types are almost OK

18 changes: 18 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ const MD = standard.markdownBundle;
const X = standard.extractorBundle;
const T = standard.tokenBundle;

export const bundle = {
data,
genlex,
parsec,
standard,
Stream,
parser,
F,
C,
N,
JSON,
MD,
X,
T,
};

export {
data,
genlex,
Expand All @@ -34,3 +50,5 @@ export {
X,
T,
};

export default bundle;

0 comments on commit bea13b8

Please sign in to comment.