Skip to content

Commit ddb0e8f

Browse files
committed
feat(v2): End on renaming Streams.ofString to eventually Stream.ofChars
1 parent 9621a18 commit ddb0e8f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+326
-334
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const combinator = helloParser.then(white.rep()).then(worldParser)
7070

7171
```js
7272
// N: Number Bundle, C: Chars Bundle
73-
import { Streams, N, C } from '@masala/parser'
73+
import { Stream, N, C } from '@masala/parser'
7474

7575
const stream = Stream.ofChars('|4.6|')
7676
const floorCombinator = C.char('|')
@@ -124,14 +124,14 @@ that represents your problem. After parsing, there are two subtypes of
124124
- `Reject` if it could not.
125125

126126
```js
127-
let response = C.char('a').rep().parse(Streams.ofChars('aaaa'))
127+
let response = C.char('a').rep().parse(Stream.ofChars('aaaa'))
128128
assertEquals(response.value.join(''), 'aaaa')
129129
assertEquals(response.offset, 4)
130130
assertTrue(response.isAccepted())
131131
assertTrue(response.isConsumed())
132132

133133
// Partially accepted
134-
response = C.char('a').rep().parse(Streams.ofChars('aabb'))
134+
response = C.char('a').rep().parse(Stream.ofChars('aabb'))
135135
assertEquals(response.value.join(''), 'aa')
136136
assertEquals(response.offset, 2)
137137
assertTrue(response.isAccepted())
@@ -163,7 +163,7 @@ The goal is to check that we have Hello 'someone', then to grab that name
163163

164164
```js
165165
// Plain old javascript
166-
import { Streams, C } from '@masala/parser'
166+
import { Stream, C } from '@masala/parser'
167167

168168
var helloParser = C.string('Hello')
169169
.then(C.char(' ').rep())
@@ -182,7 +182,7 @@ And each new Parser is a combination of Parsers given by the standard bundles or
182182
previous functions.
183183

184184
```js
185-
import { Streams, N, C, F } from '@masala/parser'
185+
import { Stream, N, C, F } from '@masala/parser'
186186

187187
const blanks = () => C.char(' ').optrep()
188188

@@ -220,7 +220,7 @@ function combinator() {
220220
}
221221

222222
function parseOperation(line) {
223-
return combinator().parse(Streams.ofChars(line))
223+
return combinator().parse(Stream.ofChars(line))
224224
}
225225

226226
assertEquals(4, parseOperation('2 +2').value, 'sum: ')

documentation/chars-bundle.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
Using Only Chars
66

77
```js
8-
import { Streams, F, C } from '@masala/parser'
8+
import { Stream, F, C } from '@masala/parser'
99

10-
let stream = Streams.ofChars('abc')
10+
let stream = Stream.ofChars('abc')
1111
const charsParser = C.char('a')
1212
.then(C.char('b'))
1313
.then(C.char('c'))
@@ -20,7 +20,7 @@ assertArrayEquals(['a', 'b', 'c'], parsing.value)
2020
Or just using `C.letter` and `rep()`:
2121

2222
```js
23-
stream = Streams.ofChars('Hello World')
23+
stream = Stream.ofChars('Hello World')
2424
const letterParser = C.letter
2525
.rep() // 'Hello'
2626
.then(C.char(' ')) // space is not a letter
@@ -36,7 +36,7 @@ We can improve our control by using the right function at the right time. Here,
3636
Using `C.letters` and `C.string`
3737

3838
```js
39-
stream = Streams.ofChars('Hello World')
39+
stream = Stream.ofChars('Hello World')
4040
const helloParser = C.string('Hello').then(C.char(' ')).then(C.letters)
4141

4242
parsing = helloParser.parse(stream)
@@ -48,22 +48,22 @@ assertArrayEquals(['Hello', ' ', 'World'], parsing.value)
4848
### `letterAs(symbol)`:
4949

5050
```js
51-
import { Streams, F, C } from 'masala-parser'
51+
import { Stream, F, C } from 'masala-parser'
5252

