public class SoyFileParser extends Object implements SoyFileParserConstants
Important: Do not use outside of Soy code (treat as superpackage-private).
This parser parses the following Soy file structure:
1. Delegate package (delpackage):
+ Optional.
+ The file must contain 0 or 1 delpackage declaration.
+ It must appear before the namespace declaration.
+ It must appear on its own line and start at the start of a line.
Example: {delpackage MySecretFeature}
2. Namespace:
+ The file must contain exactly one namespace declaration.
+ It must appear before any templates.
+ It must appear on its own line and start at the start of a line.
Examples:
{namespace boo.foo}
{namespace boo.foo autoescape="..."}
3. Alias:
+ Alias declarations must appear after the namespace declaration.
+ They must appear before any templates.
+ Each must appear on its own line and start at the start of a line.
Examples:
{alias boo.foo.goo.moo}
{alias boo.foo.goo.moo as zoo}
4. SoyDoc:
+ Starts with slash-star-star (/**) and ends with star-slash (*/) like JavaDoc.
+ SoyDoc must appear on its own line(s) and start at the start of a line.
+ Currently recognizes two tags: "@param keyName" and "@param? optionalKeyName".
Example:
/**
* @param boo Something scary.
* @param? goo Something slimy (optional).
*/
5. Template:
+ Each template must be immediately preceded by a SoyDoc block.
+ The 'template' tag and the '/template' tag much each appear on its own line(s) and start
at the start of a line.
+ The template content is parsed by TemplateParser.jj.
Examples:
/**
* New style.
* @param boo Something scary.
* @param? goo Something slimy (optional).
*/
{template .foo autoescape="..."}
{msg desc=""}
{$boo} has a friend named {$goo.firstName}.
{/msg}
{/template}
/**
* Old style.
*/
{template name="foo"}
...
{/template}
6. Misc:
+ Other than the items specified above, everything else is ignored.
+ SoyDoc blocks not immediately followed by a template are ignored.
+ The file must end with a newline.
| Modifier and Type | Field and Description |
|---|---|
Token |
jj_nt
Next token.
|
Token |
token
Current token.
|
SoyFileParserTokenManager |
token_source
Generated Token Manager.
|
ALIAS_TAG, ANY_CHAR, ANY_TEMPLATE_CMD_NAME, ANY_TEMPLATE_TAG, DEFAULT, DELPACKAGE_TAG, DOTTED_IDENT, EOF, IDENT, IN_SOY_DOC, IN_TEMPLATE, NAMESPACE_TAG, NEWLINE, NOT_BRACE, NOT_EOL, NOT_SOL, SKIPPED_CHAR, SKIPPED_NEWLINE, SOY_DOC_CHAR, SOY_DOC_END, SOY_DOC_NEWLINE, SOY_DOC_START, TEMPLATE_CONTENT, TEMPLATE_CONTENT_CHAR, tokenImage, WS, WS_UNTIL_EOL, XXX_ALIAS_INVALID, XXX_ALIAS_TAG_NOT_EOL, XXX_ALIAS_TAG_NOT_SOL, XXX_DELPACKAGE_INVALID, XXX_DELPACKAGE_TAG_NOT_EOL, XXX_DELPACKAGE_TAG_NOT_SOL, XXX_END_TEMPLATE_TAG_INVALID, XXX_END_TEMPLATE_TAG_NOT_EOL, XXX_END_TEMPLATE_TAG_NOT_SOL, XXX_NAMESPACE_INVALID, XXX_NAMESPACE_TAG_NOT_EOL, XXX_NAMESPACE_TAG_NOT_SOL, XXX_SOY_DOC_END_NOT_EOL, XXX_SOY_DOC_START_NOT_SOL, XXX_TEMPLATE_TAG_INVALID, XXX_TEMPLATE_TAG_NOT_EOL, XXX_TEMPLATE_TAG_NOT_SOL| Constructor and Description |
|---|
SoyFileParser(InputStream stream)
Constructor with InputStream.
|
SoyFileParser(InputStream stream,
String encoding)
Constructor with InputStream and supplied encoding
|
SoyFileParser(Reader stream)
Constructor.
|
SoyFileParser(SoyFileParserTokenManager tm)
Constructor with generated Token Manager.
|
SoyFileParser(SoyTypeRegistry typeRegistry,
IdGenerator nodeIdGen,
Reader input,
SoyFileKind soyFileKind,
String filePath,
ErrorReporter errorReporter)
Constructor that takes a reader object providing the input.
|
SoyFileParser(SoyTypeRegistry typeRegistry,
IdGenerator nodeIdGen,
String input,
SoyFileKind soyFileKind,
String filePath)
Constructor that takes a string input.
|
SoyFileParser(SoyTypeRegistry typeRegistry,
IdGenerator nodeIdGen,
String input,
SoyFileKind soyFileKind,
String filePath,
ErrorReporter errorReporter)
Constructor that takes a string input.
|
| Modifier and Type | Method and Description |
|---|---|
void |
disable_tracing()
Disable tracing.
|
void |
enable_tracing()
Enable tracing.
|
ParseException |
generateParseException()
Generate ParseException.
|
Token |
getNextToken()
Get the next Token.
|
Token |
getToken(int index)
Get the specific Token.
|
SoyFileNode |
parseSoyFile()
Attempts to parse the given input as a Soy file.
|
void |
ReInit(InputStream stream)
Reinitialise.
|
void |
ReInit(InputStream stream,
String encoding)
Reinitialise.
|
void |
ReInit(Reader stream)
Reinitialise.
|
void |
ReInit(SoyFileParserTokenManager tm)
Reinitialise.
|
public SoyFileParserTokenManager token_source
public Token token
public Token jj_nt
public SoyFileParser(SoyTypeRegistry typeRegistry, IdGenerator nodeIdGen, Reader input, SoyFileKind soyFileKind, String filePath, ErrorReporter errorReporter)
typeRegistry - The type registry for resolving type names.nodeIdGen - The node id generator for the tree being built.input - The input to parse.soyFileKind - The kind of this Soy file.filePath - The path of the source being parsed. Used for reporting.errorReporter - For reporting parse errors.public SoyFileParser(SoyTypeRegistry typeRegistry, IdGenerator nodeIdGen, String input, SoyFileKind soyFileKind, String filePath, ErrorReporter errorReporter)
typeRegistry - The type registry for resolving type names.nodeIdGen - The node id generator for the tree being built.input - The input to parse.soyFileKind - The kind of this Soy file.filePath - The path of the source being parsed. Used for reporting.errorReporter - For reporting parse errors.public SoyFileParser(SoyTypeRegistry typeRegistry, IdGenerator nodeIdGen, String input, SoyFileKind soyFileKind, String filePath)
typeRegistry - The type registry for resolving type names.nodeIdGen - The node id generator for the tree being built.input - The input to parse.soyFileKind - The kind of this Soy file.filePath - The path of the source being parsed. Used for reporting.public SoyFileParser(InputStream stream)
public SoyFileParser(InputStream stream, String encoding)
public SoyFileParser(Reader stream)
public SoyFileParser(SoyFileParserTokenManager tm)
public SoyFileNode parseSoyFile()
public void ReInit(InputStream stream)
public void ReInit(InputStream stream, String encoding)
public void ReInit(Reader stream)
public void ReInit(SoyFileParserTokenManager tm)
public final Token getNextToken()
public final Token getToken(int index)
public ParseException generateParseException()
public final void enable_tracing()
public final void disable_tracing()