functionalscript 0.0.335 → 0.0.338
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/json/tokenizer/index.js +11 -12
- package/json/tokenizer/test.js +2 -15
- package/package.json +1 -1
- package/test.js +1 -0
- package/types/range/index.js +9 -0
- package/types/range/test.js +9 -0
package/json/tokenizer/index.js
CHANGED
|
@@ -116,22 +116,19 @@ const letterZ = 0x7a
|
|
|
116
116
|
|
|
117
117
|
/** @typedef {number|undefined} CharCodeOrEof */
|
|
118
118
|
|
|
119
|
-
/** @type {(old: string) => (input:
|
|
120
|
-
const appendChar = old => input =>
|
|
121
|
-
|
|
122
|
-
/** @type {(input: CharCodeOrEof) => string} */
|
|
123
|
-
const charToString = input => input === undefined ? '' : String.fromCharCode(input)
|
|
119
|
+
/** @type {(old: string) => (input: number) => string} */
|
|
120
|
+
const appendChar = old => input => `${old}${String.fromCharCode(input)}`
|
|
124
121
|
|
|
125
122
|
/** @type {(state: InitialState) => (input: number) => readonly[list.List<JsonToken>, TokenizerState]} */
|
|
126
123
|
const initialStateOp = initialState => input =>
|
|
127
124
|
{
|
|
128
125
|
if (input >= digit1 && input <= digit9)
|
|
129
126
|
{
|
|
130
|
-
return [undefined, { kind: 'number', value:
|
|
127
|
+
return [undefined, { kind: 'number', value: String.fromCharCode(input), numberKind: 'int'}]
|
|
131
128
|
}
|
|
132
129
|
if (input >= letterA && input <= letterZ)
|
|
133
130
|
{
|
|
134
|
-
return [undefined, { kind: 'keyword', value:
|
|
131
|
+
return [undefined, { kind: 'keyword', value: String.fromCharCode(input)}]
|
|
135
132
|
}
|
|
136
133
|
switch(input)
|
|
137
134
|
{
|
|
@@ -142,8 +139,8 @@ const initialStateOp = initialState => input =>
|
|
|
142
139
|
case leftBracket: return [[{kind: '['}], initialState]
|
|
143
140
|
case rightBracket: return [[{kind: ']'}], initialState]
|
|
144
141
|
case quotationMark: return[undefined, {kind: 'string', value: ''}]
|
|
145
|
-
case digit0: return [undefined, { kind: 'number', value:
|
|
146
|
-
case signMinus: return [undefined, { kind: 'number', value:
|
|
142
|
+
case digit0: return [undefined, { kind: 'number', value: String.fromCharCode(input), numberKind: '0'}]
|
|
143
|
+
case signMinus: return [undefined, { kind: 'number', value: String.fromCharCode(input), numberKind: '-'}]
|
|
147
144
|
case horizontalTab:
|
|
148
145
|
case newLine:
|
|
149
146
|
case carriageReturn:
|
|
@@ -390,10 +387,12 @@ const tokenizeEofOp = state => {
|
|
|
390
387
|
/** @type {operator.StateScan<CharCodeOrEof, TokenizerState, list.List<JsonToken>>} */
|
|
391
388
|
const tokenizeOp = state => input => input === undefined ? tokenizeEofOp(state) : tokenizeCharCodeOp(state)(input)
|
|
392
389
|
|
|
393
|
-
|
|
394
|
-
|
|
390
|
+
const initial = list.stateScan(tokenizeOp)({ kind: 'initial' })
|
|
391
|
+
|
|
392
|
+
/** @type {(input: list.List<number>) => list.List<JsonToken>} */
|
|
393
|
+
const tokenize = input => list.flat(initial(list.concat(/** @type {list.List<CharCodeOrEof>} */(input))([undefined])))
|
|
395
394
|
|
|
396
395
|
module.exports = {
|
|
397
396
|
/** @readonly */
|
|
398
|
-
tokenize
|
|
397
|
+
tokenize
|
|
399
398
|
}
|
package/json/tokenizer/test.js
CHANGED
|
@@ -3,23 +3,10 @@ const list = require('../../types/list/index.js')
|
|
|
3
3
|
const json = require('../index.js')
|
|
4
4
|
const { sort } = require('../../types/object/index.js')
|
|
5
5
|
|
|
6
|
-
/** @type {(s: string) => list.List<tokenizer.CharCodeOrEof>} */
|
|
7
|
-
const toCharacters = s =>
|
|
8
|
-
{
|
|
9
|
-
/** @type {list.List<tokenizer.CharCodeOrEof>} */
|
|
10
|
-
const charCodes = list.toCharCodes(s)
|
|
11
|
-
return list.concat(charCodes)([undefined])
|
|
12
|
-
}
|
|
13
|
-
|
|
14
6
|
/** @type {(s: string) => readonly tokenizer.JsonToken[]} */
|
|
15
|
-
const tokenizeString = s =>
|
|
16
|
-
{
|
|
17
|
-
const characters = toCharacters(s)
|
|
18
|
-
return list.toArray(tokenizer.tokenize(characters))
|
|
19
|
-
}
|
|
7
|
+
const tokenizeString = s => list.toArray(tokenizer.tokenize(list.toCharCodes(s)))
|
|
20
8
|
|
|
21
|
-
|
|
22
|
-
const stringify = a => json.stringify(sort)(a)
|
|
9
|
+
const stringify = json.stringify(sort)
|
|
23
10
|
|
|
24
11
|
{
|
|
25
12
|
const result = tokenizeString('')
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -14,6 +14,7 @@ require('./commonjs/path/test.js')
|
|
|
14
14
|
require('./types/function/compare/test.js')
|
|
15
15
|
require('./types/stringSet/test.js')
|
|
16
16
|
require('./commonjs/build/test.js')
|
|
17
|
+
require('./types/range/test.js')
|
|
17
18
|
|
|
18
19
|
/** @type {() => never} */
|
|
19
20
|
const assert = () => { throw 'assert' }
|