functionalscript 0.0.477 → 0.0.478

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/fsc/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # FunctionalScript Compiler
2
+
3
+ ## Tokenizer
4
+
5
+ - `!` - logicalNot
6
+ - `!=` - nonStrictNotEqual
7
+ - `!==` - notEqual
8
+ - `"` - doubleStringBegin
9
+ - `$` - idBegin
10
+ - `%` - remainder
11
+ - `%=` - remainder assignment
12
+ - `&` - bitwiseAnd
13
+ - `&&` - logicalAnd
14
+ - `&&=` - logicalAndAssignment
15
+ - `&=` - bitwiseAndAssignment
16
+ - `'` - singleStringBegin
17
+ - `(` - groupingBegin
18
+ - `)` - groupingEnd
19
+ - `*` - multiplication
20
+ - `**` - exponential
21
+ - `**=` - exponentialAssignment
22
+ - `*/` - commentEnd
23
+ - `*=` - multiplicationAssignment
24
+ - `+` - addition
25
+ - `++` - increment
26
+ - `+=` - additionAssignment
27
+ - `,` - comma
28
+ - `-` - subtraction
29
+ - `--` - decrement
30
+ - `-=` - subtractionAssignment
31
+ - `.` - dot
32
+ - `...` - spread
33
+ - `/` - division
34
+ - `/*` - commentBegin
35
+ - `/=` - divisionAssignment
36
+ - `0..9` - numberBegin
37
+ - `:` - colon
38
+ - `;` - semicolon
39
+ - `<` - less
40
+ - `<<` - leftShift
41
+ - `<<=` - leftShiftAssignment
42
+ - `<=` - lessEqual
43
+ - `=` - assignment
44
+ - `==` - nonStrictEqual ?
45
+ - `===` - equal
46
+ - `=>` - arrow
47
+ - `>` - greater
48
+ - `<=` - greaterEqual
49
+ - `>>` - rightShift
50
+ - `>>>` - unsignedRightShift
51
+ - `>>>=` unsignedRightShiftAssignment
52
+ - `?` - question
53
+ - `?.` - optional chaining
54
+ - `??` - nullish coalescing
55
+ - `A..Z` - idBegin
56
+ - `Infinity` - infinity
57
+ - `NaN` - nan
58
+ - `[` - propertyBegin
59
+ - `]` - propertyEnd`
60
+ - `^` - bitwiseXor
61
+ - `^=` - bitwiseXorAssignment
62
+ - `_` - idBegin
63
+ - '`' - templateBegin
64
+ - `a..z` - idBegin
65
+ - `async` ?
66
+ - `await` ?
67
+ - `break`
68
+ - `case`
69
+ - `catch`
70
+ - `class`
71
+ - `const`
72
+ - `continue`
73
+ - `debugger`
74
+ - `delete` ?
75
+ - `do` ?
76
+ - `else`
77
+ - `export`
78
+ - `exports` <= non-standard
79
+ - `false`
80
+ - `function` ?
81
+ - `globalThis` ?
82
+ - `for`
83
+ - `if`
84
+ - `import`
85
+ - `in`
86
+ - `instanceof`
87
+ - `let`
88
+ - `module` <= non-standard
89
+ - `new` ?
90
+ - `null`
91
+ - `of`
92
+ - `require` <= non-standard
93
+ - `return`
94
+ - `super`
95
+ - `switch`
96
+ - `this` ?
97
+ - `throw`
98
+ - `true`
99
+ - `try`
100
+ - `typeof`
101
+ - `undefined`
102
+ - `var`
103
+ - `void`
104
+ - `while`
105
+ - `yield`
106
+ - `{` - objectBegin
107
+ - `|` - bitwiseOr
108
+ - `|=` - bitwiseOrAssignment
109
+ - `||` - logicalOr
110
+ - `||=` - logicalOrAssignment
111
+ - `}` - objectEnd
112
+ - `~` - bitwiseNot
113
+ - `~=` - bitwiseNotAssignment
package/fsc/module.f.cjs CHANGED
@@ -1,4 +1,118 @@
1
- const ascii = require('../text/ascii/module.f.cjs')
1
+ const operator = require('../types/function/operator/module.f.cjs')
2
+ const range_map = require('../types/range_map/module.f.cjs')
3
+ const { merge: rangeMapMerge, fromRange, get } = range_map
4
+ const { reduce: listReduce } = require('../types/list/module.f.cjs')
5
+ const { range: asciiRange } = require('../text/ascii/module.f.cjs')
6
+ const { fromCharCode } = String
7
+ const { fn } = require('../types/function/module.f.cjs')
8
+ const list = require('../types/list/module.f.cjs')
9
+ const _range = require('../types/range/module.f.cjs')
10
+ const { one } = _range
11
+ const { toArray, map } = list
12
+
13
+ /** @typedef {readonly[readonly string[], ToResult]} Result */
14
+
15
+ /** @typedef {(a: number) => Result} ToResult */
16
+
17
+ /**
18
+ * @template T
19
+ * @typedef {(state: T) => ToResult} CreateToResult
20
+ */
21
+
22
+ /**
23
+ * @template T
24
+ * @typedef {range_map.RangeMapArray<CreateToResult<T>>} State
25
+ */
26
+
27
+ /** @type {ToResult} */
28
+ const unknownSymbol = a => [[`unknown symbol ${a}`], unknownSymbol]
29
+
30
+ /** @type {<T>(a: T) => ToResult} */
31
+ const def = () => unknownSymbol
32
+
33
+ /** @type {<T>(a: CreateToResult<T>) => (b: CreateToResult<T>) => CreateToResult<T>} */
34
+ const union = a => b => {
35
+ if (a === def || a === b) { return b }
36
+ if (b === def) { return a }
37
+ throw [a, b]
38
+ }
39
+
40
+ /** @type {readonly never[]} */
41
+ const empty = []
42
+
43
+ /** @type {<T>(a: list.List<State<T>>) => State<T>} */
44
+ const reduce = a => {
45
+ /** @typedef {typeof a extends list.List<State<infer T>> ? T : never} T */
46
+ /** @type {range_map.RangeMerge<CreateToResult<T>>} */
47
+ const merge = rangeMapMerge({
48
+ union,
49
+ equal: operator.strictEqual,
50
+ })
51
+ return toArray(listReduce(merge)(empty)(a))
52
+ }
53
+
54
+
55
+ const codePointRange = fromRange(def)
56
+
57
+ const range = fn(asciiRange).then(codePointRange).result
58
+
59
+ /** @type {(l: readonly string[]) => <T>(f: CreateToResult<T>) => State<T>} */
60
+ const rangeSet = l => f => {
61
+ /** @typedef {typeof f extends CreateToResult<infer T> ? T : never} T */
62
+ /** @type {(a: _range.Range) => (f: CreateToResult<T>) => State<T>} */
63
+ const codePointRange = fromRange(def)
64
+ /** @type {(r: string) => State<T>} */
65
+ const g = r => codePointRange(asciiRange(r))(f)
66
+ return reduce(map(g)(l))
67
+ }
68
+
69
+ /** @type {<T>(a: list.List<State<T>>) => CreateToResult<T>} */
70
+ const create = a => {
71
+ /** @typedef {typeof a extends list.List<State<infer T>> ? T : never} T */
72
+ const i = reduce(a)
73
+ /** @type {(v: number) => (i: State<T>) => (v: T) => ToResult} */
74
+ const x = get(def)
75
+ return v => c => x(c)(i)(v)(c)
76
+ }
77
+
78
+ const terminal = -1
79
+
80
+ const init = create([
81
+ codePointRange(one(terminal))(() => () => [[], unknownSymbol]),
82
+ rangeSet(['\t', ' '])(() => () => [[' '], unknownSymbol]),
83
+ rangeSet(['\n', '\r'])(() => () => [['\n'], unknownSymbol]),
84
+ range('!')(() => () => [['!'], unknownSymbol]),
85
+ range('"')(() => () => [['"'], unknownSymbol]),
86
+ rangeSet(['$', '_', 'AZ', 'az'])(() => c => [[fromCharCode(c)], unknownSymbol]),
87
+ range('%')(() => () => [['%'], unknownSymbol]),
88
+ range('&')(() => () => [['&'], unknownSymbol]),
89
+ range("'")(() => () => [["'"], unknownSymbol]),
90
+ range('(')(() => () => [['('], unknownSymbol]),
91
+ range(')')(() => () => [[')'], unknownSymbol]),
92
+ range('*')(() => () => [['*'], unknownSymbol]),
93
+ range('+')(() => () => [['+'], unknownSymbol]),
94
+ range(',')(() => () => [[','], unknownSymbol]),
95
+ range('-')(() => () => [['-'], unknownSymbol]),
96
+ range('.')(() => () => [['.'], unknownSymbol]),
97
+ range('/')(() => () => [['/'], unknownSymbol]),
98
+ range('09')(() => a => [[fromCharCode(a)], unknownSymbol]),
99
+ range(':')(() => () => [[':'], unknownSymbol]),
100
+ range(';')(() => () => [[';'], unknownSymbol]),
101
+ range('<')(() => () => [['<'], unknownSymbol]),
102
+ range('=')(() => () => [['='], unknownSymbol]),
103
+ range('>')(() => () => [['>'], unknownSymbol]),
104
+ range('?')(() => () => [['?'], unknownSymbol]),
105
+ range('[')(() => () => [['['], unknownSymbol]),
106
+ range(']')(() => () => [[']'], unknownSymbol]),
107
+ range('^')(() => () => [['^'], unknownSymbol]),
108
+ range('`')(() => () => [['`'], unknownSymbol]),
109
+ range('{')(() => () => [['{'], unknownSymbol]),
110
+ range('|')(() => () => [['|'], unknownSymbol]),
111
+ range('}')(() => () => [['}'], unknownSymbol]),
112
+ range('~')(() => () => [['~'], unknownSymbol]),
113
+ ])
2
114
 
