-
Notifications
You must be signed in to change notification settings - Fork 7
/
abnf_syntaxtree.ml
54 lines (48 loc) · 1.71 KB
/
abnf_syntaxtree.ml
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
(** Copyright (c) 2008,2009 Anil Madhavapeddy <[email protected]>
** See the COPYING file included in this distribution for licensing details *)
(* basic syntax tree for ABNF *)
open Printf
type terminal =
| ALPHA (* [A-Z][a-z] *)
| UPALPHA (* [A-Z] *)
| LOALPHA (* [a-z] *)
| DIGIT (* [0-9] *)
| HEXDIGIT (* [0-9a-fA-F] *)
| DQUOTE
| SP
| HTAB
| WSP
| LWSP
| VCHAR
| CHAR
| OCTET
| CTL (* <any US-ASCII control character (0-31) and DEL (127)> *)
| CR (* <US-ASCII CR, carriage return (13)> *)
| LF (* <US-ASCII LF, linefeed (10)> *)
| CRLF (* CR LF *)
| BIT
(* Type of the rules syntax tree *)
type rule =
| S_terminal of terminal (* Terminal character *)
| S_string of string (* Flat string *)
| S_concat of rule * rule (* Concatenation of rules *)
| S_reference of string (* reference to another rule *)
| S_alt of rule * rule (* Alt rules with a / *)
| S_bracket of rule (* Brackets : Needed because of the printer *)
| S_repetition of int option * int option * rule (* Repetition *)
| S_element_list of int option * int option * rule (* List rule, RFC2068 2.1 *)
| S_hex_range of int * int
| S_any_except of rule * rule (* any rule except rule *)
type derivation =
| D_terminal of terminal * string
| D_hex_range of int * int * string
| D_string of string
| D_concat of derivation * derivation
| D_reference of string * derivation
| D_repetition of derivation list
(* No any_except or alt, of which all branches are not represented, or seq/concat differentiation *)
(* Each line in an ABNF file is defined here *)
type rule_definition = {
s_name: string;
s_rule: rule;
}