File: parser.mly

package info (click to toggle)
ben 1.14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 672 kB
  • sloc: ml: 4,116; sh: 345; javascript: 78; ansic: 39; makefile: 29; python: 18
file content (76 lines) | stat: -rw-r--r-- 2,578 bytes parent folder | download
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
/**************************************************************************/
/*  Copyright © 2009 Stéphane Glondu <steph@glondu.net>                   */
/*                                                                        */
/*  This program is free software: you can redistribute it and/or modify  */
/*  it under the terms of the GNU Affero General Public License as        */
/*  published by the Free Software Foundation, either version 3 of the    */
/*  License, or (at your option) any later version, with the additional   */
/*  exemption that compiling, linking, and/or using OpenSSL is allowed.   */
/*                                                                        */
/*  This program is distributed in the hope that it will be useful, but   */
/*  WITHOUT ANY WARRANTY; without even the implied warranty of            */
/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     */
/*  Affero General Public License for more details.                       */
/*                                                                        */
/*  You should have received a copy of the GNU Affero General Public      */
/*  License along with this program.  If not, see                         */
/*  <http://www.gnu.org/licenses/>.                                       */
/**************************************************************************/

%{
  open Types
  open Core
%}

%token <Types.field> FIELD
%token <Types.regexp> REGEXP
%token MATCH OR AND NOT LPAREN RPAREN EOF SOURCE
%token TRUE FALSE AUTO LBRACKET RBRACKET SEMICOLON
%token <string> STRING IDENT
%token LE LT GT GE EQ

%left OR
%left AND
%nonassoc NOT

%start <Types.expr> full_expr
%start <Types.config> config_file

%%

full_expr:
| e = expr EOF { e }

expr:
| e1 = expr OR e2 = expr { EOr (e1, e2) }
| e1 = expr AND e2 = expr { EAnd (e1, e2) }
| TRUE { Etrue }
| FALSE { Efalse }
| AUTO { Eauto }
| c = comparison x = STRING { EVersion (c, x) }
| NOT e = expr { ENot e }
| n = FIELD MATCH p = predicate { EMatch (n, p) }
| LPAREN e = expr RPAREN { e }
| SOURCE { ESource }
| LBRACKET xs = separated_list(SEMICOLON, expr) RBRACKET { EList xs }
| x = STRING { EString x }

predicate:
| x = REGEXP { ERegexp x }
| x = STRING { EString x }
| x = STRING c = comparison v = STRING { EDep (x, c, v) }

comparison:
| LE { Le }
| LT { Lt }
| EQ { Eq }
| GE { Ge }
| GT { Gt }

config_item:
| i = IDENT EQ e = expr SEMICOLON { (i, e) }

config_file:
| xs = list(config_item) EOF {
  List.fold_left (fun accu (key, value) -> StringMap.add key value accu) StringMap.empty xs
}