ccorrodi avatar ccorrodi committed 66a7cf1

set next fields for rules

Comments (0)

Files changed (3)

     else
       ""
   in
-  (* TODO: add tabs in here *)
-  (* TODO: also only remove one tab (or so) in the parser *)
   let tabcommands = L.map ((^) "\t") r.r_commands in
   let commands = String.concat "\n" tabcommands in
-(*   let commands = String.concat "\n" (L.map ((^) "\t" r.r_commands)) in *)
   Printf.sprintf "%s%s%s\n%s" targets colon deps commands
 
+(** Convert the rule targets to a string. *)
+let s_of_rule_targets (r : rule) : string =
+  String.concat " " r.r_targets
+
 (** Convert a dependency to a string. *)
 let dep_to_s (d : dependency) : string =
   d
     dependency. *)
 val s_to_dep : string -> dependency
 
+(** Convert a rule to a string in make database format. *)
+val s_of_rule : rule -> string
+
+(** Convert the rule targets to a string. *)
+val s_of_rule_targets : rule -> string
+
 (** {2 Initialization} *)
 (** Create a var instance of given inputs. *)
 val make_var :
 
 module A = Ast
 module S = Str
+module L = List
 
 (** Convert input token list to "Lexing.lexbuf -> Parser.token", as this is
     the type we need as first argument to Parser.input.
       | [t] ->
           t
       | t :: ts ->
-          List.iter (fun tok -> Queue.add tok q) ts;
+          L.iter (fun tok -> Queue.add tok q) ts;
           t
 
 (** {2 Input} *)
 (** Process the given raw ast after parsing. This includes pointing to actual
     rules in dependencies, etc. *)
 let post_parse (a : A.ast) : A.ast =
-  a
+  let process_rule (cur : A.rule) (next : A.rule) : A.rule =
+    let targets = cur.A.r_targets in
+    let prereqs = cur.A.r_deps in
+    let commands = cur.A.r_commands in
+    A.make_rule
+      ~next:(Some next)
+      ~targets:targets
+      (* TODO *)
+      ~suffixes:[]
+      (* TODO *)
+      ~deps:prereqs
+      ~commands:commands
+      ~num:(L.length targets)
+      ~terminal:false
+      ~in_use:false
+  in
+
+  let process_rules (rules : A.rule list) : A.rule list =
+    let rec helper (rules : A.rule list) : A.rule list =
+      let new_rules : A.rule list =
+        match rules with
+        | next :: cur :: [] ->
+            [process_rule cur next]
+        | next :: cur :: rest ->
+            (process_rule cur next) :: (helper (cur :: rest))
+      in
+      new_rules
+    in
+    L.hd rules :: (helper rules)
+  in
+
+  let process_db (db : A.database) : A.database =
+    {
+      A.d_commands = db.A.d_commands;
+      A.d_variables = db.A.d_variables;
+      A.d_implicit_rules = L.rev (process_rules (L.rev db.A.d_implicit_rules));
+      A.d_files = db.A.d_files;
+    }
+  in
+
+  let rec process_dbs (dbs : A.database list) : A.database list =
+      match dbs with
+      | db :: dbs ->
+          (process_db db) :: (process_dbs dbs)
+      | [] ->
+          []
+  in
+  process_dbs a
 
 (** Parse the database from given input file input and return the generated
     ast.*)
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.