nginxinc / nginx-go-crossplane

A library for working with NGINX configs in Go
Apache License 2.0
46 stars 12 forks source link

Add all 16 *_by_lua_block and 9 *_by_lua directives to crossplane #86

Closed xynicole closed 2 months ago

xynicole commented 4 months ago

Proposed changes

Add all 16 _by_lua_block and 9 _by_lua directives to crossplane along with tests. Add Lua lexer to allow Crossplane to read Lua blocks Add Lua built Fix incorrect Lua testdata

How do we parse Lua: In lexer:

  1. Grab everything in the Lua block as a single token and drop the {}. Example: content_by_lua_block {some code} will be content_by_lua_block "some code"; "some code" is an argument of directive
  2. If a user puts the same argument name as the Lua block directives' name, we will treat it as a normal argument parse. Check if it starts with { which means token depth == 0.
  3. If a user puts the same upstream name as the Lua block directives' name, we will treat it as a normal argument parse. Check if the token is a directive
  4. Set_by_lua_block has a return value, so we need to additionally check for this directive. Get the return value token first and then obtain the rest of the block token.
  5. If a user puts quotes around the Lua directives, we need to skip these quotes.
  6. If there are braces inside the Lua block, we should retain them and not remove them as we did in # 1.

In parser (analyzer): We want to use normal directives way to parse lua block, so remove ngxConfBlock and change ngxConfNoArgs to ngxConfTake1, for set_by_lua_block change to ngxConfTake2. Just similar to server_name

In builder: Add ExternalBuild to handle specific directives Add { } back to the string

Checklist

Before creating a PR, run through this checklist and mark each as complete.