author | nipkow |
Tue, 17 Jun 2025 14:11:40 +0200 | |
changeset 82733 | 8b537e1af2ec |
parent 82679 | 1dd29afaddda |
permissions | -rw-r--r-- |
57905
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/PIDE/command_span.ML |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
3 |
|
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
4 |
Syntactic representation of command spans. |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
5 |
*) |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
6 |
|
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
7 |
signature COMMAND_SPAN = |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
8 |
sig |
72754 | 9 |
val extensions: string list -> Path.T -> Path.T list |
57905
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
10 |
datatype kind = Command_Span of string * Position.T | Ignored_Span | Malformed_Span |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
11 |
datatype span = Span of kind * Token.T list |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
12 |
val kind: span -> kind |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
13 |
val content: span -> Token.T list |
68183
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
14 |
val symbol_length: span -> int option |
82679 | 15 |
val eof: span |
16 |
val is_eof: span -> bool |
|
17 |
val stopper: span Scan.stopper |
|
68183
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
18 |
val adjust_offsets_kind: (int -> int option) -> kind -> kind |
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
19 |
val adjust_offsets: (int -> int option) -> span -> span |
57905
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
20 |
end; |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
21 |
|
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
22 |
structure Command_Span: COMMAND_SPAN = |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
23 |
struct |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
24 |
|
72754 | 25 |
(* loaded files *) |
26 |
||
27 |
fun extensions exts path = map (fn ext => Path.ext ext path) exts; |
|
28 |
||
29 |
||
30 |
(* span *) |
|
31 |
||
57905
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
32 |
datatype kind = Command_Span of string * Position.T | Ignored_Span | Malformed_Span; |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
33 |
datatype span = Span of kind * Token.T list; |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
34 |
|
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
35 |
fun kind (Span (k, _)) = k; |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
36 |
fun content (Span (_, toks)) = toks; |
68183
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
37 |
val symbol_length = Position.distance_of o Token.range_of o content; |
68177 | 38 |
|
72754 | 39 |
|
82679 | 40 |
(* stopper *) |
41 |
||
42 |
val eof = Span (Command_Span ("", Position.none), []); |
|
43 |
||
44 |
fun is_eof (Span (Command_Span ("", _), _)) = true |
|
45 |
| is_eof _ = false; |
|
46 |
||
47 |
val stopper = Scan.stopper (K eof) is_eof; |
|
48 |
||
49 |
||
72754 | 50 |
(* presentation positions *) |
51 |
||
68183
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
52 |
fun adjust_offsets_kind adjust k = |
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
53 |
(case k of |
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
54 |
Command_Span (name, pos) => Command_Span (name, Position.adjust_offsets adjust pos) |
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
55 |
| _ => k); |
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
56 |
|
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
57 |
fun adjust_offsets adjust (Span (k, toks)) = |
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
58 |
Span (adjust_offsets_kind adjust k, map (Token.adjust_offsets adjust) toks); |
68177 | 59 |
|
57905
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
diff
changeset
|
60 |
end; |