diff --git a/integration-ts/.gitignore b/integration-ts/.gitignore index 4c43fe6..03aeb0f 100644 --- a/integration-ts/.gitignore +++ b/integration-ts/.gitignore @@ -1 +1,2 @@ -*.js \ No newline at end of file +*.js +!/examples/beginner/chars.ts diff --git a/integration-ts/examples/beginner/chars.ts b/integration-ts/examples/beginner/chars.ts new file mode 100644 index 0000000..19ec86a --- /dev/null +++ b/integration-ts/examples/beginner/chars.ts @@ -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'); + diff --git a/integration-ts/floor/floor.ts b/integration-ts/examples/beginner/floor.ts similarity index 54% rename from integration-ts/floor/floor.ts rename to integration-ts/examples/beginner/floor.ts index 75d093e..ea3143a 100644 --- a/integration-ts/floor/floor.ts +++ b/integration-ts/examples/beginner/floor.ts @@ -2,7 +2,7 @@ import {Streams, F, C, N} from '@robusta/trash' -import {assertEquals} from '../assert'; +import {assertEquals} from '../../assert'; @@ -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'); \ No newline at end of file diff --git a/integration-ts/examples/beginner/hello-something.ts b/integration-ts/examples/beginner/hello-something.ts new file mode 100644 index 0000000..c0bc708 --- /dev/null +++ b/integration-ts/examples/beginner/hello-something.ts @@ -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"); + diff --git a/integration-ts/examples/index.ts b/integration-ts/examples/index.ts new file mode 100644 index 0000000..f3d0308 --- /dev/null +++ b/integration-ts/examples/index.ts @@ -0,0 +1,5 @@ +import './beginner/chars' +import './beginner/floor' +import './beginner/hello-something' + + diff --git a/integration-ts/index.ts b/integration-ts/index.ts deleted file mode 100644 index 69f18d8..0000000 --- a/integration-ts/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Created by Nicolas Zozol on 13/10/2017. - */ - -import * as masala from './masala'; -import Bundles from '@masala/parser'; - -// Can I get rid of this line ? -let {Stream, F, C}:masala.Bundles = Bundles; - -let stream = Stream.ofString('abc'); -let parser= C.char('a'); -const parsing = parser.parse(stream); -const x = 'a' === parsing.value; //compiling, types are almost OK - - - - - -