Skip to content
This repository has been archived by the owner on Jan 24, 2020. It is now read-only.

Assignment #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add single dot operator + maybe fix a parsing mishap
  • Loading branch information
AmaranthineCodices committed Jun 8, 2018

Verified

This commit was signed with the committer’s verified signature.
Josh-Walker-GM Josh GM Walker
commit 4ef64f17dd4351c8aab989ecca23f27fea724aaf
18 changes: 14 additions & 4 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use std::collections::HashMap;

use regex::{self, Regex};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash)]
pub enum Symbol {
LeftBrace,
RightBrace,
@@ -21,10 +21,12 @@ pub enum Symbol {
Slash,
Caret,
Hash,
Dot,
TwoDots,
Equal,
Comma,
Semicolon,
Colon,
Ellipse,
And,
Or,
@@ -62,10 +64,12 @@ impl Symbol {
Symbol::Slash => "/",
Symbol::Caret => "^",
Symbol::Hash => "#",
Symbol::Dot => ".",
Symbol::TwoDots => "..",
Symbol::Equal => "=",
Symbol::Comma => ",",
Symbol::Semicolon => ";",
Symbol::Colon => ":",
Symbol::Ellipse => "...",
Symbol::And => "and",
Symbol::Or => "or",
@@ -220,19 +224,25 @@ lazy_static! {
Symbol::LeftBracket, Symbol::RightBracket,
Symbol::LeftParen, Symbol::RightParen,

Symbol::Plus, Symbol::Minus, Symbol::Star, Symbol::Slash, Symbol::Caret, Symbol::TwoDots,
Symbol::Plus, Symbol::Minus, Symbol::Star, Symbol::Slash, Symbol::Caret,
Symbol::And, Symbol::Or,
Symbol::Hash,
Symbol::Equal,
Symbol::Comma, Symbol::Semicolon,
Symbol::Ellipse,
Symbol::Comma, Symbol::Semicolon, Symbol::Colon,

Symbol::Local, Symbol::Function,
Symbol::If, Symbol::While, Symbol::Repeat, Symbol::Until, Symbol::For,
Symbol::Then, Symbol::Do, Symbol::Else, Symbol::ElseIf, Symbol::End,
Symbol::In,
Symbol::True, Symbol::False, Symbol::Nil,
Symbol::Not,

// All the dot symbols are moved here because the order that they appear in
// the generated regex is crucial to proper parsing.
// They must be present in the regex in order of decreasing length.
Symbol::Ellipse,
Symbol::TwoDots,
Symbol::Dot,
];

static ref STR_TO_SYMBOL: HashMap<&'static str, Symbol> = {