From d37b849a342314dd9787791b308cc19af2fc7e44 Mon Sep 17 00:00:00 2001 From: fy Date: Wed, 24 Apr 2024 16:51:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E4=B8=8D=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E6=B3=A8=E9=87=8A=E5=A4=B9=E7=A9=BA=E8=A1=8C=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test_and_lint.yml | 2 +- jsport/main.go | 2 +- jsport/package.json | 2 +- roll.peg | 2 +- roll.peg.go | 5 ++++- rollvm_test.go | 14 ++++++++++++++ 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test_and_lint.yml b/.github/workflows/test_and_lint.yml index d0218211..07e1e6b4 100644 --- a/.github/workflows/test_and_lint.yml +++ b/.github/workflows/test_and_lint.yml @@ -51,7 +51,7 @@ jobs: if: github.event.name == 'pull_request' with: go-version: '1.18' - version: 'v1.51.2' + version: 'v1.57.2' args: '--timeout 9999s' only-new-issues: true skip-pkg-cache: true diff --git a/jsport/main.go b/jsport/main.go index bb045d7a..2ce97ce9 100644 --- a/jsport/main.go +++ b/jsport/main.go @@ -4,10 +4,10 @@ package main import ( - "github.com/gopherjs/gopherjs/js" "regexp" "strconv" + "github.com/gopherjs/gopherjs/js" ds "github.com/sealdice/dicescript" ) diff --git a/jsport/package.json b/jsport/package.json index 87174a16..e72203b8 100644 --- a/jsport/package.json +++ b/jsport/package.json @@ -1,6 +1,6 @@ { "name": "dicescript", - "version": "0.1.2", + "version": "0.1.3", "description": "Simple script language for TRPG dice engine.", "module": "./dist/main.mjs", "type": "module", diff --git a/roll.peg b/roll.peg index 0e10632f..9b792950 100644 --- a/roll.peg +++ b/roll.peg @@ -28,7 +28,7 @@ stmtRoot <- stmtLines sp // stmtLines stmtLines <- &{!p.Config.DisableStmts} stmtWithBlock stmtLines? / flagsSwitch stmtLines? - / comment stmtLines? + / comment sp stmtLines? / stmtWithSemicolon nextLine? / (';' sp)+ stmtLines? diff --git a/roll.peg.go b/roll.peg.go index 9625f447..d6069316 100644 --- a/roll.peg.go +++ b/roll.peg.go @@ -2169,7 +2169,7 @@ func (p *Parser) Init(options ...func(*Parser) error) error { position, tokenIndex = position103, tokenIndex103 return false }, - /* 3 stmtLines <- <((&{!p.Config.DisableStmts} stmtWithBlock stmtLines?) / (flagsSwitch stmtLines?) / (comment stmtLines?) / (stmtWithSemicolon nextLine?) / ((';' sp)+ stmtLines?))> */ + /* 3 stmtLines <- <((&{!p.Config.DisableStmts} stmtWithBlock stmtLines?) / (flagsSwitch stmtLines?) / (comment sp stmtLines?) / (stmtWithSemicolon nextLine?) / ((';' sp)+ stmtLines?))> */ func() bool { position105, tokenIndex105 := position, tokenIndex { @@ -2822,6 +2822,9 @@ func (p *Parser) Init(options ...func(*Parser) error) error { l170: add(rulecomment, position166) } + if !_rules[rulesp]() { + goto l165 + } { position173, tokenIndex173 := position, tokenIndex if !_rules[rulestmtLines]() { diff --git a/rollvm_test.go b/rollvm_test.go index 75508e86..59c41d2b 100644 --- a/rollvm_test.go +++ b/rollvm_test.go @@ -1093,6 +1093,20 @@ func TestComment(t *testing.T) { } } +func TestComment2(t *testing.T) { + // 发现注释间无法空行,予以修复 + vm := NewVM() + err := vm.Run(` +//c1 + + +//c2 +a = 1; a`) + assert.NoError(t, err) + assert.Equal(t, vm.RestInput, "") + assert.True(t, valueEqual(vm.Ret, ni(1))) +} + func TestDiceAndSpaceBug(t *testing.T) { // 一个错误的代码逻辑: 部分算符后需要跟sp1,导致f +1可以工作,但f+1不行 // 但也不能让 f1 被解析为f,剩余文本1