From 9d5138bf11eb0c979c49f904010d2d3690bdf74c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 31 Dec 2017 11:32:49 +0300 Subject: [PATCH] Lexer: simplistic char & lifetime tests --- src/lexer/mod.rs | 3 ++- tests/data/lexer/{0004_number.rs => 0004_numbers.rs} | 0 tests/data/lexer/{0004_number.txt => 0004_numbers.txt} | 0 tests/data/lexer/0006_chars.rs | 1 + tests/data/lexer/0006_chars.txt | 6 ++++++ tests/data/lexer/0007_lifetimes.rs | 1 + tests/data/lexer/0007_lifetimes.txt | 8 ++++++++ 7 files changed, 18 insertions(+), 1 deletion(-) rename tests/data/lexer/{0004_number.rs => 0004_numbers.rs} (100%) rename tests/data/lexer/{0004_number.txt => 0004_numbers.txt} (100%) create mode 100644 tests/data/lexer/0006_chars.rs create mode 100644 tests/data/lexer/0006_chars.txt create mode 100644 tests/data/lexer/0007_lifetimes.rs create mode 100644 tests/data/lexer/0007_lifetimes.txt diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index 918683556f..320d59de5e 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -101,7 +101,7 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { _ => NOT, }, - // '\'' => scan_char_or_lifetime(ptr), + '\'' => return scan_char_or_lifetime(ptr), _ => (), } ERROR @@ -159,6 +159,7 @@ fn scan_literal_suffix(ptr: &mut Ptr) { } fn scan_char_or_byte(ptr: &mut Ptr) { + //FIXME: deal with escape sequencies ptr.bump(); } diff --git a/tests/data/lexer/0004_number.rs b/tests/data/lexer/0004_numbers.rs similarity index 100% rename from tests/data/lexer/0004_number.rs rename to tests/data/lexer/0004_numbers.rs diff --git a/tests/data/lexer/0004_number.txt b/tests/data/lexer/0004_numbers.txt similarity index 100% rename from tests/data/lexer/0004_number.txt rename to tests/data/lexer/0004_numbers.txt diff --git a/tests/data/lexer/0006_chars.rs b/tests/data/lexer/0006_chars.rs new file mode 100644 index 0000000000..03598d9082 --- /dev/null +++ b/tests/data/lexer/0006_chars.rs @@ -0,0 +1 @@ +'x' ' ' '0' diff --git a/tests/data/lexer/0006_chars.txt b/tests/data/lexer/0006_chars.txt new file mode 100644 index 0000000000..ecaf223552 --- /dev/null +++ b/tests/data/lexer/0006_chars.txt @@ -0,0 +1,6 @@ +CHAR 3 "\'x\'" +WHITESPACE 1 " " +CHAR 3 "\' \'" +WHITESPACE 1 " " +CHAR 3 "\'0\'" +WHITESPACE 1 "\n" diff --git a/tests/data/lexer/0007_lifetimes.rs b/tests/data/lexer/0007_lifetimes.rs new file mode 100644 index 0000000000..b764f1dce3 --- /dev/null +++ b/tests/data/lexer/0007_lifetimes.rs @@ -0,0 +1 @@ +'a 'foo 'foo_bar_baz '_ diff --git a/tests/data/lexer/0007_lifetimes.txt b/tests/data/lexer/0007_lifetimes.txt new file mode 100644 index 0000000000..005c29100a --- /dev/null +++ b/tests/data/lexer/0007_lifetimes.txt @@ -0,0 +1,8 @@ +LIFETIME 2 "\'a" +WHITESPACE 1 " " +LIFETIME 4 "\'foo" +WHITESPACE 1 " " +LIFETIME 12 "\'foo_bar_baz" +WHITESPACE 1 " " +LIFETIME 2 "\'_" +WHITESPACE 1 "\n"