Skip to content
riccafi edited this page Nov 30, 2023 · 2 revisions

Queryparser

This is the wiki of Queryparser project.

How to include parsing rules

It's possible add new parsing rules. What do you need to do?

The file queryparser.y includes all the parsing rules.
If you change the regexp expression, you have to update the switch cases for each single token.
This means that if you have to insert a new part of regular expression such as a new operator like NEW-OPERATOR into section:
^((?P<op>((OR)|(NOT)|(AND)))|(?P<comp>((\!\=)|(\!\~)|(
it will change into
^((?P<op>((OR)|(NOT)|(NEW-OPERATOR)|(AND)))|(?P<comp>((\!\=)|(\!\~)|(
but also the lex rules such us:

                  [...]
  	case 12:
  	    t = AND
  	    lval.token = common.Token{Position: l.pos + start, Token: t, Literal: "AND"}
  	    break
                  [...]

will have to be changed for AND and for all following parsing rules:

                  [...]
  	case 16: //it will be a case number greater than 12 that can be found with the snippet of source code of this page
  	    t = AND
  	    lval.token = common.Token{Position: l.pos + start, Token: t, Literal: "AND"}
  	    break
                  [...]

You can try what case will be identified running on https://go.dev/play/ the following snippet of source code:

// You can edit this code!
// Click here and start typing.
package main

import (
"fmt"
"regexp"
)

func main() {
rex := regexp.MustCompile("you should insert here regexp expression of queryparser.y")
string := "!?"
result := rex.FindSubmatchIndex([]byte(string))
for k, index := range result {
if index != -1 && k%2 == 0 {
fmt.Println(k)
}
}
//fmt.Println(result)

}

Once you completed to update the rules you can enter into parser folder and start the following command:
goyacc -o queryparser.go -p Query queryparser.y
This command will update the file queryparser.go that will be used by the software.

Clone this wiki locally