Skip to content
Browse files

Replace S_seq by S_bracket which is a less confusing name

  • Loading branch information...
1 parent a51dfa2 commit 31821af6c0d7eca9d22124880b2805d245d7a942 @samoht samoht committed Oct 29, 2010
Showing with 12 additions and 11 deletions.
  1. +8 −6 abnf_ops.ml
  2. +1 −2 abnf_parser.mly
  3. +1 −1 abnf_recursive_descent.ml
  4. +1 −1 abnf_rules.ml
  5. +1 −1 abnf_syntaxtree.ml
View
14 abnf_ops.ml
@@ -50,9 +50,9 @@ module Text = struct
let rec string_of_rule = function
| S_terminal term -> string_of_terminal term
| S_string str -> sprintf "\"%s\"" str
- | S_concat (rl1,rl2) -> sprintf "%s . %s" (string_of_rule rl1) (string_of_rule rl2)
+ | S_concat (rl1,rl2) -> sprintf "%s %s" (string_of_rule rl1) (string_of_rule rl2)
| S_alt (rl1,rl2) -> sprintf "%s / %s" (string_of_rule rl1) (string_of_rule rl2)
- | S_seq (rl1,rl2) -> sprintf "(%s %s)" (string_of_rule rl1) (string_of_rule rl2)
+ | S_bracket rl -> sprintf "(%s)" (string_of_rule rl)
| S_element_list (min, max, rl) -> string_of_repeat_rule "#" min max rl
| S_repetition (min, max, rl) -> string_of_repeat_rule "*" min max rl
| S_reference r -> sprintf "@%s" r
@@ -71,7 +71,7 @@ module Text = struct
| S_string str -> sprintf "(string %s)" str
| S_concat (rl1,rl2) -> sprintf "(concat %s %s)" (sexpr_of_rule rl1) (sexpr_of_rule rl2)
| S_alt (rl1,rl2) -> sprintf "(alt %s %s)" (sexpr_of_rule rl1) (sexpr_of_rule rl2)
- | S_seq (rl1,rl2) -> sprintf "(seq %s %s)" (sexpr_of_rule rl1) (sexpr_of_rule rl2)
+ | S_bracket rl -> sprintf "(bracket %s)" (sexpr_of_rule rl)
| S_element_list (min, max, rl) -> sprintf "(list %d %s %s)" (match min with |None -> 0 |Some x -> x)
(match max with |None -> "inf" |Some x -> string_of_int x) (sexpr_of_rule rl)
| S_repetition (min, max, rl) -> sprintf "(rep %d %s %s)" (match min with |None -> 0 |Some x -> x)
@@ -91,9 +91,10 @@ module Text = struct
Hashtbl.iter (fun _ rule ->
let rec register_terminal = function
| S_terminal term -> Hashtbl.replace terms term ()
- | S_concat (rl1, rl2) |S_alt (rl1,rl2) |S_seq(rl1,rl2)
+ | S_concat (rl1, rl2) |S_alt (rl1,rl2)
| S_any_except(rl1,rl2) -> register_terminal rl1; register_terminal rl2
| S_string _ | S_hex_range _ | S_reference _ -> ()
+ | S_bracket(rl)
| S_element_list (_,_,rl) -> register_terminal rl
| S_repetition (_,_,rl) -> register_terminal rl
in register_terminal rule
@@ -145,8 +146,9 @@ module Graph = struct
let to_node = find_node torule in
[ { f=from_node; t=to_node } ]
| S_concat (rl1,rl2) | S_alt (rl1,rl2)
- | S_seq (rl1,rl2) | S_any_except (rl1,rl2) ->
+ | S_any_except (rl1,rl2) ->
edges_from_rule rl1 @ (edges_from_rule rl2)
+ | S_bracket (rl)
| S_repetition (_,_,rl) | S_element_list (_,_,rl) -> edges_from_rule rl
in
List.iter (fun x -> Hashtbl.add edges x ()) (edges_from_rule rule_def);
@@ -270,7 +272,7 @@ module HTML = struct
| S_string str -> sprintf "<span class=\"string\">&quot;%s&quot;</span>" str
| S_concat (rl1,rl2) -> sprintf "%s <span class=\"operator\">.</span> %s" (html_of_rule rl1) (html_of_rule rl2)
| S_alt (rl1,rl2) -> sprintf "%s <span class=\"operator\">/</span> %s" (html_of_rule rl1) (html_of_rule rl2)
- | S_seq (rl1,rl2) -> sprintf " <span class=\"operator\">(</span> %s %s <span class=\"operator\">)</span> " (html_of_rule rl1) (html_of_rule rl2)
+ | S_bracket rl -> sprintf " <span class=\"operator\">(</span> %s <span class=\"operator\">)</span> " (html_of_rule rl)
| S_repetition (min, max, rl) -> html_of_repeat_rule "&#35;" min max rl
| S_element_list (min, max, rl) -> html_of_repeat_rule "*" min max rl
| S_reference r -> span_rule r
View
3 abnf_parser.mly
@@ -53,8 +53,7 @@ rule_identifier:
| IDENTIFIER { match Abnf_ops.Text.terminal_of_string (id $1) with
|None -> Abnf_syntaxtree.S_reference (id $1)
|Some term -> Abnf_syntaxtree.S_terminal term }
-| LBRACKET rule_definition rule_definition RBRACKET { Abnf_syntaxtree.S_seq ($2, $3) }
-| LBRACKET rule_definition RBRACKET { $2 }
+| LBRACKET rule_definition RBRACKET { Abnf_syntaxtree.S_bracket ($2) }
| LESSTHAN ANY rule_definition EXCEPT rule_definition GREATERTHAN
{ Abnf_syntaxtree.S_any_except ($3, $5) }
;
View
2 abnf_recursive_descent.ml
@@ -143,7 +143,7 @@ let parse_file_with_grammar infile grammar starting_nonterminal = (
)
)
)
- | S_seq (rl1, rl2) -> parse_rule (S_concat (rl1, rl2))
+ | S_bracket rl -> parse_rule rl
| S_repetition (min, max, rl) ->
D_repetition (parse_repetition min max rl [])
| S_reference r -> eprintf "Expanding %s to %s\n"
View
2 abnf_rules.ml
@@ -24,7 +24,7 @@ let rec check_rule rules_hash rule_name =
|S_string _ -> ()
|S_concat (r1, r2) -> cfn r1; cfn r2
|S_alt (r1, r2) -> cfn r1; cfn r2
- |S_seq (r1, r2) -> cfn r1; cfn r2
+ |S_bracket r -> cfn r
|S_any_except (r1, r2) -> cfn r1; cfn r2
|S_reference r ->
if not (Hashtbl.mem rules_hash r) then
View
2 abnf_syntaxtree.ml
@@ -31,7 +31,7 @@ type rule =
| 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_seq of rule * rule (* Sequence group *)
+ | 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

0 comments on commit 31821af

Please sign in to comment.
Something went wrong with that request. Please try again.