Skip to content

Commit 7a3915c

Browse files
committed
wow, closer again
1 parent 018fc44 commit 7a3915c

5 files changed

Lines changed: 63 additions & 50 deletions

File tree

crates/vim9-lexer/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,17 +517,26 @@ impl Lexer {
517517
}
518518

519519
fn read_line(&self) -> Result<Token<'static>> {
520+
// TODO: Could probably do this without static and just peek until we see
521+
// a newline, then return that slice, but I wrote it this way the first time
522+
// so I think it's OK
523+
//
524+
// Also, we're only using this right now for NormalModeParser, so we need
525+
// to figure that out later
520526
let position = self.position();
521527

522528
let mut line = String::new();
523529
loop {
524530
match self.ch() {
525531
Some(&ch) => {
526-
if ch == '\n' {
527-
break;
532+
line += &ch.to_string();
533+
534+
if let Some(&peek) = self.peek_char() {
535+
if peek == '\n' {
536+
break;
537+
}
528538
}
529539

530-
line += &ch.to_string();
531540
self.read_char();
532541
}
533542
None => panic!("OH NO"),
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/vim9-lexer/src/lib.rs
3-
assertion_line: 1156
3+
assertion_line: 1159
44
expression: snapshot_lexing(contents)
55
---
66
vim9script
@@ -11,13 +11,16 @@ vim9script
1111
normal! dd
1212
^^^^^^ Token(Identifier, "normal", (2,0)->(2,6))
1313
^ Token(Bang, "!", (2,6)->(2,7))
14-
^^ Token(Literal, "dd", (2,8)->(2,10))
14+
^ Token(Literal, "dd", (2,8)->(2,9))
15+
Token(EndOfLine, "\n", (2,10)->(2,10))
1516
normal dd
1617
^^^^^^ Token(Identifier, "normal", (3,0)->(3,6))
17-
^^ Token(Literal, "dd", (3,7)->(3,9))
18+
^ Token(Literal, "dd", (3,7)->(3,8))
19+
Token(EndOfLine, "\n", (3,9)->(3,9))
1820
:normal! v"_y
1921
^ Token(Colon, ":", (4,0)->(4,1))
2022
^^^^^^ Token(Identifier, "normal", (4,1)->(4,7))
2123
^ Token(Bang, "!", (4,7)->(4,8))
22-
^^^^ Token(Literal, "v\"_y", (4,9)->(4,13))
24+
^^^ Token(Literal, "v\"_y", (4,9)->(4,12))
25+
Token(EndOfLine, "\n", (4,13)->(4,13))
2326

crates/vim9-lexer/testdata/output/vim9_lexer__test__selection.snap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/vim9-lexer/src/lib.rs
3-
assertion_line: 1163
3+
assertion_line: 1166
44
expression: snapshot_lexing(contents)
55
---
66
vim9script
@@ -85,7 +85,8 @@ def SelectText(bnr: number, range: dict<dict<number>>)
8585
^ Token(Colon, ":", (13,2)->(13,3))
8686
^^^^^^ Token(Identifier, "normal", (13,3)->(13,9))
8787
^ Token(Bang, "!", (13,9)->(13,10))
88-
^^^^ Token(Literal, "v\"_y", (13,11)->(13,15))
88+
^^^ Token(Literal, "v\"_y", (13,11)->(13,14))
89+
Token(EndOfLine, "\n", (13,15)->(13,15))
8990
enddef
9091
^^^^^^ Token(Identifier, "enddef", (14,0)->(14,6))
9192
Token(EndOfLine, "\n", (14,6)->(14,6))

crates/vim9-parser/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ impl StatementCommand {
619619
}
620620

621621
pub fn parse(parser: &Parser) -> Result<ExCommand> {
622-
let expr = Expression::parse(parser, Precedence::Lowest)?;
622+
let expr = dbg!(Expression::parse(parser, Precedence::Lowest)?);
623623
if parser.front_kind() == TokenKind::Equal {
624624
return Ok(ExCommand::Statement(StatementCommand::Assign(
625625
AssignStatement {
@@ -2432,13 +2432,11 @@ impl<'a> Parser<'a> {
24322432
} else if self.command_match("continue") {
24332433
ContinueCommand::parse(self)?
24342434
}
2435-
// CallCommand should be lower, because it has less strict requirements,
2435+
// The following commands must remain at the bottom end of the list
24362436
//
24372437
// This is true of a few of the other kind of "dynamic" style commands
24382438
// that are detected/guessed by what the rest of the line looks like.
2439-
else if CallCommand::matches(self) {
2440-
CallCommand::parse(self)?
2441-
} else if StatementCommand::matches(self) {
2439+
else if StatementCommand::matches(self) {
24422440
// TODO: There are some kind of assignments that aren't legal if there is a
24432441
// colon. I'm not sure what to do about that... it seems a bit weird.
24442442
//
@@ -2448,7 +2446,10 @@ impl<'a> Parser<'a> {
24482446
//
24492447
// var sum = 1
24502448
// :sum = sum + 1
2449+
println!("STATEMENT TIME");
24512450
StatementCommand::parse(self)?
2451+
} else if CallCommand::matches(self) {
2452+
CallCommand::parse(self)?
24522453
} else if self.line_contains_kind(TokenKind::MethodArrow) {
24532454
EvalCommand::parse(self)?
24542455
} else {
@@ -2697,5 +2698,5 @@ mod test {
26972698
}
26982699

26992700
// TODO: Slowly but surely, we can work towards this
2700-
// snapshot!(test_matchparen, "../../shared/snapshots/matchparen.vim");
2701+
// snap!(test_matchparen, "../../shared/snapshots/matchparen.vim");
27012702
}
Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
---
22
source: crates/vim9-parser/src/lib.rs
3-
assertion_line: 2043
3+
assertion_line: 2682
44
expression: snapshot_parsing(contents)
55
---
66
[
77
Vim9Script(
88
Vim9ScriptCommand {
99
noclear: false,
10-
eol: Token(EndOfLine, "\n", (0,10)->(0,10)),
10+
eol: Token(EndOfLine, (0,10)->(0,10)),
1111
},
1212
),
13+
NoOp(
14+
Token(EndOfLine, "\n", (1,0)->(1,0)),
15+
),
1316
Comment(
1417
Token(Comment, "# Thanks to: https://github.com/yegappan/lsp for some test cases", (2,0)->(2,64)),
1518
),
@@ -24,15 +27,13 @@ expression: snapshot_parsing(contents)
2427
),
2528
ImportCommand(
2629
ImportImplicit {
27-
import: Token(Identifier, "import", (6,0)->(6,6)),
30+
import: Token(Identifier, (6,0)->(6,6)),
2831
autoload: false,
2932
file: "./util.vim",
3033
name: None,
34+
eol: Token(EndOfLine, (6,19)->(6,19)),
3135
},
3236
),
33-
NoOp(
34-
Token(EndOfLine, "\n", (6,19)->(6,19)),
35-
),
3637
NoOp(
3738
Token(EndOfLine, "\n", (7,0)->(7,0)),
3839
),
@@ -41,16 +42,16 @@ expression: snapshot_parsing(contents)
4142
),
4243
Def(
4344
DefCommand {
44-
def: Token(Identifier, "def", (9,0)->(9,3)),
45+
def: Token(Identifier, (9,0)->(9,3)),
4546
name: Raw(SelectText),
4647
args: Signature {
47-
open: Token(LeftParen, "(", (9,14)->(9,15)),
48+
open: Token(LeftParen, (9,14)->(9,15)),
4849
params: [
4950
Parameter {
5051
name: Raw(bnr),
5152
ty: Some(
5253
Type {
53-
colon: Token(SpacedColon, ": ", (9,18)->(9,20)),
54+
colon: Token(SpacedColon, (9,18)->(9,20)),
5455
inner: Number,
5556
},
5657
),
@@ -61,45 +62,45 @@ expression: snapshot_parsing(contents)
6162
name: Raw(range),
6263
ty: Some(
6364
Type {
64-
colon: Token(SpacedColon, ": ", (9,33)->(9,35)),
65+
colon: Token(SpacedColon, (9,33)->(9,35)),
6566
inner: Dict {
66-
open: Token(AngleLeft, "<", (9,39)->(9,40)),
67+
open: Token(AngleLeft, (9,39)->(9,40)),
6768
inner: Dict {
68-
open: Token(AngleLeft, "<", (9,44)->(9,45)),
69+
open: Token(AngleLeft, (9,44)->(9,45)),
6970
inner: Number,
70-
close: Token(AngleRight, ">", (9,51)->(9,52)),
71+
close: Token(AngleRight, (9,51)->(9,52)),
7172
},
72-
close: Token(AngleRight, ">", (9,52)->(9,53)),
73+
close: Token(AngleRight, (9,52)->(9,53)),
7374
},
7475
},
7576
),
7677
equal: None,
7778
default_val: None,
7879
},
7980
],
80-
close: Token(RightParen, ")", (9,53)->(9,54)),
81+
close: Token(RightParen, (9,53)->(9,54)),
8182
},
8283
ret: None,
83-
def_eol: Token(EndOfLine, "\n", (9,54)->(9,54)),
84+
def_eol: Token(EndOfLine, (9,54)->(9,54)),
8485
body: Body {
8586
commands: [
8687
Var(
8788
VarCommand {
88-
var: Token(Identifier, "var", (10,2)->(10,5)),
89+
var: Token(Identifier, (10,2)->(10,5)),
8990
ty: Some(
9091
Type {
91-
colon: Token(SpacedColon, ": ", (10,15)->(10,17)),
92+
colon: Token(SpacedColon, (10,15)->(10,17)),
9293
inner: Number,
9394
},
9495
),
9596
name: Raw(start_col),
96-
equal: Token(Equal, "=", (10,24)->(10,25)),
97+
equal: Token(Equal, (10,24)->(10,25)),
9798
expr: Infix(
9899
InfixExpression {
99100
token: Token(Plus, "+", (10,68)->(10,69)),
100101
operator: Plus,
101102
left: Call(
102-
f: DictAccess(DictAccess { container: Identifier(Raw(util)), dot: Token(Dot, ".", (10,30)->(10,31)), index: RawIdentifier { name: "GetLineByteFromPos" } }) arg: [
103+
f: DictAccess(DictAccess { container: Identifier(Raw(util)), dot: Token(Dot, (10,30)->(10,31)), index: RawIdentifier { name: "GetLineByteFromPos" } }) arg: [
103104
Identifier(
104105
Raw(bnr),
105106
),
@@ -108,7 +109,7 @@ expression: snapshot_parsing(contents)
108109
container: Identifier(
109110
Raw(range),
110111
),
111-
dot: Token(Dot, ".", (10,60)->(10,61)),
112+
dot: Token(Dot, (10,60)->(10,61)),
112113
index: RawIdentifier {
113114
name: "start",
114115
},
@@ -117,28 +118,26 @@ expression: snapshot_parsing(contents)
117118
],
118119
),
119120
right: Number(
120-
VimNumber {
121-
value: "1",
122-
},
121+
Number(1),
123122
),
124123
},
125124
),
126-
eol: Token(EndOfLine, "\n", (10,71)->(10,71)),
125+
eol: Token(EndOfLine, (10,71)->(10,71)),
127126
},
128127
),
129128
Var(
130129
VarCommand {
131-
var: Token(Identifier, "var", (11,2)->(11,5)),
130+
var: Token(Identifier, (11,2)->(11,5)),
132131
ty: Some(
133132
Type {
134-
colon: Token(SpacedColon, ": ", (11,13)->(11,15)),
133+
colon: Token(SpacedColon, (11,13)->(11,15)),
135134
inner: Number,
136135
},
137136
),
138137
name: Raw(end_col),
139-
equal: Token(Equal, "=", (11,22)->(11,23)),
138+
equal: Token(Equal, (11,22)->(11,23)),
140139
expr: Call(
141-
f: DictAccess(DictAccess { container: Identifier(Raw(util)), dot: Token(Dot, ".", (11,28)->(11,29)), index: RawIdentifier { name: "GetLineByteFromPos" } }) arg: [
140+
f: DictAccess(DictAccess { container: Identifier(Raw(util)), dot: Token(Dot, (11,28)->(11,29)), index: RawIdentifier { name: "GetLineByteFromPos" } }) arg: [
142141
Identifier(
143142
Raw(bnr),
144143
),
@@ -147,30 +146,30 @@ expression: snapshot_parsing(contents)
147146
container: Identifier(
148147
Raw(range),
149148
),
150-
dot: Token(Dot, ".", (11,58)->(11,59)),
149+
dot: Token(Dot, (11,58)->(11,59)),
151150
index: RawIdentifier {
152151
name: "end",
153152
},
154153
},
155154
),
156155
],
157156
),
158-
eol: Token(EndOfLine, "\n", (11,63)->(11,63)),
157+
eol: Token(EndOfLine, (11,63)->(11,63)),
159158
},
160159
),
161160
NoOp(
162161
Token(EndOfLine, "\n", (12,0)->(12,0)),
163162
),
164163
SharedCommand(
165164
SharedCommand {
166-
contents: " normal! v_y",
167-
eol: Token(EndOfLine, "\n", (13,14)->(13,14)),
165+
contents: " normal! v\"_y",
166+
eol: Token(EndOfLine, (13,15)->(13,15)),
168167
},
169168
),
170169
],
171170
},
172-
enddef: Token(Identifier, "enddef", (14,0)->(14,6)),
173-
end_eol: Token(EndOfLine, "\n", (14,6)->(14,6)),
171+
enddef: Token(Identifier, (14,0)->(14,6)),
172+
end_eol: Token(EndOfLine, (14,6)->(14,6)),
174173
},
175174
),
176175
]

0 commit comments

Comments
 (0)