# Route definition and parser

Flamego's routing syntax is defined using the following BNF:

```ebnf
/* FIXME: `[]:,` are not allowed, since it may affect the binding processing */
<char> ::= [a-z] | [A-Z] | [0-9] | "-" | "." |  "_" |  "~" | "@" | "!" | "&" | "'" | "(" | ")" | "*" | "+" | ";" | "%" | "="
<any> ::= <char> | "[" | "]" | "+" | "," | "?" | "{" | "}" | " " | "\\" | "|"

<ident> ::= <char>+

<bind_parameter_value> ::= <ident> | "/" <any>+ "/"
<bind_parameter> ::= <ident> ":" " "* <bind_parameter_value>
<bind_parameters> ::= <bind_parameter> | <bind_parameters> "," " "* <bind_parameter>

<segment_element> ::= <ident> | "{" <ident> "}" | "{" <bind_parameters> "}"
<segment> ::= "/" "?"? <segment_element>*
<route> ::= <segment>+
```

The above BNF is generated and validated using https://bnfplayground.pauliankline.com/.

Converting the BNF to Go structs ([`definition.go`](definition.go)) that can be understood by [alecthomas/participle](https://github.com/alecthomas/participle) is currently a painful manual process. We're looking for a robust and automated code generation solution.

The EBNF generated by the parser is as follows:

```ebnf
Route = Segment+ .
Segment = "/" "?"? SegmentElement* .
SegmentElement = <ident> | ("{" <ident> "}") | ("{" BindParameters "}") .
BindParameters = (BindParameter ("," " "* BindParameter)*)+ .
BindParameter = <ident> ":" " "* BindParameterValue .
BindParameterValue = <ident> | ("/" <regex> "/") .
```
