Skip to content

Commit

Permalink
\ allows command over multiple lines in ocli files (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeremWD authored Aug 30, 2023
1 parent dfe110c commit 46801bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions CLI/ocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,24 @@ func parseFile(path string) ([]parsedLine, error) {
result := []parsedLine{}
var fileErr *fileParseError
scanner := bufio.NewScanner(file)
line := ""
startLineNumber := 1
for lineNumber := 1; scanner.Scan(); lineNumber++ {
line := scanner.Text()
if len(line) > 0 {
newLine := strings.TrimRight(scanner.Text(), " ")
if len(newLine) >= 1 && newLine[len(newLine)-1] == '\\' {
newLine = newLine[:len(newLine)-1]
line += newLine + "\n"
} else {
line += newLine
root, err := Parse(line)
if err != nil {
fileErr = addLineError(fileErr, err, filename, lineNumber, line)
fileErr = addLineError(fileErr, err, filename, startLineNumber, line)
}
if root != nil {
result = append(result, parsedLine{line, lineNumber, root})
result = append(result, parsedLine{line, startLineNumber, root})
}
line = ""
startLineNumber = lineNumber + 1
}
}
if fileErr != nil {
Expand Down
4 changes: 2 additions & 2 deletions CLI/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (p *parser) error(message string) {

func (p *parser) skipWhiteSpaces() {
defer un(trace(p, ""))
for p.cursor < len(p.buf) && (p.peek() == ' ' || p.peek() == '\t') {
for p.cursor < len(p.buf) && (p.peek() == ' ' || p.peek() == '\t' || p.peek() == '\n') {
p.forward(1)
}
}
Expand Down Expand Up @@ -309,7 +309,7 @@ loop:
}
}
if trim {
s = strings.Trim(s, " ")
s = strings.Trim(s, " \n")
}
if len(subExpr) == 0 {
return &valueNode{s}
Expand Down

0 comments on commit 46801bc

Please sign in to comment.