ocaml-niwango / ast.ml

open Util

type ident = string

type constant =
  | Bool of bool
  | Num of float
  | String of string

type binop =
  | Binop of string

type exp =
  | This
  | Var of ident
  | Con of constant
  | Assign of exp * exp
  | Field of exp * ident
  | Method of exp * ident * (exp list)
  | Binop of binop * exp * exp
  | Lambda of (ident list) * exp
  | Def of ident * exp
  | Seq of exp * exp (* 命令列 *)
  | Array of exp list (* 配列 *)

type line =
    Line of Date.t * exp

let string_of_const = function
  | Bool b -> !%"B(%b)" b
  | Num f -> !%"N(%f)" f
  | String s -> !%"\"%s\""s

let rec string_of_exp = function
  | This -> "THIS"
  | Var x -> !%"Var(%s)" x
  | Con c -> string_of_const c
  | Method(obj, fname, args) ->
      !%"Method(%s, %s, [%s])" (string_of_exp obj) fname
        (slist";"string_of_exp args)
  | Field(obj, fname) ->
      !%"Field(%s, %s)" (string_of_exp obj) fname
  | _ -> "TODO"

let string_of_line (Line(d, exp)) =
  !%"%f: %s" (Date.unixtime d)(string_of_exp exp)

let to_string lines =
  "[\n" ^ slist "\n" (string_of_line) lines ^ "\n]"
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.