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

bugfix #77: Fix error and debug line/columns #78

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions cherri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ package main
import (
"encoding/json"
"fmt"
"github.com/electrikmilk/args-parser"
"os"
"strings"
"testing"
"time"

"github.com/electrikmilk/args-parser"
)

var currentTest string
Expand Down Expand Up @@ -91,7 +92,7 @@ func resetParser() {
char = -1
idx = 0
lineIdx = 0
lineCharIdx = 0
lineCharIdx = -1
groupingUUIDs = map[int]string{}
groupingTypes = map[int]tokenType{}
groupingIdx = 0
Expand Down
8 changes: 2 additions & 6 deletions copy_paste.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package main

import (
"fmt"
"github.com/electrikmilk/args-parser"
"regexp"
"strings"

"github.com/electrikmilk/args-parser"
)

var pasteables map[string]string
Expand Down Expand Up @@ -63,11 +64,6 @@ func collectCopy() {

func pasteCopy() {
var identifier = collectIdentifier()
if char == '\n' {
idx--
lineIdx--
lineCharIdx = len(lines[lineIdx])
}
if contents, found := pasteables[identifier]; found {
lines[lineIdx] = contents
} else {
Expand Down
4 changes: 2 additions & 2 deletions includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ package main

import (
"fmt"
"github.com/electrikmilk/args-parser"
"os"
"slices"
"strings"

"github.com/electrikmilk/args-parser"
)

// include is a data structure to track include statements.
Expand Down Expand Up @@ -78,7 +79,6 @@ func parseInclude() {
advance()

var includePath = collectRawString()
lineIdx--

if slices.Contains(included, includePath) {
parserError(fmt.Sprintf("File '%s' has already been included.", includePath))
Expand Down
7 changes: 4 additions & 3 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package main

import (
"fmt"
"github.com/electrikmilk/args-parser"
"os"
"os/exec"

"github.com/electrikmilk/args-parser"
)

// writeFile writes plist in bytes to filename.
Expand Down Expand Up @@ -56,7 +57,7 @@ func openShortcut() {
handle(importErr)
}

func printChar(ch rune) {
func printChar(ch rune, chLineIdx int, chLineCharIdx int) {
var currentChar string
switch ch {
case ' ':
Expand All @@ -70,7 +71,7 @@ func printChar(ch rune) {
default:
currentChar = string(ch)
}
fmt.Printf("%s %d:%d\n", currentChar, lineIdx+1, lineCharIdx)
fmt.Printf("%s %d:%d\n", currentChar, chLineIdx+1, chLineCharIdx+1)
}

type outputType int
Expand Down
36 changes: 22 additions & 14 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func initParse() {
char = -1
idx = -1
lineIdx = 0
lineCharIdx = 0
lineCharIdx = -1
chars = []rune{}
lines = []string{}
groupingUUIDs = map[int]string{}
Expand Down Expand Up @@ -112,16 +112,26 @@ func printParsingDebug() {

if idx != 0 {
fmt.Println("Previous Character:")
printChar(prev(1))
var prevChar = prev(1)
if prevChar != '\n' {
printChar(prevChar, lineIdx, lineCharIdx-1)
} else {
printChar(prevChar, lineIdx-1, len(lines[lineIdx-1]))
}
}

fmt.Println("\nCurrent Character:")
printChar(char)
printChar(char, lineIdx, lineCharIdx)
fmt.Print("\n")

if len(contents) > idx+1 {
fmt.Println("Next Character:")
printChar(next(1))
var nextChar = next(1)
if char != '\n' {
printChar(nextChar, lineIdx, lineCharIdx+1)
} else {
printChar(nextChar, lineIdx+1, 0)
}
fmt.Print("\n")
}

Expand Down Expand Up @@ -272,7 +282,6 @@ func collectVariableValue(constant bool, valueType *tokenType, value *any, coerc
collectValue(valueType, value, '\n')

if constant && (*valueType == Arr || *valueType == Variable) {
lineIdx--
parserError(fmt.Sprintf("Type %v values cannot be constants.", *valueType))
}
if *valueType == Question {
Expand Down Expand Up @@ -555,7 +564,6 @@ func collectVariable(constant bool) {
skipWhitespace()
collectType(&valueType, &value)
case constant:
lineIdx--
parserError("Constants must be initialized with a value.")
}

Expand Down Expand Up @@ -1312,19 +1320,19 @@ func collectAction(identifier *string) (value action) {

// advance advances the character cursor.
func advance() {
idx++
if len(chars) <= idx {
char = -1
return
}

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

idx++
if len(chars) <= idx {
char = -1
return
}
char = chars[idx]
}

// advanceTimes advances the character cursor by `times`.
Expand Down Expand Up @@ -1425,7 +1433,7 @@ func getChar(atIndex int) rune {

func firstChar() {
lineIdx = 0
lineCharIdx = 0
lineCharIdx = -1
idx = -1
advance()
}
Expand Down