-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Combine included VCL modules into main and parse once #93
Conversation
type RunMode int | ||
|
||
const ( | ||
RunModeLint RunMode = 0x000001 | ||
RunModeStat RunMode = 0x000010 | ||
) |
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.
Runner no longer needs to recognize the VCL is main or not, so RunMode could be simple as bit mode.
case *ast.IncludeStatement: | ||
module, err := r.resolver.Resolve(t.Module.Value) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
vcl, err := r.parseVCL(module.Name, module.Data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
vcl.Statements, err = r.resolveStatements(vcl.Statements) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resolved = append(resolved, vcl.Statements...) |
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.
Resolve include
statement here.
case *ast.IfStatement: | ||
if err := r.resolveIfStatement(t); err != nil { | ||
return nil, err | ||
} | ||
resolved = append(resolved, t) |
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.
If
statement may have a block statement so need to resolve recursively.
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.
what does block statement mean here? Can you give an example?
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.
(also we should probably move this to the code as a comment)
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.
The block statement may have include
statement of embedding dynamic snippets inside (and probably include file is also valid).
For example:
sub vcl_fetch {
if (req.restarts > 0) {
include "snippet::<snippet_name>"; # Embed dynamic snippet here
}
...
}
According to include statement, it is available in all subroutines so the above syntax should be valid and resolve inclusion recursively.
case *ast.SubroutineDeclaration: | ||
ss, err := r.resolveStatements(t.Block.Statements) | ||
if err != nil { | ||
return nil, err | ||
} | ||
t.Block.Statements = ss | ||
resolved = append(resolved, t) |
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.
Subroutine may have a block statement so need to resolve recursively.
That is soooooo dope, super excited for this PR. will review tomorrow |
I'll resolve the conflict lately |
@davinci26 I've resolved conflict with |
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.
LGTM! Thanks for working on this
when this + #99 is merged I will pull it in to our internal branch and test it on our VCL corpus as well and report back if I run into any issues |
Fixes #78
Resolve include modules that are declared at
include "xxx";
statement, replace the parsed AST into its declaration position, and lint whole codes as a single VCL treeThis implementation still does not use DFS style parsing but it's should be lint properly.
Example
From #78, the example case of VCLs:
Then resolved VCL should be:
And linter should not raise any errors.
Additional Specs