]> ocean-lang.org Git - ocean-D/blob - spaces
updates
[ocean-D] / spaces
1
2 On adding indents to an LALR(1) parser.
3
4 Two ideas.
5   1/ end-of-line should sometimes be a semantic end-of-statement.
6      But when?
7
8   2/ line continuation by indent is easy to read:
9
10       this a semantic unit which has
11          been broken on to multiple lines but clearly
12          is all one unit
13       this is a new unit
14
15
16 We could suggest that whenever something is indented it doesn't end
17 the statement, but that doesn't allow for nexting
18
19    if stuff {
20        thing 1
21        thing 2
22    }
23    thing 3
24
25 Thing1 is indented but should be terminated.  Only locally though, the
26 'if' shouldn't be terminated.
27
28    a = [
29         one, two,
30         there, four,
31    ]
32    b = 5
33
34 pattern of indents is identical here, but now several newlines should
35 be ignored.  why is this so?  Mostly because lists are declared as
36 being terminated by newlines.
37
38 More examples?
39
40
41 First we need help from the lexer/scanner.  It must report newlines,
42 indents, and undents (or outdents or dedents or whatever).
43 If a line in more indented than the previous line, we get an 'indent'.
44 If a line is less indented, then we get one or more undents.
45 Possibly we can get undents and indents all at once.
46
47    line1
48      line2
49        line3
50      line4
51     line5
52
53 Line 2 has an indent, line3 another indent.
54 line 4 get an undent so it lines up with line 2.
55 line 5 needs an undent, but that would imply it lines up with line 1
56 which it doesn't.  So it needs and undent and an indent.
57
58 We get the lexer  to produce these and the newlines, but it does
59 something clever with newlines.  An 'indent' is never accompanied by
60 a newline.  Instead the newline is delayed until after the matching
61 undent.
62 So the above would be scanned as
63
64   line1 indent line2 indent line3 newline undent newline line4 newline
65   undent newline indent line5 undent newline
66
67 If we then choose to ignore a particular indent and all newlines,
68 indents and undents until the matching undent, then we will still see
69 a newline at the end and it indented section will look like line
70 continuation.
71
72 How do we choose what to ignore?
73