53-
assertTrue(C.letterAs().parse(Streams.ofChars('a')).isAccepted())
53+
assertTrue(C.letterAs().parse(Stream.ofChars('a')).isAccepted())
5454
assertTrue(
55-
C.letterAs(C.OCCIDENTAL_LETTER).parse(Streams.ofChars('a')).isAccepted(),
55+
C.letterAs(C.OCCIDENTAL_LETTER).parse(Stream.ofChars('a')).isAccepted(),
5656
)
57-
assertTrue(C.letterAs(C.UTF8_LETTER).parse(Streams.ofChars('Б')).isAccepted())
57+
assertTrue(C.letterAs(C.UTF8_LETTER).parse(Stream.ofChars('Б')).isAccepted())
5858
assertTrue(
59-
!C.letterAs(C.OCCIDENTAL_LETTER).parse(Streams.ofChars('÷')).isAccepted(),
59+
!C.letterAs(C.OCCIDENTAL_LETTER).parse(Stream.ofChars('÷')).isAccepted(),
6060
)
6161
```
6262

6363
### stringIn
6464

6565
```js
66-
stream = Streams.ofChars('James')
66+
stream = Stream.ofChars('James')
6767
const combinator = C.stringIn(['The', 'James', 'Bond', 'series'])
6868
parsing = combinator.parse(stream)
6969
assertEquals('James', parsing.value)
@@ -77,7 +77,7 @@ parser. The argument can be either a raw range string `a-zA-Z_` or a RegExp
7777
consumes exactly one code unit.
7878

7979
```js
80-
let stream = Streams.ofChars('myUser')
80+
let stream = Stream.ofChars('myUser')
8181

8282
//identifier parser-> myUser: ok ; 0myUser: not ok
8383
const firstChar = C.inRegexRange('a-zA-Z_')

documentation/flow-bundle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ in a document. `F.dropTo(string|parser)` will do the same, but dropping the
8787
content.
8888

8989
```js
90-
const line = Streams.ofChars('I write until James Bond appears')
90+
const line = Stream.ofChars('I write until James Bond appears')
9191

9292
const combinator = F.moveUntil(C.string('James'))
9393
.then(F.dropTo('appears'))

documentation/numbers-bundle.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
**Import**
44

55
```ts
6-
import { N, Streams } from '@masala/parser'
6+
import { N, Stream } from '@masala/parser'
77
```
88

99
## Number parser
@@ -24,9 +24,9 @@ The parsing is returned as a JavaScript type `number`.
2424
**Examples**
2525

2626
```ts
27-
N.number().parse(Streams.ofChars('42')) // → 42
28-
N.number().parse(Streams.ofChars('-12.5')) // → -12.5
29-
N.number().parse(Streams.ofChars('3.1e-2')) // → 0.031
27+
N.number().parse(Stream.ofChars('42')) // → 42
28+
N.number().parse(Stream.ofChars('-12.5')) // → -12.5
29+
N.number().parse(Stream.ofChars('3.1e-2')) // → 0.031
3030
```
3131

3232
Grammar: `[+-]? (digits ("." digits?)? | "." digits) ([eE][+-]?digits)?`
@@ -46,6 +46,6 @@ const ratio = N.number().then(C.char('/')).then(N.number())
4646
**Examples**
4747

4848
```ts
49-
N.digit().parse(Streams.ofChars('7')) // '7'
50-
N.digits().parse(Streams.ofChars('1234')) // '1234'
49+
N.digit().parse(Stream.ofChars('7')) // '7'
50+
N.digits().parse(Stream.ofChars('1234')) // '1234'
5151
```

documentation/parser-core-functions.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Here is an example of a home-made parser for going back after an Accept:
4545
- Construct a Tuple of values from previous accepted values
4646

4747
```js
48-
let stream = Streams.ofChars('abc')
48+
let stream = Stream.ofChars('abc')
4949
const charsParser = C.char('a')
5050
.then(C.char('b'))
5151
.then(C.char('c'))
@@ -59,7 +59,7 @@ assertEquals(parsing.value, 'abc')
5959
- Uses `then()` and returns only the left or right value
6060

6161
```js
62-
const stream = Streams.ofChars('|4.6|')
62+
const stream = Stream.ofChars('|4.6|')
6363
const floorCombinator = C.char('|')
6464
.drop()
6565
.then(N.number()) // we have ['|',4.6], we keep 4.6
@@ -78,7 +78,7 @@ assertEquals(4, parsing.value, 'Floor parsing')
7878
- Change the value of the response
7979

8080
```js
81-
const stream = Streams.ofChars('5x8')
81+
const stream = Stream.ofChars('5x8')
8282
const combinator = N.integer()
8383
.then(C.charIn('x*').drop())
8484
.then(N.integer())
@@ -93,7 +93,7 @@ assertEquals(combinator.val(stream), 40)
9393
- It's a simplification of map
9494

9595
```js
96-
const stream = Streams.ofChars('ab')
96+
const stream = Stream.ofChars('ab')
9797
// given 'ac', value should be ['X' , 'c']
9898
const combinator = C.char('a').returns('X').then(C.char('b'))
9999
assertEquals(combinator.val(stream).array(), ['X', 'b'])
@@ -142,7 +142,7 @@ C.char('a').opt(C.char('b')).char('c')
142142
- Ensure a parser is repeated **at least** one time
143143

