1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//#![feature(proc_macro_hygiene)]

#[macro_use]
extern crate phf;

pub mod token;
#[macro_use]
mod macros;
mod equivalence;
pub mod error;
mod identifier;
mod number;
mod state;
mod state_machine;
mod string;

/// Module for efficient string representation
pub mod internship {
    extern crate internship;

    pub use internship::*;
}

use self::{state_machine::parse, token::*};

/// Lexer implementation
#[derive(Debug, Copy, Clone)]
pub struct Lexer;

impl Lexer {
    /// Transform string to stream of tokens
    pub fn lex(s: &str) -> Result<Vec<Token>, error::Error> {
        let mut tokens = parse(s)?;
        tokens.push(Token::EOF);
        Ok(tokens)
    }
}