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

Feature/lexical scanning #54

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

zhuharev
Copy link

No description provided.

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.”
I don’t think there’s anything that will stop this.

1.4 is only required to generate the spec tests.
Add coverage target to the build, and delete code that isn’t used.
Travis build failing with gom dependency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants