transpile.ts 684 B

123456789101112131415161718192021222324252627
  1. /**
  2. * Copyright (c) 2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Koya Sakuma <koya.sakuma.work@gmail.com>
  5. *
  6. * Adapted from MolQL src/transpile.ts
  7. */
  8. import { Transpiler } from './transpilers/transpiler';
  9. import { _transpiler } from './transpilers/all';
  10. import { Expression } from './language/expression';
  11. import { Script } from './script';
  12. const transpiler: {[index: string]: Transpiler} = _transpiler;
  13. export function parse(lang: Script.Language, str: string): Expression {
  14. try {
  15. const query = transpiler[lang](str);
  16. return query;
  17. } catch (e) {
  18. console.error(e.message);
  19. throw e;
  20. }
  21. }