expug v0.9.2 Expug.ExpressionTokenizer View Source

Tokenizes an expression. This is used by Expug.Tokenizer to match attribute values and support multiline.

expression/2 is used to capture an expression token.

state
|> Expug.ExpressionTokenizer.expression(:attribute_value)

Valid expressions

Expressions are combination of one or more of these:

  • a word without spaces
  • a balanced () pair (or [, or {)
  • a string with single quotes '...' or double quotes "..."

A balanced pair can have balanced pairs, words, and strings inside them. Double-quote strings can have #{...} interpolation inside them.

Examples

These are valid expressions:

hello
hello(1 + 2)
"Hello world"           # strings
(hello world)           # balanced (...) pair

These aren’t:

hello world             # spaces
hello(world[)           # pairs not balanced
"hello #{foo(}"         # not balanced inside an interpolation

Link to this section Summary

Functions

Matches balanced {...} fragments

Matches balanced [...] fragments

Underlying implementation for balanced_* functions

Matches balanced (...) fragments

Matches an entire double-quoted string, taking care of interpolation and escaping

Matches simple expressions like xyz or even a+b

Matches simple expressions like xyz, but only for inside parentheses. These can have spaces

Matches an entire double-quoted string, taking care of escaping

Link to this section Functions

Matches balanced {...} fragments

Link to this function balanced_brackets(state) View Source

Matches balanced [...] fragments

Link to this function balanced_pairs(state, left, right) View Source

Underlying implementation for balanced_* functions

Link to this function balanced_parentheses(state) View Source

Matches balanced (...) fragments

Link to this function double_quote_string(state) View Source

Matches an entire double-quoted string, taking care of interpolation and escaping

Link to this function expression(state, token_name) View Source
Link to this function expression_fragment(state) View Source

Matches simple expressions like xyz or even a+b.

Link to this function expression_term_inside(state) View Source

Matches simple expressions like xyz, but only for inside parentheses. These can have spaces.

Link to this function single_quote_string(state) View Source

Matches an entire double-quoted string, taking care of escaping