types.js 996 B

12345678910111213141516171819202122232425262728293031323334353637
  1. export const Types = Object.freeze({
  2. INTEGER: {value: "int", ord: 0},
  3. REAL: {value: "real", ord: 1},
  4. STRING: {value: "string", ord: 2},
  5. BOOLEAN: {value: "bool", ord: 3},
  6. VOID: {value: "void", ord: 4},
  7. ARRAY: {value: 'array', ord: 5},
  8. UNDEFINED: {value: 'undefined', ord: 6},
  9. ALL: {value: 'all', ord: 7}
  10. });
  11. export function toInt (str) {
  12. if(str.match('^0b|^0B')) {
  13. return parseInt(str.substring(2), 2);
  14. } else if (str.match('^0x|^0X')) {
  15. return parseInt(str.substring(2), 16);
  16. } else {
  17. return parseInt(str);
  18. }
  19. }
  20. export function toString (str) {
  21. let value = str.replace(/^"/, '');
  22. value = value.replace(/"$/, '');
  23. value = value.replace(/\\b/g, "\b");
  24. value = value.replace(/\\t/g, "\t");
  25. value = value.replace(/\\n/g, "\n");
  26. value = value.replace(/\\r/g, "\r");
  27. value = value.replace(/\\\"/g, "\"");
  28. value = value.replace(/\\\'/g, "\'");
  29. value = value.replace(/\\\\/g, "\\");
  30. return value;
  31. }
  32. export function toBool (str) {
  33. return true;
  34. }