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.
@@ -116,22 +116,19 @@ const letterZ = 0x7a
116
116
 
117
117
  /** @typedef {number|undefined} CharCodeOrEof */
118
118
 
119
- /** @type {(old: string) => (input: CharCodeOrEof) => string} */
120
- const appendChar = old => input => input === undefined ? old : operator.concat(charToString(input))(old)
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: charToString(input), numberKind: 'int'}]
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: charToString(input)}]
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: charToString(input), numberKind: '0'}]
146
- case signMinus: return [undefined, { kind: 'number', value: charToString(input), numberKind: '-'}]
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
- /** @type {(input: list.List<CharCodeOrEof>) => list.List<JsonToken>} */
394
- const tokenize = input => list.flat(list.stateScan(tokenizeOp)({kind: 'initial'})(input))
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
  }
@@ -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
- /** @type {(a: readonly tokenizer.JsonToken[]) => string} */
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.335",
3
+ "version": "0.0.338",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
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' }
@@ -0,0 +1,9 @@
1
+ /** @typedef {readonly[number,number]} Range */
2
+
3
+ /** @type {(range: Range) => (i: number) => boolean} */
4
+ const contains = ([b, e]) => i => b <= i && i <= e
5
+
6
+ module.exports = {
7
+ /** @readonly */
8
+ contains,
9
+ }
@@ -0,0 +1,9 @@
1
+ const _ = require('./index.js')
2
+
3
+ {
4
+ if (!_.contains([0, 5])(1)) { throw 1 }
5
+ if (!_.contains([0, 5])(0)) { throw 0 }
6
+ if (!_.contains([0, 5])(5)) { throw 5 }
7
+ if (_.contains([0, 5])(-1)) { throw -1 }
8
+ if (_.contains([0, 5])(6)) { throw 6 }
9
+ }