Snowball.Generator (snowball v0.1.1)

Copy Markdown View Source

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/1 at 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 defp returning {:ok, state} | {:fail, state}.

  • The snowball_do/2, snowball_try/2, and snowball_or/3 combinators plus lift/2 and next_codepoint/1 helpers are inlined into every generated module.

Summary

Functions

Generate an Elixir module source string from a Snowball program AST.

Functions

generate(program, module_name, language)

@spec generate(Snowball.Analyser.program(), module(), atom()) :: binary()

Generate an Elixir module source string from a Snowball program AST.

Arguments

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