Commits

orbitz committed 6765c56

Adding stubs for formatting

Comments (0)

Files changed (8)

 
 SOURCES = token.mli token.ml \
 	lexer.mli lexer.ml \
+	program_options.ml \
+	formatter.mli formatter.ml \
 	erlint.ml
 
 RESULT  = erlint
+type expr = 
+  | Atom of string
+  | Var of string
+  | Number of string
+  | Binary of (operator * expr * expr)
+
+type top_level =
+  | Compiler_directive
-
-type program_options = { file_path : string option }
+module Po = Program_options
 
 let usage = ""
 
 let parse_argv argv =
   let file_path = ref "" in
-
+  let indent_spaces = ref 2 in
   let params = 
-    Arg.align [ ("-f", Arg.Set_string file_path, "Path A file containing a list of paths to sequences (default stdin).")
+    Arg.align [ ( "-f"
+		, Arg.Set_string file_path
+		, "Path A file containing a list of paths to sequences (default stdin)."
+                )
+	      ; ( "-indent-spaces"
+		, Arg.Set_int indent_spaces
+		, "Int Number of spaces to indent, default is 2"
+	        )
 	      ]
   in
   Arg.parse params (fun _ -> ()) usage;
-  { file_path = if !file_path = "" then None else Some !file_path 
+  { Po.file_path = if !file_path = "" then None else Some !file_path 
+  ; Po.indent_spaces = !indent_spaces
   }
 
-
+let list_of_stream stream =
+  let rec list_of_stream' acc =
+    match Stream.peek stream with
+      | None ->
+	List.rev acc
+      | Some e -> begin
+	Stream.junk stream;
+	list_of_stream' (e::acc)
+      end
+  in
+  list_of_stream' []
 
 let main argv =
   let program_options = parse_argv argv in
   let in_chan = 
-    match program_options.file_path with
+    match program_options.Po.file_path with
       | None -> stdin
       | Some path ->
 	open_in path
   in
   let code_stream = Stream.of_channel in_chan in
-  Token.pp (Lexer.lex code_stream)
+  let code_lexed = list_of_stream (Lexer.lex code_stream) in
+  Token.pp_list code_lexed;
+  Formatter.format stdout code_lexed
 
 
 let () = main Sys.argv
-
+let format out_chan code = raise (Failure "uhhh..")

src/formatter.mli

+val format : out_channel -> Token.t list -> unit

src/program_options.ml

+type program_options = { file_path : string option
+		       ; indent_spaces : int
+		       }
       Stream.junk stream;
       pp stream
     end
+
+let rec pp_list = function
+  | [] ->
+    Printf.printf "\n";
+  | Newline::xs -> begin
+    Printf.printf "(Newline)\n";
+    pp_list xs
+  end
+  | x::xs -> begin
+    Printf.printf "(%s) " (token_to_string x);
+    pp_list xs
+  end
 
 
 val pp : t Stream.t -> unit
+val pp_list : t list -> unit
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.