From 2f24fb4f2c5d8708533a1b0155e1e884bd4b2ba2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 31 Dec 2017 14:02:55 +0300 Subject: Lexer: byte strings --- src/lexer/strings.rs | 31 ++++++++++++++++++++++++++----- src/syntax_kinds.rs | 18 ++++++++++++++---- 2 files changed, 40 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/lexer/strings.rs b/src/lexer/strings.rs index 40e5e4528..283ce8feb 100644 --- a/src/lexer/strings.rs +++ b/src/lexer/strings.rs @@ -33,30 +33,51 @@ pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind { match c { '\'' => { scan_byte(ptr); - CHAR + BYTE } '"' => { scan_byte_string(ptr); - CHAR + BYTE_STRING } 'r' => { scan_raw_byte_string(ptr); - CHAR + RAW_BYTE_STRING } _ => unreachable!(), } } fn scan_byte(ptr: &mut Ptr) { - + if ptr.next_is('\'') { + ptr.bump(); + return + } + ptr.bump(); + if ptr.next_is('\'') { + ptr.bump(); + return + } } fn scan_byte_string(ptr: &mut Ptr) { - + while let Some(c) = ptr.bump() { + if c == '"' { + return + } + } } fn scan_raw_byte_string(ptr: &mut Ptr) { + if !ptr.next_is('"') { + return + } + ptr.bump(); + while let Some(c) = ptr.bump() { + if c == '"' { + return + } + } } fn scan_char_or_byte(ptr: &mut Ptr) { diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 4c023757b..4a68acb31 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs @@ -33,10 +33,15 @@ pub const EQEQ: SyntaxKind = SyntaxKind(28); pub const FAT_ARROW: SyntaxKind = SyntaxKind(29); pub const NEQ: SyntaxKind = SyntaxKind(30); pub const NOT: SyntaxKind = SyntaxKind(31); -pub const CHAR: SyntaxKind = SyntaxKind(32); -pub const LIFETIME: SyntaxKind = SyntaxKind(33); +pub const LIFETIME: SyntaxKind = SyntaxKind(32); +pub const CHAR: SyntaxKind = SyntaxKind(33); +pub const BYTE: SyntaxKind = SyntaxKind(34); +pub const STRING: SyntaxKind = SyntaxKind(35); +pub const RAW_STRING: SyntaxKind = SyntaxKind(36); +pub const BYTE_STRING: SyntaxKind = SyntaxKind(37); +pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(38); -static INFOS: [SyntaxInfo; 34] = [ +static INFOS: [SyntaxInfo; 39] = [ SyntaxInfo { name: "ERROR" }, SyntaxInfo { name: "IDENT" }, SyntaxInfo { name: "UNDERSCORE" }, @@ -69,8 +74,13 @@ static INFOS: [SyntaxInfo; 34] = [ SyntaxInfo { name: "FAT_ARROW" }, SyntaxInfo { name: "NEQ" }, SyntaxInfo { name: "NOT" }, - SyntaxInfo { name: "CHAR" }, SyntaxInfo { name: "LIFETIME" }, + SyntaxInfo { name: "CHAR" }, + SyntaxInfo { name: "BYTE" }, + SyntaxInfo { name: "STRING" }, + SyntaxInfo { name: "RAW_STRING" }, + SyntaxInfo { name: "BYTE_STRING" }, + SyntaxInfo { name: "RAW_BYTE_STRING" }, ]; pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { -- cgit v1.2.3