olfend / path.ml

open Spotlib.Spot
open Sexplib.Conv

type t = 
  | Ident of Ident.t
  | Dot of t * Ident.t * int
with sexp

let of_ident id = Ident id

let rec to_string = function
  | Ident id -> Ident.to_string id
  | Dot (Ident predef, id, pos) when Ident.name predef = "*predef*" -> Printf.sprintf "%s/%d" (Ident.to_string id) pos
  | Dot (t, id, pos) -> Printf.sprintf "%s.%s/%d" (to_string t) (Ident.to_string id) pos

let ppr p = Treeprint.Printer.string (to_string p) 
let format = Treeprint.Printer.format ppr

let rec name = function
  | Ident id -> Ident.name id
  | Dot (Ident predef, n, _) when Ident.name predef = "*predef*" -> Ident.name n
  | Dot (t, n, _) -> Printf.sprintf "%s.%s" (name t) (Ident.name n)

let compare = compare

let rec localize path_in idpostbl = function
  | (Ident id as p) when Ident.stamp id = -1 -> p
  | Ident id -> 
      begin try 
        Dot (path_in, id, List.assoc id idpostbl )
      with Not_found -> Dot (path_in, id, -1) (* woooo right? *)
      end
  | Dot (p, name, pos) -> Dot (localize path_in idpostbl p, name, pos)

let postfix = function
  | Ident id | Dot (_, id, _) -> Ident.name id
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.