Source file character_state.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
open Fmlib_std.Interfaces
module Make (User: ANY) =
struct
type t = {
pos: Position.t;
indent: Indent.t;
user: User.t;
}
let make (pos: Position.t) (user: User.t): t =
{
pos;
user;
indent = Indent.initial
}
let position (s: t): Position.t =
s.pos
let line (s: t): int
= Position.line s.pos
let column (s: t): int =
Position.column s.pos
let user (s: t): User.t =
s.user
let put (user: User.t) (s: t): t =
{s with user}
let update (f: User.t-> User.t) (s: t) =
{s with user = f s.user}
let indent (s: t): Indent.t =
s.indent
let next (c: char) (s: t): t =
{s with
pos =
Position.next c s.pos;
indent =
Indent.token (Position.column s.pos) s.indent
}
let check_position (s: t): Indent.violation option =
Indent.check_position
(Position.column s.pos)
s.indent
let align (s: t): t =
{s with indent = Indent.align s.indent}
let left_align (s: t): t =
{s with indent = Indent.left_align s.indent}
let start_detach (s:t): t =
{s with indent = Indent.initial}
let end_detach (s0:t) (s:t): t =
{s with indent = s0.indent}
let start_indent (i: int) (s: t): t =
assert (0 <= i);
{s with indent = Indent.start_indent i s.indent}
let end_indent (i: int) (s0: t) (s: t): t =
{s with indent = Indent.end_indent i s0.indent s.indent}
end