Skip to content

Commit 5c1b331

Browse files
committed
fix: expr precendence
1 parent 6220cb1 commit 5c1b331

6 files changed

Lines changed: 175 additions & 120 deletions

File tree

crates/vim9-gen/testdata/output/busted_shared.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("filename", function()
99
vim.v.errors = {}
1010

1111
-- Actual test
12-
vim.cmd([[ syn keyword Test testkeyword contained ]])
12+
pcall(vim.cmd, [[ syn keyword Test testkeyword contained ]])
1313
NVIM9.fn["assert_equal"](2, NVIM9.fn["len"](NVIM9.fn["split"](NVIM9.fn["execute"]("syntax list Test"), "\n")))
1414

1515
-- Assert that errors is still empty

crates/vim9-gen/testdata/output/vim9_gen__test__cfilter.snap

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/vim9-gen/src/lib.rs
3-
assertion_line: 1388
3+
assertion_line: 1389
44
expression: "generate(contents, false).unwrap()"
55
---
66
local NVIM9 = require("vim9script")
@@ -50,15 +50,31 @@ Qf_filter = function(qf, searchpat, bang)
5050
for _, val in ipairs({ ... }) do
5151
table.insert(copied, val)
5252
end
53-
return vim.fn["function"](unpack(copied))
53+
54+
local funcref = "getloclist"
55+
if type(funcref) == "function" then
56+
return funcref(unpack(copied))
57+
elseif type(funcref) == "string" then
58+
return vim.fn[funcref](unpack(copied))
59+
else
60+
error(string.format("unable to call funcref: %s", funcref))
61+
end
5462
end
5563

5664
Xsetlist = function(...)
5765
local copied = vim.deepcopy({ 0 })
5866
for _, val in ipairs({ ... }) do
5967
table.insert(copied, val)
6068
end
61-
return vim.fn["function"](unpack(copied))
69+
70+
local funcref = "setloclist"
71+
if type(funcref) == "function" then
72+
return funcref(unpack(copied))
73+
elseif type(funcref) == "string" then
74+
return vim.fn[funcref](unpack(copied))
75+
else
76+
error(string.format("unable to call funcref: %s", funcref))
77+
end
6278
end
6379

6480
cmd = NVIM9.ops["StringConcat"](":Lfilter", bang)

crates/vim9-parser/src/lib.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -725,17 +725,15 @@ pub struct Parameter {
725725
#[parse_context]
726726
impl Parameter {
727727
fn parse(parser: &Parser) -> Result<Parameter> {
728-
let name = dbg!(Identifier::parse_in_expression(parser)?);
728+
let name = Identifier::parse_in_expression(parser)?;
729729

730730
let ty = if parser.peek_real_kind() == TokenKind::SpacedColon {
731731
parser.next_real_token();
732-
Some(dbg!(Type::parse_in_expression(parser)?))
732+
Some(Type::parse_in_expression(parser)?)
733733
} else {
734734
None
735735
};
736736

737-
dbg!(parser);
738-
739737
let (equal, default_val) =
740738
if parser.peek_real_kind() == TokenKind::Equal {
741739
parser.next_real_token();
@@ -1022,7 +1020,7 @@ impl Lambda {
10221020
None
10231021
}
10241022
},
1025-
arrow: dbg!(parser).expect_token(TokenKind::Arrow)?.into(),
1023+
arrow: parser.expect_token(TokenKind::Arrow)?.into(),
10261024
body: {
10271025
if parser.front_kind() == TokenKind::LeftBrace {
10281026
todo!("parse blocks correctly");
@@ -1307,8 +1305,6 @@ pub enum Precedence {
13071305
Sum,
13081306
Product,
13091307
Modulo,
1310-
Prefix,
1311-
MethodCall,
13121308

13131309
/// PrefixExpr7 has a separate precendence:
13141310
///
@@ -1320,6 +1316,14 @@ pub enum Precedence {
13201316
/// -(1.234->string())
13211317
PrefixExpr7,
13221318

1319+
// <expr>-><funcname>()
1320+
MethodCall,
1321+
1322+
// +, -
1323+
// This is different than PrefixExpr7.
1324+
// See that enum for more details
1325+
Prefix,
1326+
13231327
Call,
13241328
Index,
13251329
Dot,
@@ -2581,9 +2585,7 @@ impl<'a> Parser<'a> {
25812585
}
25822586

25832587
fn parse_paramter_list(&self) -> Result<Vec<Parameter>> {
2584-
self.list_parser(TokenKind::RightParen, |p| {
2585-
dbg!(Parameter::parse(self))
2586-
})
2588+
self.list_parser(TokenKind::RightParen, |p| Parameter::parse(self))
25872589

25882590
// let mut params = Vec::new();
25892591
// while self.front_kind() != TokenKind::RightParen {

crates/vim9-parser/testdata/output/vim9_parser__test__handlers.snap

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/vim9-parser/src/lib.rs
3-
assertion_line: 2674
3+
assertion_line: 2719
44
expression: snapshot_parsing(contents)
55
---
66
[
@@ -5277,23 +5277,23 @@ expression: snapshot_parsing(contents)
52775277
If(
52785278
IfCommand {
52795279
if_tok: Token(Identifier, (332,4)->(332,6)),
5280-
condition: MethodCall(
5281-
MethodCall {
5282-
left: Prefix(
5283-
PrefixExpression {
5284-
token: Token(Bang, (332,7)->(332,8)),
5285-
operator: Bang,
5286-
right: Identifier(
5280+
condition: Prefix(
5281+
PrefixExpression {
5282+
token: Token(Bang, (332,7)->(332,8)),
5283+
operator: Bang,
5284+
right: MethodCall(
5285+
MethodCall {
5286+
left: Identifier(
52875287
Raw(symbolTypeTable),
52885288
),
5289+
tok: Token(MethodArrow, (332,23)->(332,25)),
5290+
right: f: Identifier(Raw(has_key)) arg: [
5291+
Identifier(
5292+
Raw(symbolType),
5293+
),
5294+
],
52895295
},
52905296
),
5291-
tok: Token(MethodArrow, (332,23)->(332,25)),
5292-
right: f: Identifier(Raw(has_key)) arg: [
5293-
Identifier(
5294-
Raw(symbolType),
5295-
),
5296-
],
52975297
},
52985298
),
52995299
if_eol: Token(EndOfLine, (332,44)->(332,44)),
@@ -5759,23 +5759,23 @@ expression: snapshot_parsing(contents)
57595759
If(
57605760
IfCommand {
57615761
if_tok: Token(Identifier, (359,4)->(359,6)),
5762-
condition: MethodCall(
5763-
MethodCall {
5764-
left: Prefix(
5765-
PrefixExpression {
5766-
token: Token(Bang, (359,7)->(359,8)),
5767-
operator: Bang,
5768-
right: Identifier(
5762+
condition: Prefix(
5763+
PrefixExpression {
5764+
token: Token(Bang, (359,7)->(359,8)),
5765+
operator: Bang,
5766+
right: MethodCall(
5767+
MethodCall {
5768+
left: Identifier(
57695769
Raw(symbolTypeTable),
57705770
),
5771+
tok: Token(MethodArrow, (359,23)->(359,25)),
5772+
right: f: Identifier(Raw(has_key)) arg: [
5773+
Identifier(
5774+
Raw(symbolType),
5775+
),
5776+
],
57715777
},
57725778
),
5773-
tok: Token(MethodArrow, (359,23)->(359,25)),
5774-
right: f: Identifier(Raw(has_key)) arg: [
5775-
Identifier(
5776-
Raw(symbolType),
5777-
),
5778-
],
57795779
},
57805780
),
57815781
if_eol: Token(EndOfLine, (359,44)->(359,44)),
@@ -7873,25 +7873,25 @@ expression: snapshot_parsing(contents)
78737873
If(
78747874
IfCommand {
78757875
if_tok: Token(Identifier, (487,4)->(487,6)),
7876-
condition: MethodCall(
7877-
MethodCall {
7878-
left: Prefix(
7879-
PrefixExpression {
7880-
token: Token(Bang, (487,7)->(487,8)),
7881-
operator: Bang,
7882-
right: Identifier(
7876+
condition: Prefix(
7877+
PrefixExpression {
7878+
token: Token(Bang, (487,7)->(487,8)),
7879+
operator: Bang,
7880+
right: MethodCall(
7881+
MethodCall {
7882+
left: Identifier(
78837883
Raw(symbol),
78847884
),
7885+
tok: Token(MethodArrow, (487,14)->(487,16)),
7886+
right: f: Identifier(Raw(has_key)) arg: [
7887+
String(
7888+
SingleQuote(
7889+
"location",
7890+
),
7891+
),
7892+
],
78857893
},
78867894
),
7887-
tok: Token(MethodArrow, (487,14)->(487,16)),
7888-
right: f: Identifier(Raw(has_key)) arg: [
7889-
String(
7890-
SingleQuote(
7891-
"location",
7892-
),
7893-
),
7894-
],
78957895
},
78967896
),
78977897
if_eol: Token(EndOfLine, (487,35)->(487,35)),
@@ -10503,31 +10503,31 @@ expression: snapshot_parsing(contents)
1050310503
If(
1050410504
IfCommand {
1050510505
if_tok: Token(Identifier, (642,2)->(642,4)),
10506-
condition: MethodCall(
10507-
MethodCall {
10508-
left: Prefix(
10509-
PrefixExpression {
10510-
token: Token(Bang, (642,5)->(642,6)),
10511-
operator: Bang,
10512-
right: Identifier(
10506+
condition: Prefix(
10507+
PrefixExpression {
10508+
token: Token(Bang, (642,5)->(642,6)),
10509+
operator: Bang,
10510+
right: MethodCall(
10511+
MethodCall {
10512+
left: Identifier(
1051310513
Raw(ftypeNtfOnceMap),
1051410514
),
10515+
tok: Token(MethodArrow, (642,21)->(642,23)),
10516+
right: f: Identifier(Raw(get)) arg: [
10517+
VimOption(
10518+
VimOption {
10519+
ampersand: Token(Ampersand, (642,27)->(642,28)),
10520+
option: Literal {
10521+
token: Token(Identifier, "ft", (642,28)->(642,30)),
10522+
},
10523+
},
10524+
),
10525+
Identifier(
10526+
Scope(ScopedIdentifier { scope: VimVar, colon: Token(Colon, (642,33)->(642,34)), accessor: Raw(false) }),
10527+
),
10528+
],
1051510529
},
1051610530
),
10517-
tok: Token(MethodArrow, (642,21)->(642,23)),
10518-
right: f: Identifier(Raw(get)) arg: [
10519-
VimOption(
10520-
VimOption {
10521-
ampersand: Token(Ampersand, (642,27)->(642,28)),
10522-
option: Literal {
10523-
token: Token(Identifier, "ft", (642,28)->(642,30)),
10524-
},
10525-
},
10526-
),
10527-
Identifier(
10528-
Scope(ScopedIdentifier { scope: VimVar, colon: Token(Colon, (642,33)->(642,34)), accessor: Raw(false) }),
10529-
),
10530-
],
1053110531
},
1053210532
),
1053310533
if_eol: Token(EndOfLine, (642,40)->(642,40)),
@@ -10994,25 +10994,25 @@ expression: snapshot_parsing(contents)
1099410994
If(
1099510995
IfCommand {
1099610996
if_tok: Token(Identifier, (678,2)->(678,4)),
10997-
condition: MethodCall(
10998-
MethodCall {
10999-
left: Prefix(
11000-
PrefixExpression {
11001-
token: Token(Bang, (678,5)->(678,6)),
11002-
operator: Bang,
11003-
right: Identifier(
10997+
condition: Prefix(
10998+
PrefixExpression {
10999+
token: Token(Bang, (678,5)->(678,6)),
11000+
operator: Bang,
11001+
right: MethodCall(
11002+
MethodCall {
11003+
left: Identifier(
1100411004
Raw(request),
1100511005
),
11006+
tok: Token(MethodArrow, (678,13)->(678,15)),
11007+
right: f: Identifier(Raw(has_key)) arg: [
11008+
String(
11009+
SingleQuote(
11010+
"params",
11011+
),
11012+
),
11013+
],
1100611014
},
1100711015
),
11008-
tok: Token(MethodArrow, (678,13)->(678,15)),
11009-
right: f: Identifier(Raw(has_key)) arg: [
11010-
String(
11011-
SingleQuote(
11012-
"params",
11013-
),
11014-
),
11015-
],
1101611016
},
1101711017
),
1101811018
if_eol: Token(EndOfLine, (678,32)->(678,32)),
@@ -12104,19 +12104,19 @@ expression: snapshot_parsing(contents)
1210412104
If(
1210512105
IfCommand {
1210612106
if_tok: Token(Identifier, (748,4)->(748,6)),
12107-
condition: MethodCall(
12108-
MethodCall {
12109-
left: Prefix(
12110-
PrefixExpression {
12111-
token: Token(Bang, (748,7)->(748,8)),
12112-
operator: Bang,
12113-
right: Identifier(
12107+
condition: Prefix(
12108+
PrefixExpression {
12109+
token: Token(Bang, (748,7)->(748,8)),
12110+
operator: Bang,
12111+
right: MethodCall(
12112+
MethodCall {
12113+
left: Identifier(
1211412114
Raw(req),
1211512115
),
12116+
tok: Token(MethodArrow, (748,11)->(748,13)),
12117+
right: f: Identifier(Raw(empty)) arg: [],
1211612118
},
1211712119
),
12118-
tok: Token(MethodArrow, (748,11)->(748,13)),
12119-
right: f: Identifier(Raw(empty)) arg: [],
1212012120
},
1212112121
),
1212212122
if_eol: Token(EndOfLine, (748,20)->(748,20)),

0 commit comments

Comments
 (0)