-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fddf7aa
commit cbc2644
Showing
6 changed files
with
50 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
*.js | ||
*.js | ||
!/examples/beginner/chars.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import './beginner/chars' | ||
import './beginner/floor' | ||
import './beginner/hello-something' | ||
|
||
|
This file was deleted.
Oops, something went wrong.