Commits

HongboZhang committed aba2eb9

add parser tracking support

Comments (0)

Files changed (3)

camlp4/Camlp4/Sig.ml

   module type Static = sig
     include Structure;
 
+    (** Whether trace parser or not *)
+    value trace_parser : ref bool;    
+
     module Entry : sig
       (** The abstract type of grammar entries. The type parameter is the type
           of the semantic actions that are associated with this entry. *)
       (** Make a new entry from the given name. *)
       value mk : string -> t 'a;
 
+
       (** Make a new entry from a name and an hand made token parser. *)
       value of_parser :
         string -> (token_stream -> 'a) -> t 'a;

camlp4/Camlp4/Struct/Grammar/Entry.ml

   value dump ppf e = fprintf ppf "%a@\n" Dump.entry e;
 
   (* value find e s = Find.entry e s; *)
-
+  value trace_parser = ref False;
   value mk g n =
     { egram = g;
       ename = n;
       edesc = Dlevels [] };
 
   value action_parse entry ts : Action.t =
-    try entry.estart 0 ts with
+    try 
+      let p =
+        if trace_parser.val then
+          Format.fprintf
+        else Format.ifprintf in 
+      let () = p Format.err_formatter "@[<4>%s@ " entry.ename in
+      let res = entry.estart 0 ts in
+      let () =  p Format.err_formatter "@]@." in 
+      res 
+    with
     [ Stream.Failure ->
         Loc.raise (get_prev_loc ts)
           (Stream.Error ("illegal begin of " ^ entry.ename))

camlp4/Camlp4/Struct/Grammar/Static.ml

     value print = E.print;
     value clear = E.clear;
     value dump = E.dump;
+
     value obj x = x;
   end;
-
+  value trace_parser = Entry.E.trace_parser;
+    
   value get_filter () = gram.gfilter;
 
   value lex loc cs = gram.glexer loc cs;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.