[][src]Trait synterm::CommandLineTool

pub trait CommandLineTool {
    const PROMPT: &'static str;
    const HISTORY_FILE_PATH: &'static str;

    fn evaluator_function(line: &String) -> String;

    fn get_hist(n: usize) -> String { ... }
fn start(&self) { ... }
fn repl(&self) { ... }
fn syntax_highlight(string: &str) { ... } }

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

Loading content...

Required methods

fn evaluator_function(line: &String) -> String

This should take a line and return the evaluated output after evaluation

Loading content...

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

  1. 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)
  2. funcName -- put in the name of your parser method
  3. 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 from syntem::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));
}
Loading content...

Implementors

Loading content...