expug v0.7.3 Expug.ExpressionTokenizer

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

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

Functions

balanced_braces(state)

Matches balanced {...} fragments

balanced_brackets(state)

Matches balanced [...] fragments

balanced_pairs(state, left, right)

Underlying implementation for balanced_* functions

balanced_parentheses(state)

Matches balanced (...) fragments

double_quote_string(state)

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

expression(state, token_name)
expression_fragment(state)
expression_term(state)

Matches simple expressions like xyz or even a+b.

expression_term_inside(state)

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

single_quote_string(state)

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