Skip to content
Browse files

Fix ambiguity from colon after close paren by repurposing tokens

Oh well. It looked nice, but it was doomed. Now `%` is used for error forwarding,
and `@` is used to indicate the this-value identifier.
  • Loading branch information...
1 parent 09a85b1 commit 4eb6ad85cb5f1b95f72a0faa30df89d90f5c7ffe @willconant committed
Showing with 27 additions and 24 deletions.
  1. +7 −7 README.md
  2. +4 −4 neatjs.neat
  3. +16 −13 parser.js
View
14 README.md
@@ -42,7 +42,7 @@ Instead, you explicitly choose a name for the this-value in function declaration
This:
- Dog(name):dog {
+ Dog(name)@dog {
dog.name = name;
}
@@ -54,7 +54,7 @@ Compiles to:
This:
- Dog.prototype.careForPuppies = ():dog {
+ Dog.prototype.careForPuppies = ()@dog {
dog.puppies.forEach((puppy) {
// the value of dog in this context is clear
dog.clean(puppy);
@@ -101,7 +101,7 @@ For asynchronous programming in environments like Node.js, there is a better syn
This:
fs.readFile('filename', onReadFile);
- onReadFile(@, text) {
+ onReadFile(%, text) {
console.log(text);
}
@@ -117,7 +117,7 @@ This:
readFileOrDir(filename, callback) {
fs.stat(filename, onStat);
- onStat(@callback, stats) {
+ onStat(%callback, stats) {
if (stats.isDirectory()) {
fs.readdir(filename, onReaddir);
}
@@ -126,11 +126,11 @@ This:
}
}
- onReaddir(@callback, filenames) {
+ onReaddir(%callback, filenames) {
callback(null, 'directory', filenames);
}
- onReadFile(@callback, buffer) {
+ onReadFile(%callback, buffer) {
callback(null, 'file', buffer);
}
}
@@ -345,7 +345,7 @@ Calls func. If func succeeds, the result is passed to callback as the second par
## Justification ##
- You already need a source validator like JSHint or JSLint.
-- The `function` keyword eight characters too long.
+- The `function` keyword is eight characters too long.
- The `this` keyword sucks in functional programming.
- It is surprisingly hard to type `prototype`.
- Including `if (err) throw err;` at the top of every function is an unreasonable amount of boilerplate.
View
8 neatjs.neat
@@ -84,7 +84,7 @@ chompPath(path) {
}
onReaddir(dirpath) {
- return (@, filenames) {
+ return (%, filenames) {
each(filter(filenames, (f) -> /\.neat$/.test(f)), (filename) {
var filepath = dirpath + '/' + filename;
fs.stat(filepath, onStats(filepath));
@@ -93,7 +93,7 @@ onReaddir(dirpath) {
}
onStats(filepath) {
- return (@, stats) {
+ return (%, stats) {
if (stats.isDirectory()) {
fs.readdir(filepath, onReaddir(filepath));
}
@@ -104,7 +104,7 @@ onStats(filepath) {
}
onReadFile(filepath) {
- return (@, source) {
+ return (%, source) {
var result = parser.compile(filepath, source);
if (result.error) {
errors.push(result.error.message);
@@ -120,7 +120,7 @@ onReadFile(filepath) {
}
onWriteFile(filepath) {
- return (@) {
+ return (%) {
// console.log("wrote", filepath);
};
}
View
29 parser.js
@@ -503,9 +503,12 @@ Parser.prototype.parseExpr = function(prec) {
this.next();
expr = new ast.StringExpr([this.findString('/')]);
break;
- case '@':
+ case '%':
expr = this.parsePassExpr();
break;
+ case '...':
+ expr = this.parseYadaExpr();
+ break;
case '[':
expr = this.parseArrayExpr();
break;
@@ -619,15 +622,7 @@ Parser.prototype.parseExpr = function(prec) {
}
expr = new ast.PrototypePropertyExpr(elts);
break;
-
- case '...':
- if (expr.astType !== 'IdentExpr') {
- this.error("unexpected '...'");
- }
- elts = [expr.elts[0], this.next()];
- expr = new ast.YadaExpr(elts);
- break;
-
+
default:
break GOBBLE;
}
@@ -638,7 +633,7 @@ Parser.prototype.parseExpr = function(prec) {
Parser.prototype.parsePassExpr = function() {
var elts = [
- this.expect('@')
+ this.expect('%')
];
if (this.peek().type === 'IDENT') {
elts.push(this.next());
@@ -646,6 +641,14 @@ Parser.prototype.parsePassExpr = function() {
return new ast.PassExpr(elts);
};
+Parser.prototype.parseYadaExpr = function() {
+ var elts = [
+ this.expect('...'),
+ this.expect('IDENT')
+ ];
+ return new ast.YadaExpr(elts);
+};
+
Parser.prototype.parseArrayExpr = function() {
var elts = [
this.expect('['),
@@ -717,7 +720,7 @@ Parser.prototype.parseGroupExpr = function() {
var closeParen = this.expect(')');
var thisElts = null;
- if (this.peek().type === ':') {
+ if (this.peek().type === '@') {
// this is going to be a function expr with a this var
thisElts = [this.next(), this.expect('IDENT')];
}
@@ -790,7 +793,7 @@ Parser.prototype.parseExprStatement = function() {
// do we have a thisElt?
thisElts = null;
- if (this.peek().type === ':') {
+ if (this.peek().type === '@') {
thisElts = [this.next(), this.expect('IDENT')];
}

0 comments on commit 4eb6ad8

Please sign in to comment.
Something went wrong with that request. Please try again.