simplify: no distinction between generic types and 'normal' types.
This commit is contained in:
parent
b4826605af
commit
a664ddac8a
27 changed files with 535 additions and 360 deletions
|
|
@ -1,7 +1,10 @@
|
|||
// A simple, hacked-together recursive parser for types.
|
||||
|
||||
import { Bool, Char, Double, Int, SymbolT, Type, Unit } from "../primitives/primitive_types.js";
|
||||
import { Bool, Char, Double, Int, UUID, Type, Unit } from "../primitives/primitive_types.js";
|
||||
import { Dynamic } from "../primitives/primitive_types.js";
|
||||
import { getHumanReadableName } from "../primitives/symbol.js";
|
||||
import { getSymbol } from "../primitives/type.js";
|
||||
import { TYPE_VARS } from "../primitives/typevars.js";
|
||||
import { dictType, fnType, lsType, prodType, sumType } from "../structures/type_constructors.js";
|
||||
import { setType } from "../structures/type_constructors.js";
|
||||
|
||||
|
|
@ -11,12 +14,6 @@ export const makeTypeParser = ({
|
|||
extraBracketOperators=[],
|
||||
extraInfixOperators=[],
|
||||
}) => {
|
||||
const a = Symbol('a');
|
||||
const b = Symbol('b');
|
||||
const c = Symbol('c');
|
||||
const d = Symbol('d');
|
||||
const e = Symbol('e');
|
||||
|
||||
const primitives = new Map([
|
||||
['Int', Int],
|
||||
['Double', Double],
|
||||
|
|
@ -27,12 +24,9 @@ export const makeTypeParser = ({
|
|||
['Unit', Unit],
|
||||
['Type', Type],
|
||||
['Dynamic', Dynamic],
|
||||
['SymbolT', SymbolT],
|
||||
['a', a],
|
||||
['b', b],
|
||||
['c', c],
|
||||
['d', d],
|
||||
['e', e],
|
||||
['UUID', UUID],
|
||||
|
||||
...TYPE_VARS.map(type => [getHumanReadableName(getSymbol(type)), type]),
|
||||
|
||||
...extraPrimitives,
|
||||
]);
|
||||
|
|
@ -41,11 +35,7 @@ export const makeTypeParser = ({
|
|||
['(', [')', null]],
|
||||
['[', [']', lsType]],
|
||||
['{', ['}', setType]],
|
||||
|
||||
// can only occur at beginning
|
||||
// we use these to extract the type variables
|
||||
['∀', [':', null]],
|
||||
|
||||
|
||||
...extraBracketOperators,
|
||||
]);
|
||||
|
||||
|
|
@ -187,13 +177,6 @@ export const makeTypeParser = ({
|
|||
|
||||
const parse = expr => {
|
||||
const tokens = tokenize(expr);
|
||||
if (tokens[0] === '∀') {
|
||||
// generic type
|
||||
const [typeVarTokens, _, rest] = consumeGroup(tokens);
|
||||
const typeVars = [].concat(__parse(typeVarTokens))
|
||||
const type = __parse(rest);
|
||||
return { typeVars, type };
|
||||
}
|
||||
return __parse(tokens);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue