Skip to content

Commit

Permalink
fix [expr]: Fixed empty expressions bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Vihan committed Jul 10, 2016
1 parent 0aa8798 commit 3aa23de
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/stdlib/primitive/Array/lib.es6
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import api from '../../api';

export default new Map([
require('./lib/len')(api),
require('./lib/fuse')(api),
require('./lib/join')(api),
require('./lib/each')(api),
require('./lib/map')(api),
Expand Down
1 change: 0 additions & 1 deletion src/stdlib/primitive/Array/lib/join.es6
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ export default (api) => ["join", api.var(new api.func(
}

return api.init(api.string, stringified);

}
))];
28 changes: 16 additions & 12 deletions src/tokenizer/parsers/expr.es6
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ expr -> A B*/

let UNARY = CheddarCustomLexer(O, true);

class CheddarExpressionToken extends CheddarLexer {
get isExpression() { return true; }
}

let E = CheddarCustomLexer(CheddarExpressionToken, true);

class CheddarExpressionTokenAlpha extends CheddarLexer {
exec() {
this.open(false);

this.jumpWhite();

const E = CheddarExpressionToken;

return this.grammar(true,
[F],
['(', E, ')'],
Expand Down Expand Up @@ -115,17 +119,17 @@ class CheddarExpressionTokenBeta extends CheddarLexer {
get isExpression() { return true; }
}

export default class CheddarExpressionToken extends CheddarLexer {
exec() {
this.open(false);
CheddarExpressionToken.prototype.exec = function(empty) {
this.open(false);

this.jumpWhite();
this.jumpWhite();

return this.grammar(true,
[CheddarExpressionTokenAlpha, CheddarExpressionTokenBeta],
[] // ε
);
let GRAMMAR = [CheddarExpressionTokenAlpha, CheddarExpressionTokenBeta];
if (empty) {
return this.grammar(true, GRAMMAR);
} else {
return this.grammar(true, GRAMMAR, [/* ε */]);
}
};

get isExpression() { return true; }
}
export default CheddarExpressionToken;
5 changes: 4 additions & 1 deletion src/tokenizer/states/if.es6
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import CheddarExpressionToken from './expr';
import CheddarCodeblock from '../patterns/block';
import CheddarCustomLexer from '../parsers/custom';
import CheddarLexer from '../patterns/EXPLICIT';
import * as CheddarError from '../consts/err';

Expand All @@ -12,8 +13,10 @@ export default class StatementIf extends CheddarLexer {

this.jumpLiteral("if");

let EXPRESSION = CheddarCustomLexer(CheddarExpressionToken, true);

// Match the `expr { block }` format
let FORMAT = [CheddarExpressionToken, CheddarCodeblock, CheddarError.EXPECTED_BLOCK];
let FORMAT = [EXPRESSION, CheddarCodeblock, CheddarError.EXPECTED_BLOCK];

// Match initial `if`
let IF = this.grammar(true, FORMAT);
Expand Down

0 comments on commit 3aa23de

Please sign in to comment.