[lexer] Pass Builders around by reference instead of implicitly Copying
This commit is contained in:
parent
9365e51893
commit
15e275513d
6 changed files with 16 additions and 10 deletions
|
@ -35,7 +35,7 @@ impl State for Begin {
|
||||||
StateResult::advance(Box::new(IdSub{}))
|
StateResult::advance(Box::new(IdSub{}))
|
||||||
} else if c.is_hash() {
|
} else if c.is_hash() {
|
||||||
StateResult::advance(Box::new(Hash::new()))
|
StateResult::advance(Box::new(Hash::new()))
|
||||||
} else if let Some(st) = Digit::with_char(Builder::new(), c) {
|
} else if let Some(st) = Digit::with_char(&Builder::new(), c) {
|
||||||
StateResult::advance(Box::new(st))
|
StateResult::advance(Box::new(st))
|
||||||
} else {
|
} else {
|
||||||
StateResult::fail(Error::invalid_char(c))
|
StateResult::fail(Error::invalid_char(c))
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl State for Hash {
|
||||||
StateResult::advance(Box::new(Bool::new(buf.as_str())))
|
StateResult::advance(Box::new(Bool::new(buf.as_str())))
|
||||||
},
|
},
|
||||||
c if c.is_radix() || c.is_exactness() => {
|
c if c.is_radix() || c.is_exactness() => {
|
||||||
if let Some(st) = Prefix::with_char(Builder::new(), c) {
|
if let Some(st) = Prefix::with_char(&Builder::new(), c) {
|
||||||
StateResult::advance(Box::new(st))
|
StateResult::advance(Box::new(st))
|
||||||
} else {
|
} else {
|
||||||
StateResult::fail(Error::new(format!("invalid numeric prefix character: {}", c)))
|
StateResult::fail(Error::new(format!("invalid numeric prefix character: {}", c)))
|
||||||
|
|
|
@ -15,7 +15,7 @@ impl Digit {
|
||||||
Digit(b)
|
Digit(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_char(b: Builder, c: char) -> Option<Digit> {
|
pub fn with_char(b: &Builder, c: char) -> Option<Digit> {
|
||||||
let mut b = b.clone();
|
let mut b = b.clone();
|
||||||
if !b.seen_radix() {
|
if !b.seen_radix() {
|
||||||
b.push_radix(Radix::Dec);
|
b.push_radix(Radix::Dec);
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub enum Sign { Neg = -1, Pos = 1 }
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum Exact { Yes, No }
|
pub enum Exact { Yes, No }
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Builder {
|
pub struct Builder {
|
||||||
radix: Option<Radix>,
|
radix: Option<Radix>,
|
||||||
sign: Option<Sign>,
|
sign: Option<Sign>,
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl Prefix {
|
||||||
Prefix(b)
|
Prefix(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_char(b: Builder, c: char) -> Option<Prefix> {
|
pub fn with_char(b: &Builder, c: char) -> Option<Prefix> {
|
||||||
if let Some(ex) = Exact::from(c) {
|
if let Some(ex) = Exact::from(c) {
|
||||||
if b.seen_exact() {
|
if b.seen_exact() {
|
||||||
return None;
|
return None;
|
||||||
|
@ -42,10 +42,10 @@ impl Prefix {
|
||||||
impl State for Prefix {
|
impl State for Prefix {
|
||||||
fn lex(&mut self, c: char) -> StateResult {
|
fn lex(&mut self, c: char) -> StateResult {
|
||||||
if c.is_hash() {
|
if c.is_hash() {
|
||||||
StateResult::advance(Box::new(Hash(self.0)))
|
StateResult::advance(Box::new(Hash::new(&self.0)))
|
||||||
} else if let Some(st) = Sign::with_char(self.0, c) {
|
} else if let Some(st) = Sign::with_char(&self.0, c) {
|
||||||
StateResult::advance(Box::new(st))
|
StateResult::advance(Box::new(st))
|
||||||
} else if let Some(st) = Digit::with_char(self.0, c) {
|
} else if let Some(st) = Digit::with_char(&self.0, c) {
|
||||||
StateResult::advance(Box::new(st))
|
StateResult::advance(Box::new(st))
|
||||||
} else {
|
} else {
|
||||||
StateResult::fail(Error::invalid_char(c))
|
StateResult::fail(Error::invalid_char(c))
|
||||||
|
@ -57,9 +57,15 @@ impl State for Prefix {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Hash {
|
||||||
|
fn new(b: &Builder) -> Hash {
|
||||||
|
Hash(b.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl State for Hash {
|
impl State for Hash {
|
||||||
fn lex(&mut self, c: char) -> StateResult {
|
fn lex(&mut self, c: char) -> StateResult {
|
||||||
if let Some(st) = Prefix::with_char(self.0, c) {
|
if let Some(st) = Prefix::with_char(&self.0, c) {
|
||||||
StateResult::advance(Box::new(st))
|
StateResult::advance(Box::new(st))
|
||||||
} else {
|
} else {
|
||||||
StateResult::fail(Error::invalid_char(c))
|
StateResult::fail(Error::invalid_char(c))
|
||||||
|
|
|
@ -15,7 +15,7 @@ impl Sign {
|
||||||
Sign(b)
|
Sign(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_char(b: Builder, c: char) -> Option<Sign> {
|
pub fn with_char(b: &Builder, c: char) -> Option<Sign> {
|
||||||
if !b.seen_sign() {
|
if !b.seen_sign() {
|
||||||
match c {
|
match c {
|
||||||
'+' => {
|
'+' => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue