-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add all 16 *_by_lua_block and 9 *_by_lua directives to crossplane #86
Conversation
0afcfef
to
fba1886
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just commenting for now as I want to take a little more time to look at the lexing of Lua as I'm seeing differences between this implementation and Python other than what I expected.
7e66fb8
to
35c862c
Compare
Added an extension for lexing an NGINX config that contains lua content. Lua follows a different grammar than most NGINX configs. The extension is based off the [Python implementation](https://github.com/nginxinc/crossplane/blob/master/crossplane/ext/lua.py) which just handles the Lua as a big multi-line string.
Wraps calls to `Scan()` to count EOL strings to retrieve token line numbers and update the main tokenizer's line count.
Moves the "register" responsibility to the options types, not 100% on the API, but it's an idea. The interfaces are now single-method which is pretty much as small as it gets. You could implement these interfaces with a single function that calls itself. A benefit to this is most obvious with the external Lexer I think as now it is not responsible for storing a value for later use that carries state and is not concurrent-safe.
Refactored the options so that callers cannot accidentally on purpose modify other parts of the config struct.
Also removed some commented out code.
Refactor idea to simplify interfaces
resolcing linter complaints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see docstrings on most of the added exported types/functions where it would help the user understand what to do with them (in case it's not obvious) but other than that, lgtm.
lua.go
Outdated
} | ||
|
||
case next == `"` || next == "'": | ||
inQuotes = !inQuotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do we know the "closing quote" is of the same type?
if i do the following, wouldn't this mess things up?
" ' foo ' "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks for pointing that out! I added var quoteType string
to track if quotes are matched
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:
content_by_lua_block {some code}
will becontent_by_lua_block "some code";
"some code" is an argument of directiveIn parser (analyzer):
We want to use normal directives way to parse lua block, so
remove
ngxConfBlock
and changengxConfNoArgs
tongxConfTake1
, forset_by_lua_block
change tongxConfTake2
. Just similar toserver_name
In builder:
Add
ExternalBuild
to handle specific directivesAdd
{ }
back to the stringChecklist
Before creating a PR, run through this checklist and mark each as complete.
CONTRIBUTING
documentREADME.md
)