diff --git a/src/analyzer.js b/src/analyzer.js index 7a13e96..3247740 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -1,4 +1,5 @@ import { + comment, literal, symbolExpr, Program, @@ -105,7 +106,7 @@ function desugarProgram(programs, pinfo, isTopLevelExpr) { var acc = [ [], (pinfo || new structures.pinfo()) ]; - var res = programs.reduce((function(acc, p) { + var res = programs.filter(function(p){ return !(p instanceof comment); }).reduce((function(acc, p) { var desugaredAndPinfo = p.desugar(acc[1]); // if it's an expression, insert a print-values call so it shows up in the repl if (structures.isExpression(p) && isTopLevelExpr) { diff --git a/src/lex.js b/src/lex.js index 9db1eed..b66eb62 100644 --- a/src/lex.js +++ b/src/lex.js @@ -184,9 +184,7 @@ var jsnums = require('./runtime/js-numbers'); i = chewWhiteSpace(str, 0); while (i < str.length) { sexp = readSExpByIndex(str, i); - if (!(sexp instanceof comment)) { - sexps.push(sexp); - } + sexps.push(sexp); i = chewWhiteSpace(str, sexp.location.startChar + sexp.location.span); } sexps.location = new Location(startCol, startRow, 0, i, source); @@ -254,7 +252,7 @@ var jsnums = require('./runtime/js-numbers'); dot2Idx = dot1Idx ? list.length : false; // if we've seen dot1, save this idx to dot2Idx dot1Idx = dot1Idx || list.length; // if we haven't seen dot1, save this idx to dot1Idx } - if (!(sexp instanceof comment)) { // if it's not a comment, add it to the list + if (!(sexp instanceof Comment)) { // if it's not a comment, add it to the list sexp.parent = list; // set this list as it's parent list.push(sexp); // and add the sexp to the list } @@ -767,9 +765,9 @@ var jsnums = require('./runtime/js-numbers'); } i++; column++; // hop over '|#' - var cmmt = new comment(txt); - cmmt.location = new Location(startCol, startRow, iStart, i - iStart); - return cmmt; + var comment = new compiler.comment(txt); + comment.location = new Location(startCol, startRow, iStart, i - iStart); + return comment; } // readSExpComment : String Number -> Atom @@ -797,7 +795,7 @@ var jsnums = require('./runtime/js-numbers'); , "Error-GenericReadError"); } // if we're here, then we read a proper s-expr - var atom = new comment("(" + nextSExp.toString() + ")"); + var atom = new compiler.comment("(" + nextSExp.toString() + ")"); i = nextSExp.location.endChar; atom.location = new Location(startCol, startRow, iStart, i - iStart); return atom; @@ -823,7 +821,7 @@ var jsnums = require('./runtime/js-numbers'); throwError(new types.Message(["read: Unexpected EOF when reading a line comment"]) , new Location(startCol, startRow, iStart, i - iStart)); } - var atom = new comment(txt); + var atom = new compiler.comment(txt); atom.location = new Location(startCol, startRow, iStart, i + 1 - iStart); // at the end of the line, reset line/col values line++; @@ -874,7 +872,7 @@ var jsnums = require('./runtime/js-numbers'); symbol.location = new Location(column - 1, startRow, iStart, i - iStart); // read the next non-comment sexp - while (!nextSExp || (nextSExp instanceof comment)) { + while (!nextSExp || (nextSExp instanceof Comment)) { i = chewWhiteSpace(str, i); try { nextSExp = readSExpByIndex(str, i); diff --git a/src/parser.js b/src/parser.js index 7e3c746..8700fbe 100644 --- a/src/parser.js +++ b/src/parser.js @@ -56,6 +56,7 @@ var compiler = require('./compiler'); function isSymbol(x) { return x instanceof symbolExpr; } function isLiteral(x) { return x instanceof literal; } function isUnsupported(x) { return x instanceof unsupportedExpr; } + function isComment(x) { return x instanceof comment; } function isCons(x) { return x instanceof Array && x.length >= 1; } function rest(ls) { return ls.slice(1); } @@ -74,7 +75,8 @@ var compiler = require('./compiler'); // parse* : sexp list -> Program list function parseStar(sexps) { function parseSExp(sexp) { - return isDefinition(sexp) ? parseDefinition(sexp) : + return isComment(sexp) ? sexp : + isDefinition(sexp) ? parseDefinition(sexp) : isExpr(sexp) ? parseExpr(sexp) : isRequire(sexp) ? parseRequire(sexp) : isProvide(sexp) ? parseProvide(sexp) : @@ -821,7 +823,8 @@ var compiler = require('./compiler'); } function parseExprSingleton(sexp) { - var singleton = isUnsupported(sexp) ? sexp : + var singleton = isComment(sexp) ? sexp : + isUnsupported(sexp) ? sexp : isVector(sexp) ? parseVector(sexp) : isSymbol(sexp) ? sexp : isLiteral(sexp) ? sexp : diff --git a/src/structures.js b/src/structures.js index 3c697c5..7f7d37b 100644 --- a/src/structures.js +++ b/src/structures.js @@ -295,7 +295,6 @@ export class ifExpr extends Program { this.stx = stx; } toString() { - console.log(this); return "(if "+this.predicate.toString()+" "+this.consequence.toString()+" "+this.alternative.toString()+")"; } }