forked from ocaml-flambda/flambda-backend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtsl_parser.mly
114 lines (87 loc) · 3.15 KB
/
tsl_parser.mly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**************************************************************************/
/* */
/* OCaml */
/* */
/* Sebastien Hinderer, projet Gallium, INRIA Paris */
/* */
/* Copyright 2016 Institut National de Recherche en Informatique et */
/* en Automatique. */
/* */
/* All rights reserved. This file is distributed under the terms of */
/* the GNU Lesser General Public License version 2.1, with the */
/* special exception on linking described in the file LICENSE. */
/* */
/**************************************************************************/
/* Parser for the Tests Specification Language */
%{
open Location
open Tsl_ast
let mkstring s = make_string ~loc:(symbol_rloc()) s
let mkidentifier id = make_identifier ~loc:(symbol_rloc()) id
let mkenvstmt envstmt =
let located_env_statement =
make_environment_statement ~loc:(symbol_rloc()) envstmt in
Environment_statement located_env_statement
%}
%token <[`Above | `Below]> TSL_BEGIN_C_STYLE
%token TSL_END_C_STYLE
%token <[`Above | `Below]> TSL_BEGIN_OCAML_STYLE
%token TSL_END_OCAML_STYLE
%token COMMA LEFT_BRACE RIGHT_BRACE SEMI
%token <int> TEST_DEPTH
%token EQUAL PLUSEQUAL
/* %token COLON */
%token INCLUDE SET UNSET WITH
%token <string> IDENTIFIER
%token <string> STRING
%start tsl_block tsl_script
%type <Tsl_ast.tsl_block> tsl_block
%type <Tsl_ast.t> tsl_script
%%
node:
| statement_list tree_list { Ast ($1, $2) }
tree_list:
| { [] }
| tree tree_list { $1 :: $2 }
tree:
| LEFT_BRACE node RIGHT_BRACE { $2 }
statement_list:
| { [] }
| statement statement_list { $1 :: $2 }
statement:
| env_item SEMI { $1 }
| identifier with_environment_modifiers SEMI { Test (0, $1, $2) }
tsl_script:
| TSL_BEGIN_C_STYLE node TSL_END_C_STYLE { $2 }
| TSL_BEGIN_OCAML_STYLE node TSL_END_OCAML_STYLE { $2 }
tsl_block:
| TSL_BEGIN_C_STYLE tsl_items TSL_END_C_STYLE { $2 }
| TSL_BEGIN_OCAML_STYLE tsl_items TSL_END_OCAML_STYLE { $2 }
tsl_items:
| { [] }
| tsl_item tsl_items { $1 :: $2 }
tsl_item:
| test_item { $1 }
| env_item { $1 }
test_item:
TEST_DEPTH identifier with_environment_modifiers { (Test ($1, $2, $3)) }
with_environment_modifiers:
| { [] }
| WITH identifier opt_environment_modifiers { $2::(List.rev $3) }
opt_environment_modifiers:
| { [] }
| opt_environment_modifiers COMMA identifier { $3::$1 }
env_item:
| identifier EQUAL string
{ mkenvstmt (Assignment (false, $1, $3)) }
| identifier PLUSEQUAL string
{ mkenvstmt (Append ($1, $3)) }
| SET identifier EQUAL string
{ mkenvstmt (Assignment (true, $2, $4)) }
| UNSET identifier
{ mkenvstmt (Unset $2) }
| INCLUDE identifier
{ mkenvstmt (Include $2) }
identifier: IDENTIFIER { mkidentifier $1 }
string: STRING { mkstring $1 }
%%