Template parsing thoughts - nortal/Utilities.TextTemplating GitHub Wiki
First pass: separation of text and commands
First scanner pass will output input template broken into a linear stream of text and command blocks.
Rules:
- Command start and end tag markers are omitted from output command texts
- Command start and end tag markers can be used as part of ordinary text or command themselves if written double.
- Every command start must be closed with end tag. Template with unclosed command will be rejected with error.
- Command mode strings must not intersect. Such templates will be rejected with error.
Second pass: parsing of commands
Command parser will verify each command has correct syntax and determine if command is a function command or a path to model.
Function commands are broken to components:
- function name
- array of provided arguments
Model path commands are broken to components:
- array of model property names
- optional format string
Third pass: building parse tree
Template will be represented as tree for efficient document generation later.