Removed dep on API
[ninja.git] / src / op5 / ninja_sdk / parsegen / js / LalrJSGenerator.php
blob542ffb2c4ef8d3292d7f83013edf4425632a58b3
1 <?php
3 class LalrJSGenerator extends js_class_generator {
4 public function __construct( $parser_name ) {
5 $this->classname = $parser_name;
8 public function generate($skip_generated_note = false) {
9 parent::generate($skip_generated_note);
11 $this->init_class(array('preprocessor','visitor'));
12 $this->write( 'this.preprocessor = preprocessor;' );
13 $this->write( 'this.visitor = visitor;');
14 $this->generate_parse();
15 $this->finish_class();
18 private function generate_parse() {
19 $this->init_function( 'parse', array( 'string' ) );
20 $this->write( 'var lexer = new '.$this->classname.'Lexer( string, this.preprocessor );' );
21 $this->write( 'var parser = new '.$this->classname.'Parser( this.visitor );' );
22 $this->write( 'return parser.parse( lexer );' );
23 $this->finish_function();