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
5614984f
Unverified
Commit
5614984f
authored
Jul 25, 2023
by
Michael Yang
Committed by
GitHub
Jul 25, 2023
Browse files
Merge pull request #189 from Mohit-Gaur/main
Improve command parsing and multiline string handling
parents
07971759
f5f79049
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
parser/parser.go
parser/parser.go
+10
-7
No files found.
parser/parser.go
View file @
5614984f
...
@@ -20,7 +20,6 @@ func (c *Command) Reset() {
...
@@ -20,7 +20,6 @@ func (c *Command) Reset() {
func
Parse
(
reader
io
.
Reader
)
([]
Command
,
error
)
{
func
Parse
(
reader
io
.
Reader
)
([]
Command
,
error
)
{
var
commands
[]
Command
var
commands
[]
Command
var
command
,
modelCommand
Command
var
command
,
modelCommand
Command
scanner
:=
bufio
.
NewScanner
(
reader
)
scanner
:=
bufio
.
NewScanner
(
reader
)
...
@@ -47,6 +46,8 @@ func Parse(reader io.Reader) ([]Command, error) {
...
@@ -47,6 +46,8 @@ func Parse(reader io.Reader) ([]Command, error) {
command
.
Name
=
string
(
fields
[
0
])
command
.
Name
=
string
(
fields
[
0
])
command
.
Args
=
string
(
fields
[
1
])
command
.
Args
=
string
(
fields
[
1
])
default
:
default
:
// log a warning for unknown commands
fmt
.
Printf
(
"WARNING: Unknown command: %s
\n
"
,
fields
[
0
])
continue
continue
}
}
...
@@ -55,27 +56,29 @@ func Parse(reader io.Reader) ([]Command, error) {
...
@@ -55,27 +56,29 @@ func Parse(reader io.Reader) ([]Command, error) {
}
}
if
modelCommand
.
Args
==
""
{
if
modelCommand
.
Args
==
""
{
return
nil
,
fmt
.
Errorf
(
"no FROM line for the model was specified"
)
return
nil
,
errors
.
New
(
"no FROM line for the model was specified"
)
}
}
return
commands
,
scanner
.
Err
()
return
commands
,
scanner
.
Err
()
}
}
func
scanModelfile
(
data
[]
byte
,
atEOF
bool
)
(
advance
int
,
token
[]
byte
,
err
error
)
{
func
scanModelfile
(
data
[]
byte
,
atEOF
bool
)
(
advance
int
,
token
[]
byte
,
err
error
)
{
const
multilineString
=
`"""`
newline
:=
bytes
.
IndexByte
(
data
,
'\n'
)
newline
:=
bytes
.
IndexByte
(
data
,
'\n'
)
if
start
:=
bytes
.
Index
(
data
,
[]
byte
(
`"""`
));
start
>=
0
&&
start
<
newline
{
if
start
:=
bytes
.
Index
(
data
,
[]
byte
(
multilineString
));
start
>=
0
&&
start
<
newline
{
end
:=
bytes
.
Index
(
data
[
start
+
3
:
],
[]
byte
(
`"""`
))
end
:=
bytes
.
Index
(
data
[
start
+
len
(
multilineString
)
:
],
[]
byte
(
multilineString
))
if
end
<
0
{
if
end
<
0
{
if
atEOF
{
if
atEOF
{
return
0
,
nil
,
errors
.
New
(
`
unterminated multiline string: "
""`
)
return
0
,
nil
,
errors
.
New
(
"
unterminated multiline string: "
+
multilineString
)
}
else
{
}
else
{
return
0
,
nil
,
nil
return
0
,
nil
,
nil
}
}
}
}
n
:=
start
+
3
+
end
+
3
n
:=
start
+
len
(
multilineString
)
+
end
+
len
(
multilineString
)
return
n
,
bytes
.
Replace
(
data
[
:
n
],
[]
byte
(
`"""`
),
[]
byte
(
""
),
2
)
,
nil
return
n
,
data
[
:
n
]
,
nil
}
}
return
bufio
.
ScanLines
(
data
,
atEOF
)
return
bufio
.
ScanLines
(
data
,
atEOF
)
...
...
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