functionalscript 0.0.338 → 0.0.341

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.
@@ -14,7 +14,7 @@ jobs:
14
14
 
15
15
  strategy:
16
16
  matrix:
17
- node-version: [14.x, 16.x, 17.x]
17
+ node-version: [14.x, 16.x, 18.x]
18
18
  # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19
19
 
20
20
  steps:
@@ -1,5 +1,6 @@
1
1
  const operator = require('../../types/function/operator/index.js')
2
2
  const list = require('../../types/list/index.js')
3
+ const range = require('../../types/range/index.js')
3
4
 
4
5
  /**
5
6
  * @typedef {{
@@ -67,6 +68,12 @@ const letterT = 0x74
67
68
  const letterU = 0x75
68
69
  const letterZ = 0x7a
69
70
 
71
+ const containsDigit = range.contains([digit0, digit9])
72
+ const containsDigitOneNine = range.contains([digit1, digit9])
73
+ const containsSmallAF = range.contains([letterA, letterF])
74
+ const containsCapitalAF = range.contains([capitalLetterA, capitalLetterF])
75
+ const containsSmallLetter = range.contains([letterA, letterZ])
76
+
70
77
  /**
71
78
  * @typedef {|
72
79
  * InitialState |
@@ -122,14 +129,18 @@ const appendChar = old => input => `${old}${String.fromCharCode(input)}`
122
129
  /** @type {(state: InitialState) => (input: number) => readonly[list.List<JsonToken>, TokenizerState]} */
123
130
  const initialStateOp = initialState => input =>
124
131
  {
125
- if (input >= digit1 && input <= digit9)
132
+ if (containsDigitOneNine(input))
126
133
  {
127
134
  return [undefined, { kind: 'number', value: String.fromCharCode(input), numberKind: 'int'}]
128
135
  }
129
- if (input >= letterA && input <= letterZ)
136
+ if (containsSmallLetter(input))
130
137
  {
131
138
  return [undefined, { kind: 'keyword', value: String.fromCharCode(input)}]
132
139
  }
140
+ if (isWhiteSpace(input))
141
+ {
142
+ return [undefined, initialState]
143
+ }
133
144
  switch(input)
134
145
  {
135
146
  case leftBrace: return [[{kind: '{'}], initialState]
@@ -141,10 +152,6 @@ const initialStateOp = initialState => input =>
141
152
  case quotationMark: return[undefined, {kind: 'string', value: ''}]
142
153
  case digit0: return [undefined, { kind: 'number', value: String.fromCharCode(input), numberKind: '0'}]
143
154
  case signMinus: return [undefined, { kind: 'number', value: String.fromCharCode(input), numberKind: '-'}]
144
- case horizontalTab:
145
- case newLine:
146
- case carriageReturn:
147
- case space: return[undefined, initialState]
148
155
  default: return [[{kind: 'error', message: 'unexpected character'}], initialState]
149
156
  }
150
157
  }
@@ -174,7 +181,7 @@ const parseNumberStateOp = state => input =>
174
181
  default: return [undefined, {kind:'number', value: appendChar(state.value)(input), numberKind: state.numberKind}]
175
182
  }
176
183
  }
177
- if (input >= digit1 && input <= digit9)
184
+ if (containsDigitOneNine(input))
178
185
  {
179
186
  switch (state.numberKind)
180
187
  {
@@ -239,6 +246,10 @@ const parseNumberStateOp = state => input =>
239
246
  /** @type {(char: number) => boolean} */
240
247
  const isTerminalForNumber = char =>
241
248
  {
249
+ if (isWhiteSpace(char))
250
+ {
251
+ return true;
252
+ }
242
253
  switch (char)
243
254
  {
244
255
  case quotationMark:
@@ -252,6 +263,19 @@ const isTerminalForNumber = char =>
252
263
  }
253
264
  }
254
265
 
266
+ /** @type {(char: number) => boolean} */
267
+ const isWhiteSpace = char =>
268
+ {
269
+ switch (char)
270
+ {
271
+ case horizontalTab:
272
+ case newLine:
273
+ case carriageReturn:
274
+ case space: return true
275
+ default: return false
276
+ }
277
+ }
278
+
255
279
  /** @type {(state: InvalidNumberState) => (input: number) => readonly[list.List<JsonToken>, TokenizerState]} */
256
280
  const invalidNumberStateOp = state => input =>
257
281
  {
@@ -298,9 +322,9 @@ const parseEscapeCharStateOp = state => input =>
298
322
  /** @type {(hex: number) => number|undefined} */
299
323
  const hexDigitToNumber = hex =>
300
324
  {
301
- if (hex >= digit0 && hex <= digit9) { return hex - digit0 }
302
- if (hex >= capitalLetterA && hex <= capitalLetterF) { return hex - capitalLetterA + 10 }
303
- if (hex >= letterA && hex <= letterF) { return hex - letterA + 10 }
325
+ if (containsDigit(hex)) { return hex - digit0 }
326
+ if (containsCapitalAF(hex)) { return hex - capitalLetterA + 10 }
327
+ if (containsSmallAF(hex)) { return hex - letterA + 10 }
304
328
  }
305
329
 
306
330
  /** @type {(state: ParseUnicodeCharState) => (input: number) => readonly[list.List<JsonToken>, TokenizerState]} */
@@ -333,7 +357,7 @@ const stringToKeywordToken = s =>
333
357
  /** @type {(state: ParseKeywordState) => (input: number) => readonly[list.List<JsonToken>, TokenizerState]} */
334
358
  const parseKeyWordStateOp = state => input =>
335
359
  {
336
- if (input >= letterA && input <= letterZ)
360
+ if (containsSmallLetter(input))
337
361
  {
338
362
  return [undefined, {kind: 'keyword', value: appendChar(state.value)(input)}]
339
363
  }
@@ -188,6 +188,16 @@ const stringify = json.stringify(sort)
188
188
  if (result !== '[{"kind":"{"},{"kind":"number","value":"90"},{"kind":"}"}]') { throw result }
189
189
  }
190
190
 
191
+ {
192
+ const result = stringify(tokenizeString('1 2'))
193
+ if (result !== '[{"kind":"number","value":"1"},{"kind":"number","value":"2"}]') { throw result }
194
+ }
195
+
196
+ {
197
+ const result = stringify(tokenizeString('0. 2'))
198
+ if (result !== '[{"kind":"error","message":"invalid number"},{"kind":"number","value":"2"}]') { throw result }
199
+ }
200
+
191
201
  {
192
202
  const result = stringify(tokenizeString('10-0'))
193
203
  if (result !== '[{"kind":"error","message":"invalid number"}]') { throw result }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.338",
3
+ "version": "0.0.341",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
30
30
  "devDependencies": {
31
- "@types/node": "^16.11.26",
32
- "typescript": "^4.6.2"
31
+ "@types/node": "^17.0.35",
32
+ "typescript": "^4.7.2"
33
33
  }
34
34
  }