2 * Copyright (C) 2019 Richard W.M. Jones
3 * Copyright (C) 2019 Red Hat Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 (* This is initialized with Lexer.read once the program
25 * starts. Doing this avoids a circular dependency caused
28 let lexer_read = ref None
32 %token <Ast.substs> CODE
45 %token <Ast.substs> STRING
46 %token <string> TACTIC
49 (* Start nonterminals. *)
50 %start <Ast.expr Ast.Env.t> file
51 %start <Ast.expr> expr
59 | (* none *) { Ast.Env.empty }
60 | stmts INCLUDE STRING
63 let filename = Ast.substitute env $loc $3 in
64 let rec find_on_include_path =
68 let path = inc // filename in
69 if Sys.file_exists path then path
70 else find_on_include_path incs
73 if Filename.is_implicit filename then
74 find_on_include_path Cmdline.includes
76 let fp = open_in filename in
77 let lexbuf = Lexing.from_channel fp in
78 lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = filename };
80 match !lexer_read with None -> assert false | Some r -> r in
81 let env' = file reader lexbuf in
83 Ast.Env.merge env env'
85 | stmts stmt { let name, expr = $2 in Ast.Env.add name expr $1 }
89 | option(goal_stmt) patterns COLON barelist option(CODE)
93 sprintf "_goal@%d" $startpos.pos_lnum, []
95 name, Ast.EGoal ($loc, (params, $2, $4, $5))
99 let name, params = $1 in
100 name, Ast.EGoal ($loc, (params, [], [], Some $2))
102 | TACTIC_KEYWORD TACTIC params_decl EQUALS CODE
104 $2, Ast.ETactic ($loc, ($3, $5))
106 | LET ID EQUALS expr { $2, $4 }
110 | GOAL ID option(params_decl) EQUALS
111 { $2, match $3 with None -> [] | Some ps -> ps }
114 | LEFT_PAREN separated_list(COMMA, param_decl) RIGHT_PAREN { $2 }
120 | separated_list(COMMA, pattern) { $1 }
123 | STRING { Ast.PTactic ($loc, "*file", [$1]) }
124 | ID pattern_params { Ast.PTactic ($loc, $1, $2) }
127 | LEFT_PAREN separated_list(COMMA, pattern_param) RIGHT_PAREN { $2 }
134 | ID params { Ast.ECallGoal ($loc, $1, $2) }
135 | ID { Ast.EVar ($loc, $1) }
136 | TACTIC params { Ast.ECallTactic ($loc, $1, $2) }
137 | STRING { Ast.ESubsts ($loc, $1) }
138 | LEFT_ARRAY barelist RIGHT_ARRAY { Ast.EList ($loc, $2) }
141 | separated_list(COMMA, expr) { $1 }
144 | LEFT_PAREN separated_list(COMMA, expr) RIGHT_PAREN { $2 }