From 9d5138bf11eb0c979c49f904010d2d3690bdf74c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 31 Dec 2017 11:32:49 +0300 Subject: Lexer: simplistic char & lifetime tests --- src/lexer/mod.rs | 3 +- tests/data/lexer/0004_number.rs | 9 ----- tests/data/lexer/0004_number.txt | 67 ------------------------------------- tests/data/lexer/0004_numbers.rs | 9 +++++ tests/data/lexer/0004_numbers.txt | 67 +++++++++++++++++++++++++++++++++++++ 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 +++++ 9 files changed, 94 insertions(+), 77 deletions(-) delete mode 100644 tests/data/lexer/0004_number.rs delete mode 100644 tests/data/lexer/0004_number.txt create mode 100644 tests/data/lexer/0004_numbers.rs create mode 100644 tests/data/lexer/0004_numbers.txt 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 918683556..320d59de5 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_number.rs deleted file mode 100644 index dc974b553..000000000 --- a/tests/data/lexer/0004_number.rs +++ /dev/null @@ -1,9 +0,0 @@ -0 0b 0o 0x 00 0_ 0. 0e 0E 0z -01790 0b1790 0o1790 0x1790aAbBcCdDeEfF 001279 0_1279 0.1279 0e1279 0E1279 -0..2 -0.foo() -0e+1 -0.e+1 -0.0E-2 -0___0.10000____0000e+111__ -1i64 92.0f32 11__s \ No newline at end of file diff --git a/tests/data/lexer/0004_number.txt b/tests/data/lexer/0004_number.txt deleted file mode 100644 index be8dee48b..000000000 --- a/tests/data/lexer/0004_number.txt +++ /dev/null @@ -1,67 +0,0 @@ -INT_NUMBER 1 "0" -WHITESPACE 1 " " -INT_NUMBER 2 "0b" -WHITESPACE 1 " " -INT_NUMBER 2 "0o" -WHITESPACE 1 " " -INT_NUMBER 2 "0x" -WHITESPACE 1 " " -INT_NUMBER 2 "00" -WHITESPACE 1 " " -INT_NUMBER 2 "0_" -WHITESPACE 1 " " -FLOAT_NUMBER 2 "0." -WHITESPACE 1 " " -INT_NUMBER 2 "0e" -WHITESPACE 1 " " -INT_NUMBER 2 "0E" -WHITESPACE 1 " " -INT_NUMBER 2 "0z" -WHITESPACE 1 "\n" -INT_NUMBER 5 "01790" -WHITESPACE 1 " " -INT_NUMBER 6 "0b1790" -WHITESPACE 1 " " -INT_NUMBER 6 "0o1790" -WHITESPACE 1 " " -INT_NUMBER 18 "0x1790aAbBcCdDeEfF" -WHITESPACE 1 " " -INT_NUMBER 6 "001279" -WHITESPACE 1 " " -INT_NUMBER 6 "0_1279" -WHITESPACE 1 " " -FLOAT_NUMBER 6 "0.1279" -WHITESPACE 1 " " -INT_NUMBER 6 "0e1279" -WHITESPACE 1 " " -INT_NUMBER 6 "0E1279" -WHITESPACE 1 "\n" -INT_NUMBER 1 "0" -DOTDOT 2 ".." -INT_NUMBER 1 "2" -WHITESPACE 1 "\n" -INT_NUMBER 1 "0" -DOT 1 "." -IDENT 3 "foo" -L_PAREN 1 "(" -R_PAREN 1 ")" -WHITESPACE 1 "\n" -INT_NUMBER 2 "0e" -ERROR 1 "+" -INT_NUMBER 1 "1" -WHITESPACE 1 "\n" -INT_NUMBER 1 "0" -DOT 1 "." -IDENT 1 "e" -ERROR 1 "+" -INT_NUMBER 1 "1" -WHITESPACE 1 "\n" -FLOAT_NUMBER 6 "0.0E-2" -WHITESPACE 1 "\n" -FLOAT_NUMBER 26 "0___0.10000____0000e+111__" -WHITESPACE 1 "\n" -INT_NUMBER 4 "1i64" -WHITESPACE 1 " " -FLOAT_NUMBER 7 "92.0f32" -WHITESPACE 1 " " -INT_NUMBER 5 "11__s" diff --git a/tests/data/lexer/0004_numbers.rs b/tests/data/lexer/0004_numbers.rs new file mode 100644 index 000000000..dc974b553 --- /dev/null +++ b/tests/data/lexer/0004_numbers.rs @@ -0,0 +1,9 @@ +0 0b 0o 0x 00 0_ 0. 0e 0E 0z +01790 0b1790 0o1790 0x1790aAbBcCdDeEfF 001279 0_1279 0.1279 0e1279 0E1279 +0..2 +0.foo() +0e+1 +0.e+1 +0.0E-2 +0___0.10000____0000e+111__ +1i64 92.0f32 11__s \ No newline at end of file diff --git a/tests/data/lexer/0004_numbers.txt b/tests/data/lexer/0004_numbers.txt new file mode 100644 index 000000000..be8dee48b --- /dev/null +++ b/tests/data/lexer/0004_numbers.txt @@ -0,0 +1,67 @@ +INT_NUMBER 1 "0" +WHITESPACE 1 " " +INT_NUMBER 2 "0b" +WHITESPACE 1 " " +INT_NUMBER 2 "0o" +WHITESPACE 1 " " +INT_NUMBER 2 "0x" +WHITESPACE 1 " " +INT_NUMBER 2 "00" +WHITESPACE 1 " " +INT_NUMBER 2 "0_" +WHITESPACE 1 " " +FLOAT_NUMBER 2 "0." +WHITESPACE 1 " " +INT_NUMBER 2 "0e" +WHITESPACE 1 " " +INT_NUMBER 2 "0E" +WHITESPACE 1 " " +INT_NUMBER 2 "0z" +WHITESPACE 1 "\n" +INT_NUMBER 5 "01790" +WHITESPACE 1 " " +INT_NUMBER 6 "0b1790" +WHITESPACE 1 " " +INT_NUMBER 6 "0o1790" +WHITESPACE 1 " " +INT_NUMBER 18 "0x1790aAbBcCdDeEfF" +WHITESPACE 1 " " +INT_NUMBER 6 "001279" +WHITESPACE 1 " " +INT_NUMBER 6 "0_1279" +WHITESPACE 1 " " +FLOAT_NUMBER 6 "0.1279" +WHITESPACE 1 " " +INT_NUMBER 6 "0e1279" +WHITESPACE 1 " " +INT_NUMBER 6 "0E1279" +WHITESPACE 1 "\n" +INT_NUMBER 1 "0" +DOTDOT 2 ".." +INT_NUMBER 1 "2" +WHITESPACE 1 "\n" +INT_NUMBER 1 "0" +DOT 1 "." +IDENT 3 "foo" +L_PAREN 1 "(" +R_PAREN 1 ")" +WHITESPACE 1 "\n" +INT_NUMBER 2 "0e" +ERROR 1 "+" +INT_NUMBER 1 "1" +WHITESPACE 1 "\n" +INT_NUMBER 1 "0" +DOT 1 "." +IDENT 1 "e" +ERROR 1 "+" +INT_NUMBER 1 "1" +WHITESPACE 1 "\n" +FLOAT_NUMBER 6 "0.0E-2" +WHITESPACE 1 "\n" +FLOAT_NUMBER 26 "0___0.10000____0000e+111__" +WHITESPACE 1 "\n" +INT_NUMBER 4 "1i64" +WHITESPACE 1 " " +FLOAT_NUMBER 7 "92.0f32" +WHITESPACE 1 " " +INT_NUMBER 5 "11__s" diff --git a/tests/data/lexer/0006_chars.rs b/tests/data/lexer/0006_chars.rs new file mode 100644 index 000000000..03598d908 --- /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 000000000..ecaf22355 --- /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 000000000..b764f1dce --- /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 000000000..005c29100 --- /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" -- cgit v1.2.3