Skip to content

Commit

Permalink
Fine tune tokenizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Aug 30, 2023
1 parent 5915ea5 commit 1fb46f8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
8 changes: 3 additions & 5 deletions src/defer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ macro_rules! defer {
};
($var:ident = ( $value:expr ) if Some($guard:ident) => $restore:expr) => {
let mut __rx__;
let $var = if let Some($guard) = $guard {
__rx__ = crate::Deferred::lock($value, $restore);
&mut *__rx__
} else {
&mut *$value
let $var = match $guard {
Some($guard) => { __rx__ = crate::Deferred::lock($value, $restore); &mut *__rx__ }
_ => &mut *$value
};
};
($var:ident if $guard:expr => $restore:expr) => {
Expand Down
12 changes: 6 additions & 6 deletions src/func/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,12 @@ pub fn get_builtin_binary_op_fn(op: &Token, x: &Dynamic, y: &Dynamic) -> Option<

// char op string
if (type1, type2) == (TypeId::of::<char>(), TypeId::of::<ImmutableString>()) {
fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) {
fn get_s1s2(args: &FnCallArgs) -> ([Option<char>; 2], [Option<char>; 2]) {
let x = args[0].as_char().unwrap();
let y = &*args[1].read_lock::<ImmutableString>().unwrap();
let s1 = [x, '\0'];
let s1 = [Some(x), None];
let mut y = y.chars();
let s2 = [y.next().unwrap_or('\0'), y.next().unwrap_or('\0')];
let s2 = [y.next(), y.next()];
(s1, s2)
}

Expand Down Expand Up @@ -470,12 +470,12 @@ pub fn get_builtin_binary_op_fn(op: &Token, x: &Dynamic, y: &Dynamic) -> Option<
}
// string op char
if (type1, type2) == (TypeId::of::<ImmutableString>(), TypeId::of::<char>()) {
fn get_s1s2(args: &FnCallArgs) -> ([char; 2], [char; 2]) {
fn get_s1s2(args: &FnCallArgs) -> ([Option<char>; 2], [Option<char>; 2]) {
let x = &*args[0].read_lock::<ImmutableString>().unwrap();
let y = args[1].as_char().unwrap();
let mut x = x.chars();
let s1 = [x.next().unwrap_or('\0'), x.next().unwrap_or('\0')];
let s2 = [y, '\0'];
let s1 = [x.next(), x.next()];
let s2 = [Some(y), None];
(s1, s2)
}

Expand Down
16 changes: 8 additions & 8 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1608,24 +1608,24 @@ fn get_next_token_inner(
stream.get_next().unwrap();

// Check if followed by digits or something that cannot start a property name
match stream.peek_next().unwrap_or('\0') {
match stream.peek_next() {
// digits after period - accept the period
'0'..='9' => {
Some('0'..='9') => {
result.push(next_char);
pos.advance();
}
// _ - cannot follow a decimal point
NUMBER_SEPARATOR => {
Some(NUMBER_SEPARATOR) => {
stream.unget(next_char);
break;
}
// .. - reserved symbol, not a floating-point number
'.' => {
Some('.') => {
stream.unget(next_char);
break;
}
// symbol after period - probably a float
ch if !is_id_first_alphabetic(ch) => {
Some(ch) if !is_id_first_alphabetic(ch) => {
result.push(next_char);
pos.advance();
result.push('0');
Expand All @@ -1642,14 +1642,14 @@ fn get_next_token_inner(
stream.get_next().expect("`e`");

// Check if followed by digits or +/-
match stream.peek_next().unwrap_or('\0') {
match stream.peek_next() {
// digits after e - accept the e
'0'..='9' => {
Some('0'..='9') => {
result.push(next_char);
pos.advance();
}
// +/- after e - accept the e and the sign
'+' | '-' => {
Some('+' | '-') => {
result.push(next_char);
pos.advance();
result.push(stream.get_next().unwrap());
Expand Down

0 comments on commit 1fb46f8

Please sign in to comment.