Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
4e986a82
Commit
4e986a82
authored
Jun 27, 2024
by
Josh Yan
Browse files
unquote, trimp space
parent
cb42e607
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletion
+33
-1
parser/parser.go
parser/parser.go
+8
-1
parser/parser_test.go
parser/parser_test.go
+25
-0
No files found.
parser/parser.go
View file @
4e986a82
...
...
@@ -125,6 +125,7 @@ func ParseFile(r io.Reader) (*File, error) {
// pass
case
stateValue
:
s
,
ok
:=
unquote
(
b
.
String
())
if
!
ok
||
isSpace
(
r
)
{
if
_
,
err
:=
b
.
WriteRune
(
r
);
err
!=
nil
{
return
nil
,
err
...
...
@@ -158,7 +159,13 @@ func ParseFile(r io.Reader) (*File, error) {
case
stateComment
,
stateNil
:
// pass; nothing to flush
case
stateValue
:
s
,
ok
:=
unquote
(
b
.
String
())
var
s
string
var
ok
bool
if
cmd
.
Name
==
"model"
{
s
,
ok
=
unquote
(
strings
.
TrimSpace
(
b
.
String
()))
}
else
{
s
,
ok
=
unquote
(
b
.
String
())
}
if
!
ok
{
return
nil
,
io
.
ErrUnexpectedEOF
}
...
...
parser/parser_test.go
View file @
4e986a82
...
...
@@ -48,6 +48,26 @@ func TestParseFileFrom(t *testing.T) {
expected
[]
Command
err
error
}{
{
"FROM
\"
FOO BAR
\"
"
,
[]
Command
{{
Name
:
"model"
,
Args
:
"FOO BAR "
}},
nil
,
},
{
"FROM
\"
FOO BAR
\"\n
PARAMETER param1 value1"
,
[]
Command
{{
Name
:
"model"
,
Args
:
"FOO BAR"
},
{
Name
:
"param1"
,
Args
:
"value1"
}},
nil
,
},
{
"FROM FOOO BAR "
,
[]
Command
{{
Name
:
"model"
,
Args
:
"FOOO BAR"
}},
nil
,
},
{
"FROM /what/is/the path "
,
[]
Command
{{
Name
:
"model"
,
Args
:
"/what/is/the path"
}},
nil
,
},
{
"FROM foo"
,
[]
Command
{{
Name
:
"model"
,
Args
:
"foo"
}},
...
...
@@ -86,6 +106,11 @@ func TestParseFileFrom(t *testing.T) {
[]
Command
{{
Name
:
"param1"
,
Args
:
"value1"
},
{
Name
:
"model"
,
Args
:
"foo"
}},
nil
,
},
{
"PARAMETER what the
\n
FROM lemons make lemonade "
,
[]
Command
{{
Name
:
"what"
,
Args
:
"the "
},
{
Name
:
"model"
,
Args
:
"lemons make lemonade"
}},
nil
,
},
}
for
_
,
c
:=
range
cases
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment