-
Notifications
You must be signed in to change notification settings - Fork 225
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
Feature/lexical scanning #54
Open
zhuharev
wants to merge
21
commits into
hoisie:master
Choose a base branch
from
jabley:feature/lexical-scanning
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As a compliant implementation of mustache, this code base should use the specs to ensure that it passes.
Allows more meaningful failure messages.
Add generate target gofmt all the things
"Interpolation tags are used to integrate dynamic content into the template. The tag's content MUST be a non-whitespace character sequence NOT containing the current closing delimiter. This tag's content names the data to replace the tag. A single period (`.`) indicates that the item currently sitting atop the context stack should be used; otherwise, name resolution is as follows: 1) Split the name on periods; the first part is the name to resolve, any remaining parts should be retained. 2) Walk the context stack from top to bottom, finding the first context that is a) a hash containing the name as a key OR b) an object responding to a method with the given name. 3) If the context is a hash, the data is the value associated with the name. 4) If the context is an object, the data is the value returned by the method with the given name. 5) If any name parts were retained in step 1, each should be resolved against a context stack containing only the result from the former resolution. If any part fails resolution, the result should be considered falsey, and should interpolate as the empty string. Data should be coerced into a string (and escaped, if appropriate) before interpolation. The Interpolation tags MUST NOT be treated as standalone."
"Comment tags represent content that should never appear in the resulting output. The tag's content may contain any substring (including newlines) EXCEPT the closing delimiter. Comment tags SHOULD be treated as standalone when appropriate."
"Section tags and End Section tags are used in combination to wrap a section of the template for iteration. These tags' content MUST be a non-whitespace character sequence NOT containing the current closing delimiter; each Section tag MUST be followed by an End Section tag with the same content within the same section. This tag's content names the data to replace the tag. Name resolution is as follows: 1) Split the name on periods; the first part is the name to resolve, any remaining parts should be retained. 2) Walk the context stack from top to bottom, finding the first context that is a) a hash containing the name as a key OR b) an object responding to a method with the given name. 3) If the context is a hash, the data is the value associated with the name. 4) If the context is an object and the method with the given name has an arity of 1, the method SHOULD be called with a String containing the unprocessed contents of the sections; the data is the value returned. 5) Otherwise, the data is the value returned by calling the method with the given name. 6) If any name parts were retained in step 1, each should be resolved against a context stack containing only the result from the former resolution. If any part fails resolution, the result should be considered falsey, and should interpolate as the empty string. If the data is not of a list type, it is coerced into a list as follows: if the data is truthy (e.g. `!!data == true`), use a single-element list containing the data, otherwise use an empty list. For each element in the data list, the element MUST be pushed onto the context stack, the section MUST be rendered, and the element MUST be popped off the context stack. Section and End Section tags SHOULD be treated as standalone when appropriate."
"Set Delimiter tags are used to change the tag delimiters for all content following the tag in the current compilation unit. The tag's content MUST be any two non-whitespace sequences (separated by whitespace) EXCEPT an equals sign ('=') followed by the current closing delimiter. Set Delimiter tags SHOULD be treated as standalone when appropriate."
"Inverted Section tags and End Section tags are used in combination to wrap a section of the template. These tags' content MUST be a non-whitespace character sequence NOT containing the current closing delimiter; each Inverted Section tag MUST be followed by an End Section tag with the same content within the same section. This tag's content names the data to replace the tag. Name resolution is as follows: 1) Split the name on periods; the first part is the name to resolve, any remaining parts should be retained. 2) Walk the context stack from top to bottom, finding the first context that is a) a hash containing the name as a key OR b) an object responding to a method with the given name. 3) If the context is a hash, the data is the value associated with the name. 4) If the context is an object and the method with the given name has an arity of 1, the method SHOULD be called with a String containing the unprocessed contents of the sections; the data is the value returned. 5) Otherwise, the data is the value returned by calling the method with the given name. 6) If any name parts were retained in step 1, each should be resolved against a context stack containing only the result from the former resolution. If any part fails resolution, the result should be considered falsey, and should interpolate as the empty string. If the data is not of a list type, it is coerced into a list as follows: if the data is truthy (e.g. `!!data == true`), use a single-element list containing the data, otherwise use an empty list. This section MUST NOT be rendered unless the data list is empty. Inverted Section and End Section tags SHOULD be treated as standalone when appropriate."
Partials require appropriate indentation, and also handling recursive partials. Added very basic environment as a type of symbol table for dealing with recursive partials. “Partial tags are used to expand an external template into the current template. The tag's content MUST be a non-whitespace character sequence NOT containing the current closing delimiter. This tag's content names the partial to inject. Set Delimiter tags MUST NOT affect the parsing of a partial. The partial MUST be rendered against the context stack local to the tag. If the named partial cannot be found, the empty string SHOULD be used instead, as in interpolations. Partial tags SHOULD be treated as standalone when appropriate. If this tag is used standalone, any whitespace preceding the tag should treated as indentation, and prepended to each line of the partial before rendering.”
Implement the spec to make this a compliant implementation
See mustache/spec#85 for how the tests were generated. If / when that pull request is merged, I will also update the submodule reference in this project. “Lambdas are a special-cased data type for use in interpolations and sections. “When used as the data value for an Interpolation tag, the lambda MUST be treatable as an arity 0 function, and invoked as such. The returned value MUST be rendered against the default delimiters, then interpolated in place of the lambda. When used as the data value for a Section tag, the lambda MUST be treatable as an arity 1 function, and invoked as such (passing a String containing the unprocessed section contents). The returned value MUST be rendered against the current delimiters, then interpolated in place of the section.”
Implement lambdas module
I don’t think there’s anything that will stop this. 1.4 is only required to generate the spec tests.
Build on go 1.2 and 1.4 as well
Add coverage target to the build, and delete code that isn’t used.
Delete unused code
Saw https://www.youtube.com/watch?v=HxaD_trXwRE and am trying it out.
jabley
force-pushed
the
feature/lexical-scanning
branch
from
May 18, 2016 06:24
b3901de
to
2f90bb3
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.