ocamlspot / xpath.ml

(* extend the original module *)
open Path
module Ident = struct
  include Ident
  include Xident

let rec name = function
  | Pident id -> Ident.name id
  | Pdot(p, s, pos) -> Name.create (name p ^ "." ^ s) pos
  | Papply(p1, p2) -> name p1 ^ "(" ^ name p2 ^ ")"
let rec local = function
  | Pident id -> not (Ident.global id)
  | Pdot (p, _, _) -> local p
  | Papply(p1, _p2) -> local p1 (* ? *) 

let parse s =
  let rec to_path = function
    | Longident.Lident s -> Pident (Xident.parse s)
    | Longident.Ldot (lid, s) ->
        let s, pos = Name.parse s in
        let path = to_path lid in
        Pdot (path, s, pos)
    | Longident.Lapply (lid1, lid2) ->
        let path1 = to_path lid1 in
        let path2 = to_path lid2 in
        Papply(path1, path2)
  to_path (Longident.parse s)

open Format
let format ppf p = pp_print_string ppf (name p)
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.