types.ts 883 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { Type } from "./type";
  2. import { MultiType } from "./multiType";
  3. import { IType } from "./itype";
  4. import { Maybe } from "../util/maybe";
  5. const INTEGER = new Type("integer", 0);
  6. const REAL = new Type("real", 1);
  7. const STRING = new Type("text", 2);
  8. const BOOLEAN =new Type("boolean", 3);
  9. const VOID = new Type("void", 4);
  10. const UNDEFINED = new Type("undefined", 5);
  11. const ALL = new MultiType([INTEGER, REAL, STRING, BOOLEAN]);
  12. interface TypeMap {
  13. [key: string]: IType
  14. }
  15. export const Types = Object.freeze({
  16. INTEGER: INTEGER,
  17. REAL: REAL,
  18. STRING: STRING,
  19. BOOLEAN: BOOLEAN,
  20. VOID: VOID,
  21. UNDEFINED: UNDEFINED,
  22. ALL: ALL
  23. });
  24. export function fromOrdToType (ord:number): Maybe<IType> {
  25. const typeMap = Types as TypeMap;
  26. for(let t in typeMap) {
  27. if(typeMap[t].ord! === ord){
  28. return Maybe.some<IType>(typeMap[t]);
  29. }
  30. }
  31. return Maybe.none<IType>();
  32. }