-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelimiters.cpp
123 lines (118 loc) · 4.12 KB
/
delimiters.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "delimiters.hpp"
using namespace std;
namespace {
enum lexical_supersuperstate {
UNNESTED_I7_IN_CONTEXT,
I6_IN_CONTEXT,
I7_IN_I6_IN_CONTEXT,
I6_COMMENT_IN_CONTEXT,
I7_IN_I6_COMMENT_IN_CONTEXT,
I7_STRING_IN_CONTEXT,
OTHER_IN_CONTEXT
};
}
static lexical_supersuperstate supersuperstate_of(lexical_state state) {
switch (state.get_superstate()) {
case I7:
case I7_IN_EXTRACT:
return UNNESTED_I7_IN_CONTEXT;
case I6:
case I6_IN_ROUTINE:
case I6_IN_EXTRACT:
case I6_IN_ROUTINE_IN_EXTRACT:
return I6_IN_CONTEXT;
case I7_IN_I6:
case I7_IN_I6_IN_ROUTINE:
case I7_IN_I6_IN_EXTRACT:
case I7_IN_I6_IN_ROUTINE_IN_EXTRACT:
return I7_IN_I6_IN_CONTEXT;
case I6_COMMENT:
case I6_COMMENT_IN_ROUTINE:
case I6_COMMENT_IN_EXTRACT:
case I6_COMMENT_IN_ROUTINE_IN_EXTRACT:
return I6_COMMENT_IN_CONTEXT;
case I7_IN_I6_COMMENT:
case I7_IN_I6_COMMENT_IN_ROUTINE:
case I7_IN_I6_COMMENT_IN_EXTRACT:
case I7_IN_I6_COMMENT_IN_ROUTINE_IN_EXTRACT:
return I7_IN_I6_COMMENT_IN_CONTEXT;
case I7_STRING:
case I7_STRING_IN_I6:
case I7_STRING_IN_I6_IN_ROUTINE:
case I7_STRING_IN_EXTRACT:
case I7_STRING_IN_I6_IN_EXTRACT:
case I7_STRING_IN_I6_IN_ROUTINE_IN_EXTRACT:
return I7_STRING_IN_CONTEXT;
}
return OTHER_IN_CONTEXT;
}
static stack_monoid<delimiter>get_delimiter_effect(const lexical_state&before, const monoid_sequence<token>::iterator&position, const lexical_state&after) {
if (before.get_comment_depth() < after.get_comment_depth()) {
assert(before.get_comment_depth() + 1 == after.get_comment_depth());
return {{I7_COMMENT_DELIMITER, position}, false};
}
if (before.get_comment_depth() > after.get_comment_depth()) {
assert(before.get_comment_depth() == 1 + after.get_comment_depth());
return {{I7_COMMENT_DELIMITER, position}, true};
}
switch (supersuperstate_of(before.get_superstate())) {
case UNNESTED_I7_IN_CONTEXT:
switch (supersuperstate_of(after.get_superstate())) {
case I6_IN_CONTEXT:
return {{I6_DELIMITER, position}, false};
case I7_STRING_IN_CONTEXT:
return {{I7_STRING_DELIMITER, position}, false};
}
break;
case I6_IN_CONTEXT:
switch (supersuperstate_of(after.get_superstate())) {
case UNNESTED_I7_IN_CONTEXT:
return {{I6_DELIMITER, position}, true};
case I7_IN_I6_IN_CONTEXT:
return {{I7_DELIMITER, position}, false};
case I6_COMMENT_IN_CONTEXT:
return {{I6_COMMENT_DELIMITER, position}, false};
}
break;
case I7_IN_I6_IN_CONTEXT:
switch (supersuperstate_of(after.get_superstate())) {
case UNNESTED_I7_IN_CONTEXT:
return stack_monoid<delimiter>{{I7_DELIMITER, position}, true} + stack_monoid<delimiter>{{I6_DELIMITER, position}, true};
case I6_IN_CONTEXT:
return {{I7_DELIMITER, position}, true};
case I7_STRING_IN_CONTEXT:
return {{I7_STRING_DELIMITER, position}, false};
}
break;
case I6_COMMENT_IN_CONTEXT:
switch (supersuperstate_of(after.get_superstate())) {
case UNNESTED_I7_IN_CONTEXT:
return stack_monoid<delimiter>{{I6_COMMENT_DELIMITER, position}, true} + stack_monoid<delimiter>{{I6_DELIMITER, position}, true};
case I6_IN_CONTEXT:
return {{I6_COMMENT_DELIMITER, position}, true};
case I7_IN_I6_COMMENT_IN_CONTEXT:
return {{I7_DELIMITER, position}, false};
}
break;
case I7_IN_I6_COMMENT_IN_CONTEXT:
switch (supersuperstate_of(after.get_superstate())) {
case UNNESTED_I7_IN_CONTEXT:
return stack_monoid<delimiter>{{I7_DELIMITER, position}, true} + stack_monoid<delimiter>{{I6_COMMENT_DELIMITER, position}, true} + stack_monoid<delimiter>{{I6_DELIMITER, position}, true};
case I6_COMMENT_IN_CONTEXT:
return {{I7_DELIMITER, position}, true};
case I7_STRING_IN_CONTEXT:
return {{I7_STRING_DELIMITER, position}, false};
}
break;
case I7_STRING_IN_CONTEXT:
switch (supersuperstate_of(after.get_superstate())) {
case UNNESTED_I7_IN_CONTEXT:
case I7_IN_I6_IN_CONTEXT:
case I7_IN_I6_COMMENT_IN_CONTEXT:
return {{I7_STRING_DELIMITER, position}, true};
}
break;
}
return stack_monoid<delimiter>{0};
}
auto unused = get_delimiter_effect;