Makeup v0.5.0 Makeup.Lexer.Combinators View Source

Link to this section Summary

Functions

Joins the result of the given combinator into a single string

Matches a given combinator, repeated 0 or more times, surrounded by left and right delimiters

Matches a given combinator, repeated 0 or more times, surrounded by left and right delimiters, and wraps the right and left delimiters into a token of the given ttype

A generic combinator for string-like syntactic structures

Wraps the given combinator into a token of the given ttype

Matches one of the literal strings in the list

Matches one of the literal strings in the list and wraps it in a token of the given type

Matches one of the literal strings in the list and wraps it in a token of the given type, with the given attrs

Link to this section Functions

Link to this function collect_raw_chars_and_binaries(rest, args, context, line, offset, ttype, attrs) View Source

Joins the result of the given combinator into a single string.

This is not usually necessary, but it can be useful if you want to match on the tokens. It’s easier to match on the token {:keyword, %{}, "unquote"} than on something like {:keyword, %{}, ["u", "nquote"]}, even though both tokens will be treated the same way by the formatter.

Link to this function many_surrounded_by(combinator, left, right) View Source

Matches a given combinator, repeated 0 or more times, surrounded by left and right delimiters.

Delimiters can be combinators or literal strings (either both combinators or both literal strings).

Link to this function many_surrounded_by(combinator, left, right, ttype) View Source

Matches a given combinator, repeated 0 or more times, surrounded by left and right delimiters, and wraps the right and left delimiters into a token of the given ttype.

Link to this function string_like(left, right, middle, ttype, attrs \\ %{}) View Source

A generic combinator for string-like syntactic structures.

It takes the following parameters:

  • left - left delimiter for the string
  • right - right delimiter for the string
  • middle - a list of parsers to run inside the strig which parse entities that aren’t characters. The most common example are special characters and string interpolation for languages that support it like Elixir.
  • ttype - the token type to use for the string delimiters and ordinary characters (tokens parsd by the )
  • attrs - metadata attributes for the string delimiters and ordinary characters

Example

Link to this function token(literal, token_type) View Source

Wraps the given combinator into a token of the given ttype.

Instead of a combinator, the first argument can also be a string literal.

Link to this function token(literal, token_type, attrs) View Source

Matches one of the literal strings in the list.

The strings aren’t matched in order: they are automatically sorted in a way that guarantees that the longest strings will be tried first.

Link to this function word_from_list(words, ttype) View Source

Matches one of the literal strings in the list and wraps it in a token of the given type.

This is is just a shorthand.

The strings aren’t matched in order: they are automatically sorted in a way that guarantees that the longest strings will be tried first.

Link to this function word_from_list(words, ttype, attrs) View Source

Matches one of the literal strings in the list and wraps it in a token of the given type, with the given attrs.

This is is just a shorthand.

The strings aren’t matched in order: they are automatically sorted in a way that guarantees that the longest strings will be tried first.