X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Fparser.mly;h=c47ac597f3b818682ed0028da63aaff20c19d557;hb=24cc20b33e3d81ed7d754391bef929276c1f4f42;hp=9ce3996d106d5c47a339ed9466315c87ee9cc4c3;hpb=94430834302e922af6c27a1c88e13f862a57dd0f;p=goals.git diff --git a/src/parser.mly b/src/parser.mly index 9ce3996..c47ac59 100644 --- a/src/parser.mly +++ b/src/parser.mly @@ -25,16 +25,17 @@ open Printf %token CODE %token COLON %token COMMA -%token ID %token EQUALS %token EOF %token GOAL +%token ID %token LEFT_ARRAY %token LEFT_PAREN %token LET %token RIGHT_ARRAY %token RIGHT_PAREN %token STRING +%token TACTIC (* Start nonterminals. *) %start file @@ -48,8 +49,8 @@ file: stmts: | list(stmt) { List.fold_left ( - fun env (name, expr) -> Ast.StringMap.add name expr env - ) Ast.StringMap.empty $1 + fun env (name, expr) -> Ast.Env.add name expr env + ) Ast.Env.empty $1 } ; stmt: @@ -57,34 +58,35 @@ stmt: { let name, params = match $1 with | None -> - let pos = $startpos in - sprintf "_goal@%d" pos.pos_lnum, [] + sprintf "_goal@%d" $startpos.pos_lnum, [] | Some x -> x in - name, Ast.EGoal (params, $2, $4, $5) + name, Ast.EGoal ($loc, (params, $2, $4, $5)) } | goal_stmt CODE { let name, params = $1 in - name, Ast.EGoal (params, [], [], Some $2) + name, Ast.EGoal ($loc, (params, [], [], Some $2)) } | LET ID EQUALS expr { $2, $4 } ; goal_stmt: - | GOAL ID option(param_decl) EQUALS + | GOAL ID option(params_decl) EQUALS { $2, match $3 with None -> [] | Some ps -> ps } ; -param_decl: - | LEFT_PAREN separated_list(COMMA, ID) RIGHT_PAREN { $2 } +params_decl: + | LEFT_PAREN separated_list(COMMA, param_decl) RIGHT_PAREN { $2 } ; +param_decl: + | ID { $1 } patterns: | separated_list(COMMA, pattern) { $1 } ; pattern: - | STRING { Ast.PTactic ("file", [$1]) } - | ID pattern_params { Ast.PTactic ($1, $2) } - | ID { Ast.PVarSubst $1 } + | STRING { Ast.PTactic ($loc, "file", [$1]) } + | ID pattern_params { Ast.PTactic ($loc, $1, $2) } + | ID { Ast.PVar ($loc, $1) } ; pattern_params: | LEFT_PAREN separated_list(COMMA, pattern_param) RIGHT_PAREN { $2 } @@ -94,10 +96,11 @@ pattern_param: ; expr: - | ID params { Ast.ECall ($1, $2) } - | ID { Ast.EVar $1 (* This might be replaced with ECall later. *) } - | STRING { Ast.ESubsts $1 } - | LEFT_ARRAY barelist RIGHT_ARRAY { Ast.EList $2 } + | ID params { Ast.ECall ($loc, $1, $2) } + | ID { Ast.EVar ($loc, $1) } + | TACTIC params { Ast.ETactic ($loc, $1, $2) } + | STRING { Ast.ESubsts ($loc, $1) } + | LEFT_ARRAY barelist RIGHT_ARRAY { Ast.EList ($loc, $2) } ; barelist: | separated_list(COMMA, expr) { $1 }