Commits

Sébastien Ferré committed 5f434d9

Addition of context to parsers.

Comments (0)

Files changed (1)

 
 let str_of_string skip s = new str skip s 0 (1,1)
 
-class ['res] get (name : string) (regexp : Str.regexp) (f : Token.t -> 'res) (str : str) =
+class ['ctx,'res] get (name : string) (regexp : Str.regexp) (f : Token.t -> 'res) (ctx : 'ctx) (str : str) =
   object (self)
     val mutable state = `Begin
 
 	  if Str.string_match regexp s p
 	  then
 	    let m = Str.matched_string s in
-	    Parsed (f (m, coord), str # shift m)
+	    Parsed (ctx, f (m, coord), str # shift m)
 	  else
 	    Failed [Msg.make (sprintf "%s expected" name) [||] (Msg.Locator.Point coord)]
       | `End -> Failed []
 
 let get = new get
 
-class look (kw : string) (str : str) =
+class ['ctx] look (kw : string) (ctx : 'ctx) (str : str) =
   object (self)
     val mutable state = `Begin
 	
 	    let l = String.length kw in
 	    let m = String.sub s p l in
 	    if kw = m 
-	    then Parsed ((m, coord), str # shift m)
+	    then Parsed (ctx, (m, coord), str # shift m)
 	    else Failed [Msg.make (sprintf "%s expected" kw) [||] (Msg.Locator.Point coord)]
 	  with Invalid_argument _ -> Failed [Msg.make (sprintf "%s expected" kw) [||] (Msg.Locator.Point coord)])
       | `End -> Failed []
 
 let look = new look
 
-class eof (str : str) =
+class ['ctx] eof (ctx : 'ctx) (str : str) =
   object
     val mutable state = `Begin
 
 	  let str = str # skip in
 	  let s, p, coord = str # params in
 	  if p = String.length s
-	  then Parsed (("<EOF>", coord), str)
+	  then Parsed (ctx, ("<EOF>", coord), str)
 	  else Failed [Msg.make "<EOF> expected" [||] (Msg.Locator.Point coord)]
       | `End -> Failed []
   end
 let eof = new eof
 
 
-type 'res parse = ('res, str, Msg.t) Dcg.parse
+type ('ctx,'res) parse = ('ctx, 'res, str, Msg.t) Dcg.parse
 
 (*
 class virtual ['a] matcher (make : string -> int -> Msg.Coord.t -> 'a) s p coord = 
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.