Sammal v0.1.0 Sammal.Tokenizer View Source

Tokenizer and various helper methods.

Link to this section Summary

Functions

Given a lexeme, return a matching Elixir value (or an error)

Split a line of raw input into a list of Node structs

Link to this section Functions

Given a lexeme, return a matching Elixir value (or an error).

Example

iex> Sammal.Tokenizer.lexeme_to_value(“12”)

iex> Sammal.Tokenizer.lexeme_to_value(“12.12”)

iex> Sammal.Tokenizer.lexeme_to_value(“\”12\””)

Link to this function tokenize(line, line_index \\ 0) View Source

Split a line of raw input into a list of Node structs.

Example

iex> Sammal.Tokenizer.tokenize(“(define x 10)”) {:ok, [%Sammal.Expr{lex: “(“, line: 0, row: 0, val: :”(“, ctx: “(define x 10)”},

     %Sammal.Expr{lex: "define", line: 0, row: 1, val: :define, ctx: "(define x 10)"},
     %Sammal.Expr{lex: "x", line: 0, row: 8, val: :x, ctx: "(define x 10)"},
     %Sammal.Expr{lex: "10", line: 0, row: 10, val: 10, ctx: "(define x 10)"},
     %Sammal.Expr{lex: ")", line: 0, row: 12, val: :")", ctx: "(define x 10)"}]}