Commits

camlspotter  committed d65994d

still not done

  • Participants
  • Parent commits 341a5a9

Comments (0)

Files changed (2)

+^.*\.(cm.*|o|sp.t|annot|opt|run|out|omc)$
+.*~$
+
+
                pos_lnum = 1;
                pos_bol = 0;
                pos_cnum = 0 }
+
+  let columns p = p.pos_cnum - p.pos_bol
 end
 
-(*
-let _ = 
-  1
-    2
-    3
-    (4
-       5
-       6
-*)
-
-(*
-let _ = 
-  1
-    2
-    3 (4
-         5
-         6
-*)
+module Region = struct
+  type t = Position.t * Position.t
+  let lnum (p,_) = p.Position.pos_lnum
+  let columns (p,_) = Position.columns p
+  let zero = (Position.zero, Position.zero)
+end
 
 type state = {
-  bases : (Parser.token * int) list;
-  region : Position.t * Position.t;
+  bases : (Parser.token * int) list; (** indentation stack *)
+  last_region : Region.t;                 (** the last token's region *)
 }
 
 let indent state token region = 
   let open Parser in
-  let _current_ind = 
+
+  let at_line_head = 
+    Region.lnum state.last_region <> Region.lnum region
+  in
+
+  let columns = Region.columns region in
+
+  let current_ind = 
     match state.bases with
     | [] -> 0
     | (_,ind)::_ -> ind
   in
-  let columns = (fst region).Position.pos_cnum - (fst region).Position.pos_bol in
-  let at_line_head = (fst state.region).Position.pos_lnum <> (fst region).Position.pos_lnum in
+
+(*
+  let indent_fix = 
+    if at_line_head then current_ind
+    else state.indet_fix in
+  in
+*)
+  
 (*
   let ind = 
     if at_line_head then 
 
     | _ -> state.bases
     in
-  let state = { bases = bases; region = region } in
+  let state = { bases = bases; last_region = region } in
   match bases with
   | [] -> 0, state
   | (_,ind)::_ when at_line_head -> ind, state
   | _ -> -1, state
 
-(*
-  match token with
-  | AND
-  | AS
-  | ASSERT
-  | BACKQUOTE
-  | BANG
-  | BAR
-  | BARRBRACKET
-  | BEGIN
-  | CHAR of (char)
-  | CLASS
-  | COLON
-  | COLONEQUAL
-  | COLONGREATER
-  | COMMA
-  | CONSTRAINT
-  | DO
-  | DONE
-  | DOT
-  | DOTDOT
-  | DOWNTO
-  | ELSE
-  | END
-  | EOF
-  | EQUAL
-  | EXCEPTION
-  | EXTERNAL
-  | FALSE
-  | FLOAT of (string)
-  | FOR
-  | FUN
-  | FUNCTION
-  | FUNCTOR
-  | GREATER
-  | GREATERRBRACE
-  | GREATERRBRACKET
-  | IF
-  | IN
-  | INCLUDE
-  | INFIXOP0 of (string)
-  | INFIXOP1 of (string)
-  | INFIXOP2 of (string)
-  | INFIXOP3 of (string)
-  | INFIXOP4 of (string)
-  | INHERIT
-  | INITIALIZER
-  | INT of (int)
-  | INT32 of (int32)
-  | INT64 of (int64)
-  | LABEL of (string)
-  | LAZY
-  | LBRACE
-  | LBRACELESS
-  | LBRACKET
-  | LBRACKETBAR
-  | LBRACKETLESS
-  | LBRACKETGREATER
-  | LESS
-  | LESSMINUS
-  | LET
-  | LIDENT of (string)
-  | LPAREN
-  | MATCH
-  | METHOD
-  | MINUSGREATER
-  | MODULE
-  | MUTABLE
-  | NATIVEINT of (nativeint)
-  | NEW
-  | OBJECT
-  | OF
-  | OPEN
-  | OPTLABEL of (string)
-  | OR
-  | PREFIXOP of (string)
-  | PRIVATE
-  | QUESTION
-  | QUESTIONQUESTION
-  | QUOTE
-  | RBRACE
-  | RBRACKET
-  | REC
-  | RPAREN
-  | SEMI
-  | SEMISEMI
-  | SHARP
-  | SIG
-  | STRING of (string)
-  | STRUCT
-  | THEN
-  | TILDE
-  | TO
-  | TRUE
-  | TRY
-  | TYPE
-  | UIDENT of (string)
-  | UNDERSCORE
-  | VAL
-  | VIRTUAL
-  | WHEN
-  | WHILE
-  | WITH
-*)
-
 module Lexbuf = struct
 
   type t = {
         | t -> 
             let region = LexReader.region reader in
             let space_between = 
-              let last_end = (snd state.region).Position.pos_cnum in
+              let last_end = (snd state.last_region).Position.pos_cnum in
               LexReader.substring 
                 reader last_end ((fst region).Position.pos_cnum - last_end)
             in
             end;
             loop state
       in
-      loop { bases = []; region = (Position.zero, Position.zero) } 
+      loop { bases = []; last_region = Region.zero } 
 
     with
     | e ->