3
115
  module.exports = {
116
+ /** @readonly */
117
+ init,
4
118
  }
package/fsc/test.f.cjs CHANGED
@@ -1,6 +1,18 @@
1
1
  const _ = require('./module.f.cjs')
2
+ const { one } = require('../text/ascii/module.f.cjs')
3
+ const { get } = require('../types/range_map/module.f.cjs')
4
+ const { stringify } = require('../json/module.f.cjs')
5
+ const s = stringify(i => i)
6
+
7
+ /** @type {(v: string) => string} */
8
+ const f = v => {
9
+ const n = one(v)
10
+ return s(_.init(undefined)(n)[0])
11
+ }
2
12
 
3
13
  module.exports = {
4
14
  a: () => {
15
+ const x = f('1')
16
+ if (x != '["1"]') { throw x }
5
17
  }
6
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.477",
3
+ "version": "0.0.478",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -13,7 +13,9 @@ const one = s => at(s)(0)
13
13
  /** @type {(s: string) => _range.Range} */
14
14
  const range = s => {
15
15
  const f = at(s)
16
- return [f(0), f(1)]
16
+ const f0 = f(0)
17
+ if (s.length === 1) { return [f0, f0] }
18
+ return [f0, f(1)]
17
19
  }
18
20
 
19
21
  module.exports = {
@@ -0,0 +1,12 @@
1
+ const { range } = require('./module.f.cjs')
2
+ const json = require('../../json/module.f.cjs')
3
+ const { sort } = require('../../types/object/module.f.cjs')
4
+
5
+ const stringify = json.stringify(sort)
6
+
7
+ module.exports = {
8
+ range: () => {
9
+ const r = stringify(range("A"))
10
+ if (r !== '[65,65]') { throw r }
11
+ }
12
+ }
@@ -3,8 +3,7 @@ const json = require('../../json/module.f.cjs')
3
3
  const { sort } = require('../../types/object/module.f.cjs')
4
4
  const { list } = require('../../types/module.f.cjs')
5
5
 
6
- /** @type {(a: readonly json.Unknown[]) => string} */
7
- const stringify = a => json.stringify(sort)(a)
6
+ const stringify = json.stringify(sort)
8
7
 
9
8
  module.exports = {
10
9
  toCodePoint: [
@@ -3,7 +3,12 @@
3
3
  /** @type {(range: Range) => (i: number) => boolean} */
4
4
  const contains = ([b, e]) => i => b <= i && i <= e
5
5
 
6
+ /** @type {(i: number) => Range} */
7
+ const one = a => [a, a]
8
+
6
9
  module.exports = {
7
10
  /** @readonly */
8
11
  contains,
12
+ /** @readonly */
13
+ one,
9
14
  }
@@ -37,7 +37,7 @@ const _range = require('../range/module.f.cjs')
37
37
 
38
38
  /**
39
39
  * @template T
40
- * @typedef {(a: RangeMap<T>) => (b: RangeMap<T>) => RangeMap<T>} RangeMerge
40
+ * @typedef {operator.Reduce<RangeMap<T>>} RangeMerge
41
41
  */
42
42
 
43
43
  /** @type {<T>(union: operator.Reduce<T>) => (equal: operator.Equal<T>) => sortedList.ReduceOp<Entry<T>, RangeState<T>>} */
@@ -33,7 +33,7 @@ module.exports = {
33
33
  intersect: [
34
34
  () => {
35
35
  const result = stringify(toArray(_.intersect(unsafeCmp)([2, 3, 4])([1, 3, 5])))
36
- console.log(result)
36
+ // console.log(result)
37
37
  if (result !== '[3]') { throw result }
38
38
  },
39
39
  () => {