Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 55 lines (48 sloc) 1.753 kb
8d70150 @avsm Add an ABNF parser and a helper command-line utility to help visualize
avsm authored
1 (** Copyright (c) 2008,2009 Anil Madhavapeddy <anil@recoil.org>
2 ** See the COPYING file included in this distribution for licensing details *)
3
4 (* basic syntax tree for ABNF *)
5 open Printf
6
7 type terminal =
ddd4629 @avsm add support for HTTP ABNF constructs (mainly the list alternator and …
avsm authored
8 | ALPHA (* [A-Z][a-z] *)
9 | UPALPHA (* [A-Z] *)
10 | LOALPHA (* [a-z] *)
11 | DIGIT (* [0-9] *)
12 | HEXDIGIT (* [0-9a-fA-F] *)
8d70150 @avsm Add an ABNF parser and a helper command-line utility to help visualize
avsm authored
13 | DQUOTE
14 | SP
15 | HTAB
16 | WSP
17 | LWSP
18 | VCHAR
19 | CHAR
20 | OCTET
ddd4629 @avsm add support for HTTP ABNF constructs (mainly the list alternator and …
avsm authored
21 | CTL (* <any US-ASCII control character (0-31) and DEL (127)> *)
22 | CR (* <US-ASCII CR, carriage return (13)> *)
23 | LF (* <US-ASCII LF, linefeed (10)> *)
24 | CRLF (* CR LF *)
25 | BIT
8d70150 @avsm Add an ABNF parser and a helper command-line utility to help visualize
avsm authored
26
27 (* Type of the rules syntax tree *)
28 type rule =
29 | S_terminal of terminal (* Terminal character *)
30 | S_string of string (* Flat string *)
31 | S_concat of rule * rule (* Concatenation of rules *)
32 | S_reference of string (* reference to another rule *)
33 | S_alt of rule * rule (* Alt rules with a / *)
31821af @samoht Replace S_seq by S_bracket which is a less confusing name
authored
34 | S_bracket of rule (* Brackets : Needed because of the printer *)
8d70150 @avsm Add an ABNF parser and a helper command-line utility to help visualize
avsm authored
35 | S_repetition of int option * int option * rule (* Repetition *)
ddd4629 @avsm add support for HTTP ABNF constructs (mainly the list alternator and …
avsm authored
36 | S_element_list of int option * int option * rule (* List rule, RFC2068 2.1 *)
8d70150 @avsm Add an ABNF parser and a helper command-line utility to help visualize
avsm authored
37 | S_hex_range of int * int
38 | S_any_except of rule * rule (* any rule except rule *)
39
3046db3 Modified recursive descent parser to return a derivation, and added a…
chris authored
40 type derivation =
41 | D_terminal of terminal * string
42 | D_hex_range of int * int * string
43 | D_string of string
44 | D_concat of derivation * derivation
45 | D_reference of string * derivation
46 | D_repetition of derivation list
47 (* No any_except or alt, of which all branches are not represented, or seq/concat differentiation *)
48
8d70150 @avsm Add an ABNF parser and a helper command-line utility to help visualize
avsm authored
49 (* Each line in an ABNF file is defined here *)
50 type rule_definition = {
51 s_name: string;
52 s_rule: rule;
53 }
54
Something went wrong with that request. Please try again.