summaryrefslogtreecommitdiffstats
path: root/parser.y
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2014-07-07 16:03:32 -0500
committerNicolas Williams <nico@cryptonector.com>2014-07-07 16:03:32 -0500
commit8780bc0b8ebd3492c58f1ce221e0d87de170c6ac (patch)
treecd691c10a4cde13fcc96afb8fcfd7e56a69523a7 /parser.y
parent821cd31e67444d60656baf463e4603899697b045 (diff)
Better check for lib has only functions (fix #138)
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y10
1 files changed, 7 insertions, 3 deletions
diff --git a/parser.y b/parser.y
index 7c53d285..6abcb473 100644
--- a/parser.y
+++ b/parser.y
@@ -206,7 +206,7 @@ static block gen_update(block object, block val, int optype) {
%%
TopLevel:
Exp {
- *answer = $1;
+ *answer = BLOCK(gen_op_simple(TOP), $1);
} |
FuncDefs {
*answer = $1;
@@ -222,7 +222,10 @@ FuncDef FuncDefs {
Exp:
FuncDef Exp %prec ';' {
- $$ = block_bind($1, $2, OP_IS_CALL_PSEUDO);
+ if (block_is_funcdef($2))
+ $$ = block_bind($1, $2, OP_IS_CALL_PSEUDO);
+ else
+ $$ = block_bind($1, BLOCK(gen_op_simple(TOP), $2), OP_IS_CALL_PSEUDO);
} |
Term "as" '$' IDENT '|' Exp {
@@ -682,9 +685,10 @@ int jq_parse(struct locfile* locations, block* answer) {
int jq_parse_library(struct locfile* locations, block* answer) {
int errs = jq_parse(locations, answer);
if (errs) return errs;
- if (!block_has_only_binders(*answer, OP_IS_CALL_PSEUDO)) {
+ if (block_has_main(*answer)) {
locfile_locate(locations, UNKNOWN_LOCATION, "error: library should only have function definitions, not a main expression");
return 1;
}
+ assert(block_has_only_binders(*answer, OP_IS_CALL_PSEUDO));
return 0;
}