Skip to content

Commit

Permalink
imp: 加入一项对dN语法的语义优化
Browse files Browse the repository at this point in the history
  • Loading branch information
fy0 committed Jun 7, 2024
1 parent e4ddd15 commit 977f712
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion roll.peg
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ _diceType2 <- [dD] nos
// 3d
_diceType3 <- nos [dD]
// d
_diceType4 <- [dD]
_diceType4 <- [dD] !xidStart

// XdY 中的 dy 部分,跟上面 _diceTypeX 一一对应
_diceExpr1 <- [dD] { c.data.AddOp(typeDiceInit); c.data.AddOp(typeDiceSetTimes); } nos _diceMod? _diceModType2?
Expand Down
13 changes: 10 additions & 3 deletions roll.peg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions rollvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1495,3 +1495,13 @@ func TestStackTop(t *testing.T) {
_ = vm.Run(`1;2; while (i<10) { i=i+1; 1;2;3 }`)
assert.Equal(t, vm.StackTop(), 2) // 语句块弃栈不影响上级
}

func TestFStringDiceType4(t *testing.T) {
vm := NewVM()
vm.Config.DisableNDice = false
err := vm.Run("`{db}`")
assert.NoError(t, err)

err = vm.Run("`{ddx}`")
assert.NoError(t, err)
}

0 comments on commit 977f712

Please sign in to comment.