diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7079b96..11e65de 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,37 +13,56 @@ jobs: build-test-linux: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: 1.24 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.24 - - name: Build - run: go build -v ./... + - name: Build + run: go build -v ./... - - name: Test - run: go test -run TestCherriNoSign -v ./... + - name: Test + run: go test -run TestCherriNoSign -v ./... - - name: Decompilation Test - run: go test -run TestDecomp -v ./... + - name: Decompilation Test + run: go test -run TestDecomp -v ./... build-test-macos: runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: 1.24 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.24 - - name: Build - run: go build -v ./... + - name: Build + run: go build -v ./... - - name: Test - run: go test -run TestCherriNoSign -v ./... + - name: Test + run: go test -run TestCherriNoSign -v ./... - - name: Decompilation Test - run: go test -run TestDecomp -v ./... + - name: Decompilation Test + run: go test -run TestDecomp -v ./... + + build-test-windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.24 + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -run TestCherriNoSign -v ./... + + - name: Decompilation Test + run: go test -run TestDecomp -v ./... diff --git a/go.mod b/go.mod index 2316e24..d4c3607 100644 --- a/go.mod +++ b/go.mod @@ -6,4 +6,12 @@ require github.com/google/uuid v1.6.0 require github.com/electrikmilk/args-parser v1.1.3 -require howett.net/plist v1.0.1 +require ( + howett.net/plist v1.0.1 + sourcecode.social/reiver/go-eol v0.0.0-20240326064055-6080dd101592 +) + +require ( + sourcecode.social/reiver/go-erorr v0.0.0-20230922202459-231149d185a1 // indirect + sourcecode.social/reiver/go-opt v0.0.0-20231106172254-6b4ca5231f41 // indirect +) diff --git a/go.sum b/go.sum index 4c9f482..9facf3d 100644 --- a/go.sum +++ b/go.sum @@ -7,3 +7,9 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= howett.net/plist v1.0.1 h1:37GdZ8tP09Q35o9ych3ehygcsL+HqKSwzctveSlarvM= howett.net/plist v1.0.1/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g= +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= diff --git a/main.go b/main.go index 0c2e4da..0117929 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( "unicode" "github.com/electrikmilk/args-parser" + "sourcecode.social/reiver/go-eol" ) var filePath string @@ -212,7 +213,7 @@ func lineReport(label string) { if idx != 0 { fmt.Println("Previous Character:") var prevChar = prev(1) - if prevChar != '\n' { + if !eol.IsEOL(prevChar) { printChar(prevChar, lineIdx, lineCharIdx-1) } else { printChar(prevChar, lineIdx-1, len(lines[lineIdx-1])) @@ -226,7 +227,7 @@ func lineReport(label string) { if len(contents) > idx+1 { fmt.Println("Next Character:") var nextChar = next(1) - if char != '\n' { + if !eol.IsEOL(nextChar) { printChar(nextChar, lineIdx, lineCharIdx+1) } else { printChar(nextChar, lineIdx+1, 0) diff --git a/output.go b/output.go index 9495035..7009e32 100644 --- a/output.go +++ b/output.go @@ -72,6 +72,8 @@ func printChar(ch rune, chLineIdx int, chLineCharIdx int) { currentChar = "TAB" case '\n': currentChar = "LF" + case '\r': + currentChar = "CR" case -1: currentChar = "EMPTY" default: diff --git a/parser.go b/parser.go index 9652aa1..334e1b1 100644 --- a/parser.go +++ b/parser.go @@ -16,6 +16,7 @@ import ( "github.com/electrikmilk/args-parser" "github.com/google/uuid" + "sourcecode.social/reiver/go-eol" ) var idx int @@ -186,7 +187,7 @@ func printParsingDebug() { func parse() { switch { - case char == ' ' || char == '\t' || char == '\n': + case isWhitespace(): advance() case tokenAhead(Question): collectQuestion() @@ -266,6 +267,9 @@ func collectUntilIgnoreStrings(ch rune) string { func collectUntil(ch rune) string { var collected strings.Builder for char != ch && char != -1 { + if ch == '\n' && isEOL() { + break + } collected.WriteRune(char) advance() } @@ -282,6 +286,9 @@ func lookAheadUntil(until rune) string { if len(chars) <= nextIdx { break } + if until == '\n' && isEOL() { + break + } nextChar = chars[nextIdx] ahead.WriteRune(chars[nextIdx]) @@ -1495,7 +1502,7 @@ func collectAction(identifier *string) (value action) { // advance advances the character cursor. func advance() { - if char == '\n' { + if isEOL() { lineCharIdx = 0 lineIdx++ } else { @@ -1520,6 +1527,9 @@ func advanceTimes(times int) { // advanceUntil advances the character cursor until we reach `ch`. func advanceUntil(ch rune) { for char != ch && char != -1 { + if ch == '\n' && isEOL() { + break + } advance() } } @@ -1586,6 +1596,20 @@ func seek(mov *int, reverse bool) rune { return getChar(nextChar) } +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' || char == '\r' +} + func getChar(atIndex int) rune { if atIndex < 0 { return -1 @@ -1603,12 +1627,6 @@ func firstChar() { advance() } -func skipWhitespace() { - for char == ' ' || char == '\t' || char == '\n' { - advance() - } -} - func printVariables() { for identifier, v := range variables { if v.constant {