Import TokenType and Kw everywhere
This commit is contained in:
parent
92ece39d5e
commit
cac3ea86cf
@ -29,6 +29,7 @@ pub enum TokenType {
|
|||||||
|
|
||||||
Error(String),
|
Error(String),
|
||||||
}
|
}
|
||||||
|
use self::TokenType::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum Kw {
|
pub enum Kw {
|
||||||
@ -41,6 +42,7 @@ pub enum Kw {
|
|||||||
Trait, Impl,
|
Trait, Impl,
|
||||||
True, False
|
True, False
|
||||||
}
|
}
|
||||||
|
use self::Kw::*;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref KEYWORDS: HashMap<&'static str, Kw> =
|
static ref KEYWORDS: HashMap<&'static str, Kw> =
|
||||||
@ -87,8 +89,6 @@ fn is_digit(c: &char) -> bool {
|
|||||||
type CharIter<'a> = Peekable<Enumerate<Chars<'a>>>;
|
type CharIter<'a> = Peekable<Enumerate<Chars<'a>>>;
|
||||||
|
|
||||||
pub fn tokenize(input: &str) -> Vec<Token> {
|
pub fn tokenize(input: &str) -> Vec<Token> {
|
||||||
use self::TokenType::*;
|
|
||||||
|
|
||||||
let mut tokens: Vec<Token> = Vec::new();
|
let mut tokens: Vec<Token> = Vec::new();
|
||||||
let mut input: CharIter = input.chars().enumerate().peekable();
|
let mut input: CharIter = input.chars().enumerate().peekable();
|
||||||
|
|
||||||
@ -124,8 +124,6 @@ pub fn tokenize(input: &str) -> Vec<Token> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_digit(c: char, input: &mut CharIter) -> TokenType {
|
fn handle_digit(c: char, input: &mut CharIter) -> TokenType {
|
||||||
use self::TokenType::*;
|
|
||||||
|
|
||||||
if c == '0' && input.peek().map_or(false, |&(_, c)| { c == 'x' }) {
|
if c == '0' && input.peek().map_or(false, |&(_, c)| { c == 'x' }) {
|
||||||
input.next();
|
input.next();
|
||||||
HexNumberSigil
|
HexNumberSigil
|
||||||
@ -366,7 +364,6 @@ pub enum Expression {
|
|||||||
|
|
||||||
impl Parser {
|
impl Parser {
|
||||||
fn program(&mut self) -> ParseResult<AST> {
|
fn program(&mut self) -> ParseResult<AST> {
|
||||||
use self::TokenType::*;
|
|
||||||
let mut statements = Vec::new();
|
let mut statements = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
match self.peek() {
|
match self.peek() {
|
||||||
@ -382,7 +379,6 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn statement(&mut self) -> ParseResult<Statement> {
|
fn statement(&mut self) -> ParseResult<Statement> {
|
||||||
use self::TokenType::*;
|
|
||||||
use self::Kw::*;
|
use self::Kw::*;
|
||||||
//TODO handle error recovery here
|
//TODO handle error recovery here
|
||||||
match self.peek() {
|
match self.peek() {
|
||||||
@ -409,14 +405,12 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn literal(&mut self) -> ParseResult<Expression> {
|
fn literal(&mut self) -> ParseResult<Expression> {
|
||||||
use self::TokenType::*;
|
|
||||||
match self.peek() {
|
match self.peek() {
|
||||||
DigitGroup(_) | HexNumberSigil | BinNumberSigil | Period => self.number_literal(),
|
DigitGroup(_) | HexNumberSigil | BinNumberSigil | Period => self.number_literal(),
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn number_literal(&mut self) -> ParseResult<Expression> {
|
fn number_literal(&mut self) -> ParseResult<Expression> {
|
||||||
use self::TokenType::*;
|
|
||||||
match self.peek() {
|
match self.peek() {
|
||||||
HexNumberSigil | BinNumberSigil => self.int_literal(),
|
HexNumberSigil | BinNumberSigil => self.int_literal(),
|
||||||
_ => self.float_literal(),
|
_ => self.float_literal(),
|
||||||
@ -459,7 +453,6 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn digits(&mut self) -> ParseResult<String> {
|
fn digits(&mut self) -> ParseResult<String> {
|
||||||
use self::TokenType::*;
|
|
||||||
let mut ds = String::new();
|
let mut ds = String::new();
|
||||||
loop {
|
loop {
|
||||||
match self.peek() {
|
match self.peek() {
|
||||||
|
Loading…
Reference in New Issue
Block a user