Elixir code generator for Snowball programs.
Takes a Snowball.Analyser.program/0 AST and emits a self-contained
Elixir module source string that can be written to disk and compiled.
The generated module follows exactly the same runtime conventions as the
hand-ported Snowball.Stemmers.English:
Groupings are compiled to bit-tables via
Snowball.Grouping.from_string/1at module load time.Among tables are sorted and assigned result codes at code-gen time so the runtime binary-search works correctly.
Every routine is a private
defpreturning{:ok, state} | {:fail, state}.The
snowball_do/2,snowball_try/2, andsnowball_or/3combinators pluslift/2andnext_codepoint/1helpers are inlined into every generated module.
Summary
Functions
Generate an Elixir module source string from a Snowball program AST.
Functions
@spec generate(Snowball.Analyser.program(), module(), atom()) :: binary()
Generate an Elixir module source string from a Snowball program AST.
Arguments
programis theSnowball.Analyser.program/0map returned bySnowball.Analyser.analyse/1.module_nameis the fully-qualified atom for the generated module, e.g.Snowball.Stemmers.English.languageis the language atom used in the public facade, e.g.:english.
Returns
- A UTF-8 binary containing the complete Elixir source for the module.
Examples
iex> {:ok, tokens} = Snowball.Lexer.tokenize("externals ( stem ) define stem as delete")
iex> {:ok, prog} = Snowball.Analyser.analyse(tokens)
iex> src = Snowball.Generator.generate(prog, Snowball.Stemmers.Tiny, :tiny)
iex> is_binary(src)
true