144144
```js
145-
const stream = Streams.ofChars('aaa')
145+
const stream = Stream.ofChars('aaa')
146146
const parsing = C.char('a').rep().parse(stream)
147147
test.ok(parsing.isAccepted())
148148
// We need to call list.array()
@@ -187,7 +187,7 @@ while testing or().
187187
const eater = C.char('a').then(C.char('a'))
188188
const parser = eater.or(C.char('b'))
189189

190-
const stream = Streams.ofChars('ab')
190+
const stream = Stream.ofChars('ab')
191191
const parsing = parser.parse(stream)
192192
expect(parsing.isAccepted()).toBe(false)
193193
expect(parsing.offset).toBe(1) // ✨ this is the point ! one 'a' is consumed
@@ -272,16 +272,16 @@ It can help you to read your document knowing what happen previously
272272

273273
'expect (filter) to be accepted': function(test) {
274274
test.equal(parser.char("a").filter(a => a === 'a')
275-
.parse(Streams.ofChars("a")).isAccepted(), true, 'should be accepted.');
275+
.parse(Stream.ofChars("a")).isAccepted(), true, 'should be accepted.');
276276
}
277277

278278
### match (matchValue)
279279

280280
- Simplification of `filter()`
281281
- Check if the stream value is equal to the _matchValue_
282282

283-
//given 123
284-
N.number().match(123)
283+
//given 123
284+
N.number().match(123)
285285

286286
### error()
287287

documentation/recursion.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ parsing
77

88
## Recursion fail
99

10-
const {Streams, F, N, C, X} = require('@masala/parser');
10+
const {Stream, F, N, C, X} = require('@masala/parser');
1111

1212
function A(){
1313
return C.char('A').then(B());
@@ -20,7 +20,7 @@ parsing
2020
console.log('=== Building Parser ====');
2121
const parser = A();
2222
console.log('=== NEVER THERE ====');
23-
let parsing = parser.parse(Streams.ofChars('AAAAAB'));
23+
let parsing = parser.parse(Stream.ofChars('AAAAAB'));
2424

2525
## Lazy Recursion
2626

@@ -39,8 +39,7 @@ parsing the stream.
3939
console.log('=== Building Parser ====');
4040
const parser = A();
4141
console.log('=== GETTING THERE ====');
42-
let parsing = parser.parse(Streams.ofChars('AAAAAB')); // Accepted :)
43-
42+
let parsing = parser.parse(Stream.ofChars('AAAAAB')); // Accepted :)
4443

4544
## Operations
4645

documentation/troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ const floorCombinator = C.string('Hello')
1212
.then(C.string('fail'))
1313
.debug('wont be displayed', true)
1414

15-
const parsing = floorCombinator.parse(Streams.ofChars('Hello World !!!'))
15+
const parsing = floorCombinator.parse(Stream.ofChars('Hello World !!!'))
1616
assertFalse(parsing.isAccepted(), 'Testing debug')
1717
```

faq.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
Difference between Parser.then() and Parser.thenRight()
1+
# FAQ
2+
3+
## Difference between Parser.then() and Parser.thenRight()
24

35
```js
46
p1.thenRight(p2) === p1.drop().then(p2)
57
```
68

7-
Difference between Parser.then() and Parser.thenLeft()
9+
## Difference between Parser.then() and Parser.thenLeft()
810

911
```js
1012
p1.thenLeft(p2) === p1.then(p2.drop())

integration-ts/examples/1-easy/chars.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { describe, it, expect } from 'vitest'
2-
import { Streams, F, C } from '@masala/parser'
2+
import { Stream, F, C } from '@masala/parser'
33

44
/**
55
* Created by Nicolas Zozol on 05/11/2017.
66
*/
77
describe('Character parsers', () => {
88
it('should parse sequential characters followed by EOS', () => {
9-
const stream = Streams.ofChars('abc')
9+
const stream = Stream.ofChars('abc')
1010
const charsParser = C.char('a')
1111
.then(C.char('b'))
1212
.then(C.char('c'))

integration-ts/examples/1-easy/floor.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { describe, it, expect } from 'vitest'
2-
import { Streams, C, N } from '@masala/parser'
2+
import { Stream, C, N } from '@masala/parser'
33

44
describe('Floor combinator', () => {
55
it('should parse a number between pipes and floor it', () => {
6-
let stream = Streams.ofChars('|4.6|')
6+
let stream = Stream.ofChars('|4.6|')
77
const floorCombinator = C.char('|')
88
.drop()
99
.then(N.number()) // we have ['|',4.6], we keep 4.6

0 commit comments

Comments
 (0)