diff options
author | Vincent Ambo <mail@tazj.in> | 2021-01-18T17·27+0300 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2021-01-19T09·57+0000 |
commit | 5868d4bd49a7b80a395f1ecabedeb0b8f4ddffce (patch) | |
tree | 7f9b786e665f7ea103b256d9cab92bbb982d4770 /users/tazjin/rlox/src/treewalk/errors.rs | |
parent | 2d136e03279e481021a23948fdf5556f25394cd3 (diff) |
refactor(tazjin/rlox): Prepare scanner for shared use r/2132
In the book, the clox interpreter has its own scanner which uses a pull-based model for a single pass compiler. I can't be bothered to write another scanner, or amend this one into pull-mode to work with the treewalk interpreter, so instead I will just reuse it and pull from a vector of tokens. The tokens are shared between both interpreters and the scanner is not what I'm interested in here. Change-Id: Ib07e89127fce2b047f9b3e1ff7e9908d798b3b2b Reviewed-on: https://cl.tvl.fyi/c/depot/+/2420 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/rlox/src/treewalk/errors.rs')
-rw-r--r-- | users/tazjin/rlox/src/treewalk/errors.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/treewalk/errors.rs b/users/tazjin/rlox/src/treewalk/errors.rs index 54d2718eeda2..391663d51b18 100644 --- a/users/tazjin/rlox/src/treewalk/errors.rs +++ b/users/tazjin/rlox/src/treewalk/errors.rs @@ -1,4 +1,6 @@ +use crate::scanner::ScannerError; use crate::treewalk::interpreter::Value; + use std::fmt; #[derive(Debug)] @@ -39,3 +41,19 @@ impl fmt::Display for Error { write!(f, "[line {}] Error: {:?}", self.line, self.kind) } } + +impl From<ScannerError> for Error { + fn from(err: ScannerError) -> Self { + match err { + ScannerError::UnexpectedChar { line, unexpected } => Error { + line, + kind: ErrorKind::UnexpectedChar(unexpected), + }, + + ScannerError::UnterminatedString { line } => Error { + line, + kind: ErrorKind::UnterminatedString, + }, + } + } +} |