transpile.ts 728 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Koya Sakuma
  5. */
  6. /**
  7. * Adapted from MolQL src/transpile.ts
  8. */
  9. import { Transpiler } from './transpilers/transpiler';
  10. import { _transpiler } from './transpilers/all';
  11. const transpiler: {[index: string]: Transpiler} = _transpiler;
  12. export function parse(lang: string, str: string) {
  13. try {
  14. const query = transpiler[lang](str);
  15. console.log(str);
  16. console.log(query);
  17. // console.log(util.inspect(query, {depth: 20, color: true}))
  18. console.log('\n');
  19. return query;
  20. } catch (e) {
  21. console.log(str);
  22. console.log(e.message);
  23. console.log('\n');
  24. }
  25. }