From 46801bc432b60024868dba06244040dd8806ddb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9r=C3=A9my=20Hutin?= Date: Wed, 30 Aug 2023 10:21:16 +0200 Subject: [PATCH] \ allows command over multiple lines in ocli files (#142) --- CLI/ocli.go | 16 ++++++++++++---- CLI/parser.go | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CLI/ocli.go b/CLI/ocli.go index 695877d0d..7c91e6c4f 100644 --- a/CLI/ocli.go +++ b/CLI/ocli.go @@ -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 { diff --git a/CLI/parser.go b/CLI/parser.go index 0c2b6e7ef..4ae7949d4 100644 --- a/CLI/parser.go +++ b/CLI/parser.go @@ -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) } } @@ -309,7 +309,7 @@ loop: } } if trim { - s = strings.Trim(s, " ") + s = strings.Trim(s, " \n") } if len(subExpr) == 0 { return &valueNode{s}