Skip to content

Commit

Permalink
Revert "back out changes that allowed comments to pass through the le…
Browse files Browse the repository at this point in the history
…xer"

This reverts commit d7328ae.
  • Loading branch information
schanzer committed Jan 19, 2016
1 parent da4465d commit 04abbf7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/analyzer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
comment,
literal,
symbolExpr,
Program,
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 8 additions & 10 deletions src/lex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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++;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand All @@ -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) :
Expand Down Expand Up @@ -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 :
Expand Down
1 change: 0 additions & 1 deletion src/structures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()+")";
}
}
Expand Down

0 comments on commit 04abbf7

Please sign in to comment.