This commit is contained in:
parent
320e023d74
commit
ca91cd693c
18 changed files with 64 additions and 61 deletions
|
@ -15,12 +15,14 @@ var errs = []struct {
|
||||||
ExpectedError error
|
ExpectedError error
|
||||||
}{
|
}{
|
||||||
{"ExpectedFunctionDefinition.q", scanner.ExpectedFunctionDefinition},
|
{"ExpectedFunctionDefinition.q", scanner.ExpectedFunctionDefinition},
|
||||||
|
{"ExpectedFunctionDefinition2.q", scanner.ExpectedFunctionDefinition},
|
||||||
{"ExpectedPackageName.q", scanner.ExpectedPackageName},
|
{"ExpectedPackageName.q", scanner.ExpectedPackageName},
|
||||||
{"InvalidCharacter.q", &scanner.InvalidCharacter{Character: "@"}},
|
{"InvalidCharacter.q", &scanner.InvalidCharacter{Character: "@"}},
|
||||||
{"InvalidCharacter2.q", &scanner.InvalidCharacter{Character: "@"}},
|
{"InvalidCharacter2.q", &scanner.InvalidCharacter{Character: "@"}},
|
||||||
{"InvalidCharacter3.q", &scanner.InvalidCharacter{Character: "@"}},
|
{"InvalidCharacter3.q", &scanner.InvalidCharacter{Character: "@"}},
|
||||||
{"InvalidCharacter4.q", &scanner.InvalidCharacter{Character: "+++"}},
|
{"InvalidCharacter4.q", &scanner.InvalidCharacter{Character: "+++"}},
|
||||||
{"InvalidFunctionDefinition.q", scanner.InvalidFunctionDefinition},
|
{"InvalidFunctionDefinition.q", scanner.InvalidFunctionDefinition},
|
||||||
|
{"InvalidFunctionDefinition2.q", scanner.InvalidFunctionDefinition},
|
||||||
{"InvalidTopLevel.q", &scanner.InvalidTopLevel{Instruction: "123"}},
|
{"InvalidTopLevel.q", &scanner.InvalidTopLevel{Instruction: "123"}},
|
||||||
{"InvalidTopLevel2.q", &scanner.InvalidTopLevel{Instruction: "\"Hello\""}},
|
{"InvalidTopLevel2.q", &scanner.InvalidTopLevel{Instruction: "\"Hello\""}},
|
||||||
{"InvalidTopLevel3.q", &scanner.InvalidTopLevel{Instruction: "+"}},
|
{"InvalidTopLevel3.q", &scanner.InvalidTopLevel{Instruction: "+"}},
|
||||||
|
@ -28,6 +30,7 @@ var errs = []struct {
|
||||||
{"MissingBlockEnd2.q", scanner.MissingBlockEnd},
|
{"MissingBlockEnd2.q", scanner.MissingBlockEnd},
|
||||||
{"MissingBlockStart.q", scanner.MissingBlockStart},
|
{"MissingBlockStart.q", scanner.MissingBlockStart},
|
||||||
{"MissingGroupEnd.q", scanner.MissingGroupEnd},
|
{"MissingGroupEnd.q", scanner.MissingGroupEnd},
|
||||||
|
{"MissingGroupEnd2.q", scanner.MissingGroupEnd},
|
||||||
{"MissingGroupStart.q", scanner.MissingGroupStart},
|
{"MissingGroupStart.q", scanner.MissingGroupStart},
|
||||||
{"MissingParameter.q", scanner.MissingParameter},
|
{"MissingParameter.q", scanner.MissingParameter},
|
||||||
{"MissingParameter2.q", scanner.MissingParameter},
|
{"MissingParameter2.q", scanner.MissingParameter},
|
||||||
|
|
|
@ -56,13 +56,9 @@ func (s *scanner) scanFunction(file *fs.File, tokens token.List, i int) (int, er
|
||||||
return i, errors.New(MissingBlockEnd, file, tokens[i].Position)
|
return i, errors.New(MissingBlockEnd, file, tokens[i].Position)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bodyStart == -1 {
|
|
||||||
return i, errors.New(ExpectedFunctionDefinition, file, tokens[i].Position)
|
return i, errors.New(ExpectedFunctionDefinition, file, tokens[i].Position)
|
||||||
}
|
}
|
||||||
|
|
||||||
return i, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if blockLevel > 0 {
|
if blockLevel > 0 {
|
||||||
i++
|
i++
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -12,10 +12,10 @@ func scanSignature(file *fs.File, tokens token.List, i int, delimiter token.Kind
|
||||||
var (
|
var (
|
||||||
groupLevel = 0
|
groupLevel = 0
|
||||||
nameStart = i
|
nameStart = i
|
||||||
paramsStart = -1
|
inputStart = -1
|
||||||
paramsEnd = -1
|
inputEnd = -1
|
||||||
typeStart = -1
|
outputStart = -1
|
||||||
typeEnd = -1
|
outputEnd = -1
|
||||||
)
|
)
|
||||||
|
|
||||||
i++
|
i++
|
||||||
|
@ -27,7 +27,7 @@ func scanSignature(file *fs.File, tokens token.List, i int, delimiter token.Kind
|
||||||
i++
|
i++
|
||||||
|
|
||||||
if groupLevel == 1 {
|
if groupLevel == 1 {
|
||||||
paramsStart = i
|
inputStart = i
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
@ -41,7 +41,7 @@ func scanSignature(file *fs.File, tokens token.List, i int, delimiter token.Kind
|
||||||
}
|
}
|
||||||
|
|
||||||
if groupLevel == 0 {
|
if groupLevel == 0 {
|
||||||
paramsEnd = i
|
inputEnd = i
|
||||||
i++
|
i++
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,6 @@ func scanSignature(file *fs.File, tokens token.List, i int, delimiter token.Kind
|
||||||
return nil, i, errors.New(MissingGroupEnd, file, tokens[i].Position)
|
return nil, i, errors.New(MissingGroupEnd, file, tokens[i].Position)
|
||||||
}
|
}
|
||||||
|
|
||||||
if paramsStart == -1 {
|
|
||||||
return nil, i, errors.New(InvalidFunctionDefinition, file, tokens[i].Position)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, i, errors.New(InvalidFunctionDefinition, file, tokens[i].Position)
|
return nil, i, errors.New(InvalidFunctionDefinition, file, tokens[i].Position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,18 +72,18 @@ func scanSignature(file *fs.File, tokens token.List, i int, delimiter token.Kind
|
||||||
|
|
||||||
// Return type
|
// Return type
|
||||||
if i < len(tokens) && tokens[i].Kind == token.ReturnType {
|
if i < len(tokens) && tokens[i].Kind == token.ReturnType {
|
||||||
typeStart = i + 1
|
outputStart = i + 1
|
||||||
|
|
||||||
for i < len(tokens) && tokens[i].Kind != delimiter {
|
for i < len(tokens) && tokens[i].Kind != delimiter {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
typeEnd = i
|
outputEnd = i
|
||||||
}
|
}
|
||||||
|
|
||||||
name := tokens[nameStart].String(file.Bytes)
|
name := tokens[nameStart].String(file.Bytes)
|
||||||
function := core.NewFunction(name, file)
|
function := core.NewFunction(name, file)
|
||||||
parameters := tokens[paramsStart:paramsEnd]
|
parameters := tokens[inputStart:inputEnd]
|
||||||
|
|
||||||
for param := range parameters.Split {
|
for param := range parameters.Split {
|
||||||
if len(param) == 0 {
|
if len(param) == 0 {
|
||||||
|
@ -104,19 +100,26 @@ func scanSignature(file *fs.File, tokens token.List, i int, delimiter token.Kind
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if typeStart != -1 {
|
if outputStart == -1 {
|
||||||
if tokens[typeStart].Kind == token.GroupStart && tokens[typeEnd-1].Kind == token.GroupEnd {
|
return function, i, nil
|
||||||
typeStart++
|
|
||||||
typeEnd--
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outputTokens := tokens[typeStart:typeEnd]
|
if tokens[outputStart].Kind == token.GroupStart {
|
||||||
|
if tokens[outputEnd-1].Kind == token.GroupEnd {
|
||||||
|
outputStart++
|
||||||
|
outputEnd--
|
||||||
|
} else {
|
||||||
|
return nil, i, errors.New(MissingGroupEnd, file, tokens[outputEnd-1].Position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outputTokens := tokens[outputStart:outputEnd]
|
||||||
|
|
||||||
if len(outputTokens) == 0 {
|
if len(outputTokens) == 0 {
|
||||||
return nil, i, errors.New(MissingParameter, file, tokens[typeStart].Position)
|
return nil, i, errors.New(MissingParameter, file, tokens[outputStart].Position)
|
||||||
}
|
}
|
||||||
|
|
||||||
errorPos := token.Position(typeStart)
|
errorPos := token.Position(outputStart)
|
||||||
|
|
||||||
for param := range outputTokens.Split {
|
for param := range outputTokens.Split {
|
||||||
if len(param) == 0 {
|
if len(param) == 0 {
|
||||||
|
@ -137,7 +140,5 @@ func scanSignature(file *fs.File, tokens token.List, i int, delimiter token.Kind
|
||||||
|
|
||||||
errorPos = param[len(param)-1].End() + 1
|
errorPos = param[len(param)-1].End() + 1
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return function, i, nil
|
return function, i, nil
|
||||||
}
|
}
|
|
@ -1 +1 @@
|
||||||
main()
|
f()
|
1
src/scanner/testdata/errors/ExpectedFunctionDefinition2.q
vendored
Normal file
1
src/scanner/testdata/errors/ExpectedFunctionDefinition2.q
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
f() 123
|
|
@ -1 +1 @@
|
||||||
main@
|
f@
|
|
@ -1,4 +1,4 @@
|
||||||
main() {
|
f() {
|
||||||
x := 123 +++ 456
|
x := 123 +++ 456
|
||||||
syscall(60, x)
|
syscall(60, x)
|
||||||
}
|
}
|
|
@ -1,3 +1,3 @@
|
||||||
main() {
|
f() {
|
||||||
if 42 {}
|
if 42 {}
|
||||||
}
|
}
|
|
@ -1,3 +1,3 @@
|
||||||
main() {
|
f() {
|
||||||
syscall(+, -, *, /)
|
syscall(+, -, *, /)
|
||||||
}
|
}
|
|
@ -1 +1 @@
|
||||||
main
|
f
|
1
src/scanner/testdata/errors/InvalidFunctionDefinition2.q
vendored
Normal file
1
src/scanner/testdata/errors/InvalidFunctionDefinition2.q
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
f 123
|
|
@ -1 +1 @@
|
||||||
main(){
|
f(){
|
|
@ -1,3 +1,3 @@
|
||||||
main() {
|
f() {
|
||||||
loop {
|
loop {
|
||||||
}
|
}
|
|
@ -1 +1 @@
|
||||||
main()}
|
f()}
|
|
@ -1 +1 @@
|
||||||
main(
|
f(
|
1
src/scanner/testdata/errors/MissingGroupEnd2.q
vendored
Normal file
1
src/scanner/testdata/errors/MissingGroupEnd2.q
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
f() -> (
|
|
@ -1 +1 @@
|
||||||
main)
|
f)
|
|
@ -1 +1 @@
|
||||||
f(,) {}
|
f(a (int)->(int),) {}
|
Loading…
Add table
Add a link
Reference in a new issue