Skip to main content

Module parsing

Module parsing 

Source
Expand description

This file contains code for parsing SSR rules, which look something like foo($a) ==>> bar($b). We first split everything before and after the separator ==>>. Next, both the search pattern and the replacement template get tokenized by the Rust tokenizer. Tokens are then searched for placeholders, which start with $. For replacement templates, this is the final form. For search patterns, we go further and parse the pattern as each kind of thing that we can match. e.g. expressions, type references etc.

Structsยง

ParsedRule ๐Ÿ”’
Placeholder ๐Ÿ”’
RawPattern ๐Ÿ”’
RuleBuilder ๐Ÿ”’
Token ๐Ÿ”’
Var ๐Ÿ”’
Represents a $var in an SSR query.

Enumsยง

Constraint ๐Ÿ”’
NodeKind ๐Ÿ”’
PatternElement ๐Ÿ”’

Functionsยง

contains_path ๐Ÿ”’
Returns whether there are any paths in node.
expect_token ๐Ÿ”’
parse_constraint ๐Ÿ”’
parse_pattern ๐Ÿ”’
Returns pattern_str, parsed as a search or replace pattern. If remove_whitespace is true, then any whitespace tokens will be removed, which we do for the search pattern, but not for the replace pattern.
parse_placeholder ๐Ÿ”’
tokenize ๐Ÿ”’
validate_rule ๐Ÿ”’
Checks for errors in a rule. e.g. the replace pattern referencing placeholders that the search pattern didnโ€™t define.