JavaScript: Using an already generated parser (file)

117 views
Skip to first unread message

Udo Weik

unread,
May 6, 2013, 6:22:21 PM5/6/13
to pe...@googlegroups.com
Hello again,

I generated a parser and saved the source code with
toSource in a file. Now I want to use that code for
parsing an input string. How can I accomplish that?

With nodejs, its parser file
module.exports = (function(){ ... })();
and require it works...
var parser = require( "./Parser.js" ) ;
...
...but in plain JavaScript?


Many thanks and greetings
pegguy

Guilherme Vieira

unread,
May 6, 2013, 6:29:56 PM5/6/13
to Udo Weik, pe...@googlegroups.com
You could use Browserify so that you can require() browserified modules like your parser in the browser. Maybe there's a way to make PEG.js generate vanilla JavaScript modules that create a global variable with your parser, but I'm not sure about it, I'll leave that to someone else who knows PEG.js better.

If you want to know more about require() in the browser, I suggest you read about RequireJS. The techniques to modularize JavaScript are a bit controversial, but I find them rather exciting. My favorite technique is AMD.

-- 
Atenciosamente / Sincerely,
Guilherme Prá Vieira





--
You received this message because you are subscribed to the Google Groups "PEG.js: Parser Generator for JavaScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pegjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages