Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 41 additions & 22 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"unicode"

"github.com/electrikmilk/args-parser"
"sourcecode.social/reiver/go-eol"
)

var filePath string
Expand Down Expand Up @@ -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]))
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 26 additions & 8 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/electrikmilk/args-parser"
"github.com/google/uuid"
"sourcecode.social/reiver/go-eol"
)

var idx int
Expand Down Expand Up @@ -186,7 +187,7 @@ func printParsingDebug() {

func parse() {
switch {
case char == ' ' || char == '\t' || char == '\n':
case isWhitespace():
advance()
case tokenAhead(Question):
collectQuestion()
Expand Down Expand Up @@ -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()
}
Expand All @@ -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])
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Loading