prebirth: Ignore comments in JS parser

* build-aux/bootstrap/prebirth.js (parseLisp): Ingore comment tokens.
  (_lex): Recognize comments.
master
Mike Gerwitz 2017-08-29 01:27:54 -04:00
parent 3c5089417c
commit 6a736a8fcd
Signed by: mikegerwitz
GPG Key ID: 8C917B7F5DC51BA2
1 changed files with 10 additions and 0 deletions

View File

@ -97,6 +97,10 @@ class Parser
// a very simple bootstrap lisp) // a very simple bootstrap lisp)
switch ( type ) switch ( type )
{ {
// ignore comments
case 'comment':
return result;
// closing parenthesis (end of sexp) // closing parenthesis (end of sexp)
case 'close': case 'close':
if ( depth === 0 ) { if ( depth === 0 ) {
@ -197,6 +201,12 @@ class Parser
return []; return [];
} }
// comment until end of line
if ( trim[ 0 ] === ';' ) {
const eol = trim.match( /^(.*?)(\n|$)/ );
return this._token( 'comment', eol[ 1 ], trim, pos );
}
// left and right parenthesis are handled in the same manner: they // left and right parenthesis are handled in the same manner: they
// produce distinct tokens with single-character lexemes // produce distinct tokens with single-character lexemes
if ( trim[ 0 ] === '(' ) { if ( trim[ 0 ] === '(' ) {