[−][src]Trait synterm::CommandLineTool
This Trait is how you make your command line tool it is the center of all synterm programs
Associated Constants
const PROMPT: &'static str
The input prompt defaults to >>>
const HISTORY_FILE_PATH: &'static str
Path to the history file defaults to /tmp/history.txt
Required methods
fn evaluator_function(line: &String) -> String
This should take a line and return the evaluated output after evaluation
Provided methods
fn get_hist(n: usize) -> String
Do not implement! This is used internally
fn start(&self)
fn repl(&self)
Starts the REPL
fn syntax_highlight(string: &str)
This drives the syntax highlighting it should consist of one macro and function call
First the macro cll is syntax_highlight_gen!
this will generate the lexers this will take the following paramaters
- enumName this will be the name of the enum that will serve as our tokens put an identifier here that hasn't been used i.e.
gen_lexer!(TheLexer)
- funcName -- put in the name of your parser method
- args this is as many as you want and will actually define new tokens, for each pattern of creating tokens you want add the following pair (Identifier, Color, Regex) i.e.
(Number, Color::Red, r"[0-9]+")
(we get the Color enum fromsyntem::Color
) a full example might look like this
use synterm::{syntax_highlight_gen, Color}; syntax_highlight_gen!(TheLexer, parser, (Foo, Color::Red, "foo"), (Bar, Color::Green, "bar"));
Now for the function call the parse function we create with syntax_highlight_gen!
in which one calls
ParserName(TokenNames::lexer(string));
from the last 2 snippets it is parser(TheLexer::lexer(string));
Lets put this together
use synterm::{syntax_highlight_gen, Color}; fn syntax_highlight(string: &str) { syntax_highlight_gen!(TheLexer, parser, (Foo, Color::Red, "foo"), (Bar, Color::Green, "bar")); parser(TheLexer::lexer(string)); }