Skip to content

Commit

Permalink
#88: TS: rep() and ListParser ok
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-zozol committed Nov 11, 2017
1 parent fddf7aa commit cbc2644
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 31 deletions.
3 changes: 2 additions & 1 deletion integration-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.js
*.js
!/examples/beginner/chars.ts
16 changes: 16 additions & 0 deletions integration-ts/examples/beginner/chars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Streams, F, C, N} from '@robusta/trash'

import {assertEquals} from '../../assert';


/**
* Created by Nicolas Zozol on 05/11/2017.
*/
const stream = Streams.ofString('abc');
const charsParser = C.char('a')
.then(C.char('b'))
.then(C.char('c'))
.then(F.eos.drop()); // End Of Stream ; droping its value, just checking it's here
let charsParsing = charsParser.parse(stream);
assertEquals('abc', charsParsing.value.join(''), 'Chars parsing');

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import {Streams, F, C, N} from '@robusta/trash'

import {assertEquals} from '../assert';
import {assertEquals} from '../../assert';



Expand All @@ -16,12 +16,3 @@ const floorCombinator = C.char('|').drop()
let parsing = floorCombinator.parse(stream);
assertEquals( 4, parsing.value, 'Floor parsing');



stream = Streams.ofString('abc');
const charsParser = C.char('a')
.then(C.char('b'))
.then(C.char('c'))
.then(F.eos.drop()); // End Of Stream ; droping its value, just checking it's here
let charsParsing = charsParser.parse(stream);
assertEquals( 'abc', charsParsing.value.join(''), 'Chars parsing');
26 changes: 26 additions & 0 deletions integration-ts/examples/beginner/hello-something.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Plain old ES
import {Streams, F, C, N} from '@robusta/trash'
import {assertEquals, assertArrayEquals, assertTrue} from '../../assert';

// The goal is check that we have Hello 'something', then to grab that something

const helloParser = C.string("Hello")
.then(C.char(' ').rep())
.then(C.char("'")).drop()
.then(C.letter.rep()) // keeping repeated ascii letters
.then(C.char("'").drop()); // keeping previous letters

const parsing = helloParser.parse(Streams.ofString("Hello 'World'"));
// C.letter.rep() will giv a array of letters

let x = parsing.value.array();

assertArrayEquals(['W','o','r','l','d'], parsing.value.array(), "Hello World joined");


// Note that helloParser will not reach the end of the stream; it will stop at the space after People
const peopleParsing = helloParser.parse(Streams.ofString("Hello 'People' in 2017"));

assertEquals("People", peopleParsing.value.join(''), "Hello People joined");
assertTrue(peopleParsing.offset < "Hello People in 2017".length, "Bad Offset for Hello People");

5 changes: 5 additions & 0 deletions integration-ts/examples/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import './beginner/chars'
import './beginner/floor'
import './beginner/hello-something'


20 changes: 0 additions & 20 deletions integration-ts/index.ts

This file was deleted.

0 comments on commit cbc2644

Please sign in to comment.