Source

orakuda / pa / pa_command.ml

open Camlp4                                             (* -*- camlp4of -*- *)

module Id : Sig.Id = struct
  let name = "pa_command"
  let version = "1.0"
end

module Make (Syntax : Sig.Camlp4Syntax) = struct
  (* open Sig *)
  include Syntax

  module Pa_format = Pa_format.Make(Syntax) 

  let parse stopat _loc _loc_var_opt s =
    match Pa_format.parse stopat _loc _loc_var_opt s with
    | (`Const _ | `Fun _), Some rem ->
        let pos = String.length s - String.length rem in
        raise (Lexformat.Error (pos, pos + 1,
		                Printf.sprintf "Unescaped special character %C found" rem.[0]))
    | `Const s, _ -> <:expr<command $s$>>
    | `Fun (_abss, f), _ -> 
	f <:expr<
	    Printf.ksprintf command
	  >>
  ;;

  let _ =
    Syntax.Quotation.add "qx"
      Syntax.Quotation.DynAst.expr_tag
      (parse []);

    Syntax.Quotation.add "$qx"
      Syntax.Quotation.DynAst.expr_tag
      (parse ['`']);

    Syntax.Quotation.add "qx"
      Syntax.Quotation.DynAst.str_item_tag
      (fun _loc _loc_var_opt s ->
	let e = parse [] _loc _loc_var_opt s in
	<:str_item< $exp:e$ >>);

    Syntax.Quotation.add "$qx"
      Syntax.Quotation.DynAst.str_item_tag
      (fun _loc _loc_var_opt s ->
	let e = parse ['`'] _loc _loc_var_opt s in
	<:str_item< $exp:e$ >>)
    ;;
end


let module M = Register.OCamlSyntaxExtension(Id)(Make) in ()
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.