Skip to content
← Back

src/syntax/parsers/completeness.ghul

1
namespace Syntax.Parsers is
2
use Source.LOCATION
3
4
enum COMPLETENESS is
5
COMPLETE,
6
INCOMPLETE,
7
INVALID
8
si
9
10
// Whether a piece of input is a whole program, the start of one, or
11
// wrong. Input that parses is complete. Input whose every error was
12
// reported at end of input is incomplete: each of them is a construct
13
// still open, a value not written yet or a literal not closed yet, and
14
// more input could supply it. Any error reported anywhere else is
15
// something more input cannot fix, so the input is invalid.
16
class COMPLETENESS_CLASSIFIER is
17
init() is si
18
19
classify(
20
errors: Collections.Iterable[LOCATION],
21
end_of_input_errors: Collections.Iterable[LOCATION]
22
) -> COMPLETENESS is
23
let any_error mut = false
24
25
for error in errors do
26
any_error = true
27
28
if !_contains(end_of_input_errors, error) then
29
return COMPLETENESS.INVALID
30
fi
31
od
32
33
return if any_error then COMPLETENESS.INCOMPLETE else COMPLETENESS.COMPLETE fi
34
si
35
36
_contains(locations: Collections.Iterable[LOCATION], location: LOCATION) -> bool is
37
for l in locations do
38
if l =~ location then
39
return true
40
fi
41
od
42
43
return false
44
si
45
si
46
si