forked from TrueCloudLab/frostfs-sdk-go
[#280] policy: Use policyVisitor
as ErrorListener
for QueryLexer
Share `policyVisitor` instance as an `ErrorListener` provider for both `QueryLexer` and `Query`. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
dea3d9c419
commit
ab4d1e34a8
2 changed files with 13 additions and 3 deletions
|
@ -551,16 +551,17 @@ func writeFilterStringTo(w io.StringWriter, f netmap.Filter) error {
|
|||
// DecodeString decodes PlacementPolicy from the string composed using
|
||||
// WriteStringTo. Returns error if s is malformed.
|
||||
func (p *PlacementPolicy) DecodeString(s string) error {
|
||||
var v policyVisitor
|
||||
|
||||
input := antlr.NewInputStream(s)
|
||||
lexer := parser.NewQueryLexer(input)
|
||||
lexer.RemoveErrorListeners()
|
||||
lexer.AddErrorListener(&v)
|
||||
stream := antlr.NewCommonTokenStream(lexer, 0)
|
||||
|
||||
pp := parser.NewQuery(stream)
|
||||
pp.BuildParseTrees = true
|
||||
|
||||
var v policyVisitor
|
||||
|
||||
pp.RemoveErrorListeners()
|
||||
pp.AddErrorListener(&v)
|
||||
pl := pp.Policy().Accept(&v)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue