Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* Shared code Section *)
- let nt_symbol = pack (plus nt_symbolchar) (fun (a) -> String(list_to_string a));;
- let nt_string = pack (caten (caten (char '\"') (star (disj_list [nt_stringlitteralchar;nt_stringmetachar;nt_stringhexchar]))) (char '\"')) (fun ((a,b),c) -> String (list_to_string (List.flatten b)));;
- let nt_char = pack (caten nt_charprefix (disj_list [nt_hexchar;nt_visiblechar;nt_namedchar;])) (fun (a,b) -> Char b);;
- let nt_number = disj (pack (disj_list [nt_scientific_int;nt_scientific_float;nt_float;nt_hexfloat]) (fun (a) -> (Number (Float(a))))) (pack (disj nt_plusminusinteger nt_hex) (fun (a) -> (Number (Int(a)))));;
- (* Genna's Section *)
- let gen_bool =
- let istrue = pack (word_ci "#t") (fun _ -> Bool true) in
- let isfalse = pack (word_ci "#f") (fun _ -> Bool false) in
- disj istrue isfalse;;
- let lp = char '(';;
- let rp = char ')';;
- let nt_white = pack nt_whitespace (fun a -> None);;
- (* sexprs disjoint impl *)
- let nt_sexprs = disj_list [nt_symbol;nt_string;gen_bool;nt_char;nt_number;nt_white];;
- (*test_string (star nt_sexprs) "1 #f \"Test\" 0x44 'a'";; *)
- (* list impl *)
- let nt_lst s =
- let x = pack (caten (caten lp (star nt_sexprs)) rp) (fun ((l,p),r) -> p) in
- let x = pack x (fun l -> List.fold_right (fun a b -> Pair(a,b)) l Nil) in
- x s;;
- let _whitespaces_ = star nt_whitespace;;
- let nt_not_end_line = pack (const (fun ch -> ch != '\n'))
- (fun ch -> ch);;
- (* line comment impl *)
- let nt_skip_line =
- let rec skip_this_spaces () =
- pack (caten nt_not_end_line
- (disj (delayed skip_this_spaces) nt_epsilon))
- (function (a, s) -> s) in
- skip_this_spaces();;
- let nt_del_semi= function
- | x :: l -> if (x == ';') then ( ([], l)) else (raise X_no_match)
- | _ -> raise X_no_match;;
- let nt_del_nwln_ch= function
- | x :: l -> if (x == '\n') then ( ([], l)) else (raise X_no_match)
- | _ -> raise X_no_match;;
- let nt_line_comment = caten nt_del_semi (caten nt_skip_line (disj nt_del_nwln_ch nt_end_of_input));;
- (* Genna's Section ends *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement