Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a proper parser for the path template syntax #121

Open
coryan opened this issue Nov 6, 2024 · 0 comments
Open

Use a proper parser for the path template syntax #121

coryan opened this issue Nov 6, 2024 · 0 comments
Labels
generator Issues related to the code generator priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@coryan
Copy link
Contributor

coryan commented Nov 6, 2024

We are using a regular expression to parse the path templates:

var HTTPPathVarRegex = regexp.MustCompile(`{([a-zA-Z0-9_.]+?)(=[^{}]+)?}`)

However, path templates cannot be parsed by regular expressions. Their grammar uses recursion:

// Template = "/" Segments [ Verb ] ;
// Segments = Segment { "/" Segment } ;
// Segment = "*" | "**" | LITERAL | Variable ;
// Variable = "{" FieldPath [ "=" Segments ] "}" ;
// FieldPath = IDENT { "." IDENT } ;
// Verb = ":" LITERAL ;

And therefore they form a non-regular language and require more than regular expressions to parse them correctly. Regular expressions will serve us well for a while, as very few services use the more complex forms of this grammar.

A small recursive descent parser can take care of this:

https://github.com/googleapis/google-cloud-cpp/blob/4174d656136f4b849c8a3d327237f3a96be3e003/generator/internal/http_annotation_parser.cc#L230-L250

@coryan coryan added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. priority: p3 Desirable enhancement or fix. May not be included in next release. generator Issues related to the code generator labels Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues related to the code generator priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

1 participant