Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Expression
/ Number
/ Character
/ String
/ Ellipsis
/ Symbol

List
Expand Down Expand Up @@ -96,6 +97,9 @@ Character
CharacterValue
= val:$[^ \t\n\r()]+ { return val; }

Ellipsis
= '...' { return new SymbolObj('...'); }

Symbol
= !Boolean ident:Identifier { return new SymbolObj(ident); }

Expand All @@ -110,4 +114,8 @@ Initial
Subsequent
= Initial / [0-9] / "." / "+"

_ = [ \t\n\r]* // optional whitespace
_ = (Whitespace / LineComment)*

Whitespace = [ \t\n\r]+

LineComment = ';' (![\n\r] .)* ([\n\r] / !.)
7 changes: 6 additions & 1 deletion src/system/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export default class Parser {
this.error = null;
} catch (e) {
this.exprs = [];
this.error = new Error((e as Error).message);
const loc = (e as any).location?.start;
if (loc) {
this.error = new Error(`${(e as Error).message} at line ${loc.line} column ${loc.column}`);
} else {
this.error = new Error((e as Error).message);
}
}
this.i = 0;
}
Expand Down
13 changes: 13 additions & 0 deletions test/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ describe('Parser', function () {
const indent = FoxScheme.Parser.calculateIndentation('(display "foo \\"(")');
assert_equals(indent, 0);
});

it("Ignores semicolon comments", function() {
var p = new $fs.Parser("1 ;comment\n2");
assert_equals(p.nextObject(), 1);
assert_equals(p.nextObject(), 2);
});

it("Parses ellipsis token", function() {
var p = new $fs.Parser("...");
var o = p.nextObject();
assert_instanceof(o, FoxScheme.Symbol);
assert_equals(o.name(), "...");
});
});

/*
Expand Down