oc.js 727 B

1234567891011121314151617181920212223242526
  1. var Code = require("code.js");
  2. var Context = require("context.js")
  3. var Errors = require("errors.js");
  4. var Grammar = require("grammar.js");
  5. var Lexer = require("lexer.js");
  6. var Stream = require("stream.js").Stream;
  7. exports.compile = function(text){
  8. var stream = new Stream(text);
  9. var context = new Context.Context();
  10. try {
  11. if (!Grammar.module(stream, context))
  12. throw new Errors.Error("syntax error, position: " + stream.pos());
  13. }
  14. catch (x) {
  15. if (x instanceof Errors.Error) {
  16. console.log(context.getResult());
  17. console.error(stream.describePosition());
  18. }
  19. throw x;
  20. }
  21. Lexer.skipSpaces(stream, context);
  22. if (!stream.eof())
  23. throw new Errors.Error("text beyond module end");
  24. return context.getResult();
  25. }