You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am writing a A10 loadbalancer configuration parser which syntax is similar to cisco config files.
Here is a config block example:
slb virtual-server svc1.example.com 10.0.0.1
port 80 http
name svc1.example.com-http
aflex HTTP_To_HTTPS
port 443 https
name svc1.example.com-https
source-nat pool SNAT-10.10.0.240-254
service-group svc1.example.com-https
template http default-http
template waf svc1.example.com
template client-ssl wildcard.example.com
port 4172 tcp
name tcp1.example.com-tcp
source-nat pool SNAT-10.10.0.240-254
service-group tcp1.example.com-tcp
template persist source-ip tpl-srcip
My go file looks like:
package main
import (
"github.com/alecthomas/participle/v2""github.com/alecthomas/participle/v2/lexer""github.com/alecthomas/repr"
)
var (
a10Lexer=lexer.MustSimple(
[]lexer.Rule{
{"whitespace", `\s+`, nil},
{"eol", `[\n\r]+`, nil},
{"Punct", `[ \t\n]`, nil},
{"Int", `\d+`, nil},
{"Ident", `[A-Za-z0-9._-][A-Za-z0-9._-]*`, nil},
},
lexer.MatchLongest(),
)
)
// SlbVirtualServer holds virtual-server definition.//// virtual-server consists of a name, a bind IP address and a list of// service definition.//// In A10 configuration file a virtual-server starts with://// !// slb virtual-server NAME IP// ...// !typeSlbVirtualServerstruct {
Pos lexer.PositionNamestring`"slb" "virtual-server" @(Ident)`Ipstring`@(Ident)`Service []*SlbVirtualServerService`("port" @@)*`
}
// SlbVirtualServerService holds a virtual-server service definition.// Each service definiton starts with://// port PORT PROTOCOL// ...//// A service has several optional directives such as name, source-nat// definition, service group definiton, list of templates to apply,// etc...typeSlbVirtualServerServicestruct {
// Port and Protocol appear on the same linePortint`@(Int)`Protocolstring`@("http" | "https" | "tcp" | "udp" | "ssl-proxy")`// Other resources should be defined in any order.// However this definition generates an error://// panic: 10:1: too many iterations of (("name" <ident>) | ("source-nat" SlbVirtualServerServiceSourceNat) | ("service-group" <ident>) | ("template" "persist"? SlbVirtualServerServiceTemplate)* | ("aflex" <ident>)?)* (> 1000000)//Namestring`( "name" @(Ident)`SourceNat*SlbVirtualServerServiceSourceNat` | "source-nat" @@`ServiceGroupstring` | "service-group" @(Ident)`Templates []*SlbVirtualServerServiceTemplate` | ( "template" "persist"? @@ )*`Aflexstring` | ("aflex" @(Ident))? )*`
}
// SlbVirtualServerServiceSourceNat host a service source-nat// definiton such as://// source-nat TYPE SNAT_STRINGtypeSlbVirtualServerServiceSourceNatstruct {
Typestring`@(Ident)`Namestring`@(Ident)`
}
// SlbVirtualServerServiceTemplate holds a service template// definiton such as://// template TYPE NAMEtypeSlbVirtualServerServiceTemplatestruct {
Typestring`@(Ident)`Namestring`@(Ident)`
}
// newLtmVirtual parses data and creates a new SlbVirtualServer struct.funcnewSlbVirtualServer(datastring) (ret*SlbVirtualServer, errerror) {
ret=&SlbVirtualServer{}
err=parseString("", data, ret)
return
}
// parseString parses the data string into obj.funcparseString(name, datastring, objany) (errerror) {
parser:=participle.MustBuild(
obj,
participle.Lexer(a10Lexer),
)
err=parser.ParseString(name, data, obj)
return
}
funcmain() {
data:=`slb virtual-server svc1.example.com 10.0.0.1 port 80 http name svc1.example.com-http aflex HTTP_To_HTTPS port 443 https name svc1.example.com-https source-nat pool SNAT-10.10.0.240-254 service-group svc1.example.com-https template http default-http template waf svc1.example.com template client-ssl wildcard.example.com port 4172 tcp name tcp1.example.com-tcp source-nat pool SNAT-10.10.0.240-254 service-group tcp1.example.com-tcp template persist source-ip tpl-srcip`newSlbVirtualServer, err:=newSlbVirtualServer(data)
iferr!=nil {
panic(err)
}
repr.Println(newSlbVirtualServer)
}
However when I run it I panics:
The problem I see is that the service definition has no end delimiter. Hence I am not sure about the struct defintion:
Hello,
I am writing a A10 loadbalancer configuration parser which syntax is similar to cisco config files.
Here is a config block example:
My go file looks like:
However when I run it I panics:
The problem I see is that the service definition has no end delimiter. Hence I am not sure about the struct defintion:
Did I missed something?
Thanks in advance.
The text was updated successfully, but these errors were encountered: