View Source TextParser.Token behaviour (text_parser v0.1.0)
Behaviour for implementing custom token extractors.
Example
defmodule MyApp.CustomToken do
use TextParser.Token,
pattern: ~r/(?:^| )(@S*)/u,
trim_chars: [",", ".", "!", "?"]
def is_valid?(token) do
# implement validation logic
end
end
Summary
Functions
When used, defines the token struct and implements the behaviour.
Callbacks
Callback for extracting tokens from text.
The implementation should return a list of token structs, where each token
has a :value
and :position
field. The position should be a tuple of
{start_pos, end_pos}
indicating the token's position in the text.
Callback for validating a token value.
This should be implemented by each token module to define its specific validation rules.