/[svn]/parser/parser.ml
ViewVC logotype

Diff of /parser/parser.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 26 by abate, Tue Jul 10 16:59:08 2007 UTC revision 43 by abate, Tue Jul 10 17:00:25 2007 UTC
# Line 1  Line 1 
1  open Location  open Location
2  open Ast  open Ast
3    
4    let gram    = Grammar.create (Plexer.make ())  (* let ()  = Grammar.error_verbose := true *)
5    let gram    = Grammar.gcreate (Lexer.gmake ())
6    let prog    = Grammar.Entry.create gram "prog"    let prog    = Grammar.Entry.create gram "prog"
7    let expr    = Grammar.Entry.create gram "expression"    let expr    = Grammar.Entry.create gram "expression"
8    let pat     = Grammar.Entry.create gram "type/pattern expression"    let pat     = Grammar.Entry.create gram "type/pattern expression"
# Line 28  Line 29 
29      aux [] (String.length s)      aux [] (String.length s)
30    
31    
32    let char_list loc s =
33      let s = seq_of_string (Token.eval_string s) in
34      List.map (fun c -> mk loc (Cst (Types.Char (Chars.Unichar.from_char c)))) s
35    
36    
37    EXTEND    EXTEND
38    GLOBAL: prog expr pat regexp const;    GLOBAL: prog expr pat regexp const;
39    
# Line 37  Line 43 
43    
44    phrase: [    phrase: [
45      [ e = expr -> EvalStatement e      [ e = expr -> EvalStatement e
46      | "type"; x = UIDENT; "="; t = pat -> TypeDecl (x,t) ]      | "type"; x = UIDENT; "="; t = pat -> TypeDecl (x,t)
47        | "debug"; d = debug_directive -> Debug d
48        ]
49      ];
50    
51      debug_directive: [
52        [ LIDENT "filter"; t = pat; p = pat -> `Filter(t,p)
53        | LIDENT "accept"; p = pat -> `Accept p;
54        | LIDENT "compile"; t = pat; p = LIST1 pat -> `Compile (t,p)
55        ]
56    ];    ];
57    
58    expr: [    expr: [
# Line 82  Line 97 
97      | "<"; t = expr_tag_spec; a = expr_attrib_spec; ">"; c = expr ->      | "<"; t = expr_tag_spec; a = expr_attrib_spec; ">"; c = expr ->
98          tuple loc [t;a;c]          tuple loc [t;a;c]
99      | "{"; r = [ expr_record_spec | -> mk loc (RecordLitt []) ]; "}" -> r      | "{"; r = [ expr_record_spec | -> mk loc (RecordLitt []) ]; "}" -> r
100        | s = STRING ->
101            tuple loc (char_list loc s @ [cst_nil])
102      | "!"; t = pat -> mk loc (DebugTyper t)      | "!"; t = pat -> mk loc (DebugTyper t)
103      | a = LIDENT -> mk loc (Var a)      | a = LIDENT -> mk loc (Var a)
104      ]      ]
# Line 89  Line 106 
106    ];    ];
107    
108    seq_elem: [    seq_elem: [
109      [ x = STRING ->      [ x = [CHAR | STRING] -> char_list loc x
         let s = seq_of_string (Token.eval_string x) in  
         List.map  
           (fun c -> mk loc (Cst (Types.Char (Chars.Unichar.from_char c))))  
           s  
110      | e = expr LEVEL "no_appl" -> [e]      | e = expr LEVEL "no_appl" -> [e]
111      ]      ]
112    ];    ];
# Line 134  Line 147 
147      | x = regexp; "??" -> Alt (Epsilon, x) ]      | x = regexp; "??" -> Alt (Epsilon, x) ]
148    | [ "("; x = regexp; ")" -> x    | [ "("; x = regexp; ")" -> x
149      | UIDENT "String" -> string      | UIDENT "String" -> string
150      | s = STRING ->      | s = CHAR ->
151          let s = seq_of_string (Token.eval_string s) in          let s = seq_of_string (Token.eval_string s) in
152          List.fold_right          List.fold_right
153            (fun c accu ->            (fun c accu ->

Legend:
Removed from v.26  
changed lines
  Added in v.43

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5