Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Try to fix tests on Windows #54

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
7 changes: 5 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches: [ "main" ]

jobs:
build-test:
build-test-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Build
run: go build -v ./...

build-windows:
build-test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -51,3 +51,6 @@ jobs:

- name: Build
run: go build -v ./...

- name: Test
run: go test -run TestCherri -v ./...
7 changes: 3 additions & 4 deletions copy_paste.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ func collectCopy() {

func pasteCopy() {
var identifier = collectIdentifier()
if char == '\n' {
idx--
lineIdx--
lineCharIdx = len(lines[lineIdx])
if isEOL() || char == -1 {
reverse()
}

if contents, found := pasteables[identifier]; found {
lines[lineIdx] = contents
} else {
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ go 1.22
require github.com/google/uuid v1.6.0

require github.com/electrikmilk/args-parser v1.1.3

require (
sourcecode.social/reiver/go-eol v0.0.0-20240326064055-6080dd101592 // indirect
sourcecode.social/reiver/go-erorr v0.0.0-20230922202459-231149d185a1 // indirect
sourcecode.social/reiver/go-opt v0.0.0-20231106172254-6b4ca5231f41 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ github.com/electrikmilk/args-parser v1.1.3 h1:66xFYBDmsO3mZvIM1ThO/AV/3zTRwfE45A
github.com/electrikmilk/args-parser v1.1.3/go.mod h1:mb/l2JFNNBSA8GVYL0eQCJF6Jd7UtAJTpenLZs6iIJ0=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
sourcecode.social/reiver/go-eol v0.0.0-20240326064055-6080dd101592 h1:5lIRVxewoVEKA8AB/xLirgx16VVGAvYY15BWZzLQdh0=
sourcecode.social/reiver/go-eol v0.0.0-20240326064055-6080dd101592/go.mod h1:2OmaB7yZ5/S7rix/3mhFkLZ1HwkgCBt6NqdB4fFGQjI=
sourcecode.social/reiver/go-erorr v0.0.0-20230922202459-231149d185a1 h1:wpnz4JicQBLWrgGphYBls7DysIFCcnWgDz/vce/sY8E=
sourcecode.social/reiver/go-erorr v0.0.0-20230922202459-231149d185a1/go.mod h1:NFtd7fzEf0r6A6R7JXYZfayRhPaJy0zt/18VWoLzrxA=
sourcecode.social/reiver/go-opt v0.0.0-20231106172254-6b4ca5231f41 h1:nWUCtY3Krm+bLKXEEFvVz+vm256v3D/iJXgfoWhcOEw=
sourcecode.social/reiver/go-opt v0.0.0-20231106172254-6b4ca5231f41/go.mod h1:O6WKM2UcKkheRT/dA6A2b1tW0m+WenSbxdcXE+idxzI=
70 changes: 57 additions & 13 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"regexp"
"slices"
"sourcecode.social/reiver/go-eol"
"strconv"
"strings"
"unicode"
Expand Down Expand Up @@ -163,7 +164,7 @@ func printParsingDebug() {

func parse() {
switch {
case char == ' ' || char == '\t' || char == '\n':
electrikmilk marked this conversation as resolved.
Show resolved Hide resolved
case isWhitespace():
advance()
case tokenAhead(Question):
collectQuestion()
Expand Down Expand Up @@ -251,7 +252,7 @@ func lookAheadUntil(until rune) string {
var ahead strings.Builder
var nextIdx = idx
var nextChar rune
for nextChar != until {
for !cmpChar(nextChar, until) {
if len(chars) <= nextIdx {
break
}
Expand Down Expand Up @@ -430,7 +431,7 @@ func collectArguments() (arguments []actionArgument) {
var argIndex = 0
var param parameterDefinition
for {
if char == ')' || char == '\n' || char == -1 {
if char == ')' || isEOL() || char == -1 {
break
}
if argIndex < paramsSize {
Expand Down Expand Up @@ -1297,6 +1298,40 @@ func collectAction(identifier *string) (value action) {
return
}

// isEOL returns bool based on if current char is an isEOL.
func isEOL() bool {
return eol.IsEOL(char)
}

func skipWhitespace() {
for isWhitespace() {
advance()
}
}

func isWhitespace() bool {
return unicode.IsSpace(char) || isEOL() || char == '\t' || char == ' ' || char == '\n'
}

func isCurrentChar(ch rune) bool {
if ch == '\n' {
return eol.IsEOL(char)
}

return ch == char
}

func cmpChar(ch1 rune, ch2 rune) bool {
if ch1 == '\n' {
return eol.IsEOL(ch2)
}
if ch2 == '\n' {
return eol.IsEOL(ch1)
}

return ch1 == ch2
}

// advance advances the character cursor.
func advance() {
idx++
Expand All @@ -1306,14 +1341,29 @@ func advance() {
}

char = chars[idx]
if char == '\n' {
if isEOL() {
lineCharIdx = 0
lineIdx++
} else {
lineCharIdx++
}
}

// reverse reverses the character cursor.
func reverse() {
idx--
if idx < 0 {
char = -1
return
}
if lineCharIdx == 0 {
lineIdx--
}

lineCharIdx = len(lines[lineIdx])
char = chars[idx]
}

// advanceTimes advances the character cursor by `times`.
func advanceTimes(times int) {
for i := 0; i < times; i++ {
Expand All @@ -1323,7 +1373,7 @@ func advanceTimes(times int) {

// advanceUntil advances the character cursor until we reach `ch`.
func advanceUntil(ch rune) {
for char != ch && char != -1 {
for !isCurrentChar(ch) && char != -1 {
advance()
}
}
Expand All @@ -1332,7 +1382,7 @@ func advanceUntil(ch rune) {
// However, it expects to reach this character by no more than `maxAdvances` advances and throws a parser error if it doesn't.
func advanceUntilExpect(ch rune, maxAdvances int) {
var advances int
for char != ch && char != -1 {
for !isCurrentChar(ch) && char != -1 {
if advances > maxAdvances {
parserError(fmt.Sprintf("Expected %c", ch))
}
Expand All @@ -1343,7 +1393,7 @@ func advanceUntilExpect(ch rune, maxAdvances int) {

// If char is tokenChar, advance.
func isChar(tokenChar rune) bool {
if char != tokenChar {
if !isCurrentChar(tokenChar) {
return false
}
advance()
Expand Down Expand Up @@ -1417,12 +1467,6 @@ func firstChar() {
advance()
}

func skipWhitespace() {
for char == ' ' || char == '\t' || char == '\n' {
advance()
}
}

func printVariables() {
for identifier, v := range variables {
if v.constant {
Expand Down
Loading