public class MacroFinderAutomaton extends com.google.common.collect.UnmodifiableIterator<MacroMatchResult>
The automaton accumulates intermediate values in the string builder and the match result
builder. The find()
method will advance the automaton along the input string until
it finds a macro, and returns a match, or until it reaches the end of the string and returns
null.
Examples of valid matching patterns: $(macro) $(macro argument) $(macro nested parens(argument)) $(macro 'ignored paren )')
If the macro is preceeded by a '\' the match result will be marked as escaped, and the capture group will include the escaping backslash. Example: \$(macro)
Here are the state transitions in dot format (with glossing over of saved state):
digraph G { "SEARCHING" -> "FOUND_DOLLAR" [label="'$'"]; "FOUND_DOLLAR" -> "SEARCHING" [label="*"]; "FOUND_DOLLAR" -> "READING_MACRO_NAME" [label="'('"]; "READING_MACRO_NAME" -> "FOUND_MACRO" [label="')'"]; "READING_MACRO_NAME" -> "READING_ARGS" [label="\\s"]; "READING_MACRO_NAME" -> "READING_MACRO_NAME" [label="\\w"]; "READING_ARGS" -> "FOUND_MACRO" [label="Balanced ')'"]; "READING_ARGS" -> "READING_QUOTED_ARGS" [label="'|\""]; "READING_QUOTED_ARGS" -> "READING_ARGS" [label="Matching '|\""]; "READING_QUOTED_ARGS" -> "READING_QUOTED_ARGS" [label="[^'\"]"]; "READING_ARGS" -> "READING_ARGS" [label="[^'\")]"]; "SEARCHING" -> "IN_ESCAPE_SEQUENCE" [label="\\"]; "IN_ESCAPE_SEQUENCE" -> "FOUND_DOLLAR" [label="$"]; "READING_ARGS" -> "IN_ESCAPE_ARG_SEQUENCE" [label="\\"]; "READING_QUOTED_ARGS" -> "IN_ESCAPE_ARG_SEQUENCE" [label="\\"]; }Not shown: transitions back from "IN_ESCAPE_SEQUENCE" and "IN_ESCAPE_ARG_SEQUENCE", as they return to the previous state
The EBNF grammar for a macro definition is as follows:
macro = "$(", macro_name, whitespace, [arg_list], ")"; macro_name = {all_ascii_chars - whitespace - parens}; whitespace = "\t" | "\n" | " " | "\r"; parens = "(" | ")"; arg_list = arg | arg, whitespace, arg_list; arg = {all_ascii_chars - whitespace - parens} | "(", arg, ")" | "\"", [{-"\""}], "\"" | "'", [{-"'"}], "'";This documentation and grammar are published in the string_parameters_macro.soy documentation.
Constructor and Description |
---|
MacroFinderAutomaton(String blob) |
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext() |
MacroMatchResult |
next() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
public MacroFinderAutomaton(String blob)
public boolean hasNext()
public MacroMatchResult next()