From f1a840cc385798fc2e3e9ac9ddb0dd57fd0ac509 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 31 Dec 2017 13:32:00 +0300 Subject: Lexer: extract string lexing to a separate file --- src/lexer/strings.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/lexer/strings.rs (limited to 'src/lexer/strings.rs') diff --git a/src/lexer/strings.rs b/src/lexer/strings.rs new file mode 100644 index 000000000..40e5e4528 --- /dev/null +++ b/src/lexer/strings.rs @@ -0,0 +1,65 @@ +use {SyntaxKind}; +use syntax_kinds::*; + +use lexer::ptr::Ptr; + +pub(crate) fn string_literal_start(c: char, c1: Option, c2: Option) -> bool { + match (c, c1, c2) { + ('r', Some('"'), _) | + ('r', Some('#'), _) | + ('b', Some('"'), _) | + ('b', Some('\''), _) | + ('b', Some('r'), Some('"')) | + ('b', Some('r'), Some('#')) => true, + _ => false + } +} + +pub(crate) fn scan_char(ptr: &mut Ptr) { + if ptr.bump().is_none() { + return; // TODO: error reporting is upper in the stack + } + scan_char_or_byte(ptr); + if !ptr.next_is('\'') { + return; // TODO: error reporting + } + ptr.bump(); +} + +pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind { + // unwrapping and not-exhaustive match are ok + // because of string_literal_start + let c = ptr.bump().unwrap(); + match c { + '\'' => { + scan_byte(ptr); + CHAR + } + '"' => { + scan_byte_string(ptr); + CHAR + } + 'r' => { + scan_raw_byte_string(ptr); + CHAR + } + _ => unreachable!(), + } +} + +fn scan_byte(ptr: &mut Ptr) { + +} + +fn scan_byte_string(ptr: &mut Ptr) { + +} + +fn scan_raw_byte_string(ptr: &mut Ptr) { + +} + +fn scan_char_or_byte(ptr: &mut Ptr) { + //FIXME: deal with escape sequencies + ptr.bump(); +} \ No newline at end of file -- cgit v1.2.3