From 412948c0e2f34b1db13201bf533468241ee881e6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 30 Dec 2017 18:25:37 +0300 Subject: [PATCH] More symbols --- grammar.ron | 5 +++++ src/lexer/mod.rs | 20 ++++++++++++++++++++ src/syntax_kinds.rs | 12 +++++++++++- tests/data/lexer/0005_symbols.rs | 4 +++- tests/data/lexer/0005_symbols.txt | 8 ++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/grammar.ron b/grammar.ron index 56617f7575..4c9291dfba 100644 --- a/grammar.ron +++ b/grammar.ron @@ -25,5 +25,10 @@ Grammar( "COLON", "COLONCOLON", "DOLLAR", + "EQ", + "EQEQ", + "FAT_ARROW", + "NEQ", + "NOT", ] ) \ No newline at end of file diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index d2d4aaa222..5255c3d563 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -52,6 +52,8 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { '~' => return TILDE, '?' => return QUESTION, '$' => return DOLLAR, + + // Multi-byte tokens. '.' => return match (ptr.next(), ptr.nnext()) { (Some('.'), Some('.')) => { ptr.bump(); @@ -76,6 +78,24 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { } _ => COLON }, + '=' => return match ptr.next() { + Some('=') => { + ptr.bump(); + EQEQ + } + Some('>') => { + ptr.bump(); + FAT_ARROW + } + _ => EQ, + }, + '!' => return match ptr.next() { + Some('=') => { + ptr.bump(); + NEQ + } + _ => NOT, + }, _ => (), } ERROR diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 6982cba950..a922056cee 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs @@ -26,8 +26,13 @@ pub const QUESTION: SyntaxKind = SyntaxKind(21); pub const COLON: SyntaxKind = SyntaxKind(22); pub const COLONCOLON: SyntaxKind = SyntaxKind(23); pub const DOLLAR: SyntaxKind = SyntaxKind(24); +pub const EQ: SyntaxKind = SyntaxKind(25); +pub const EQEQ: SyntaxKind = SyntaxKind(26); +pub const FAT_ARROW: SyntaxKind = SyntaxKind(27); +pub const NEQ: SyntaxKind = SyntaxKind(28); +pub const NOT: SyntaxKind = SyntaxKind(29); -static INFOS: [SyntaxInfo; 25] = [ +static INFOS: [SyntaxInfo; 30] = [ SyntaxInfo { name: "ERROR" }, SyntaxInfo { name: "IDENT" }, SyntaxInfo { name: "UNDERSCORE" }, @@ -53,6 +58,11 @@ static INFOS: [SyntaxInfo; 25] = [ SyntaxInfo { name: "COLON" }, SyntaxInfo { name: "COLONCOLON" }, SyntaxInfo { name: "DOLLAR" }, + SyntaxInfo { name: "EQ" }, + SyntaxInfo { name: "EQEQ" }, + SyntaxInfo { name: "FAT_ARROW" }, + SyntaxInfo { name: "NEQ" }, + SyntaxInfo { name: "NOT" }, ]; pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { diff --git a/tests/data/lexer/0005_symbols.rs b/tests/data/lexer/0005_symbols.rs index 79747d5e1f..00ed44b65c 100644 --- a/tests/data/lexer/0005_symbols.rs +++ b/tests/data/lexer/0005_symbols.rs @@ -1,3 +1,5 @@ ; , ( ) { } [ ] @ # ~ ? $ . .. ... ..= -: :: \ No newline at end of file +: :: += => +! != \ No newline at end of file diff --git a/tests/data/lexer/0005_symbols.txt b/tests/data/lexer/0005_symbols.txt index c845d2dff6..291872026f 100644 --- a/tests/data/lexer/0005_symbols.txt +++ b/tests/data/lexer/0005_symbols.txt @@ -35,3 +35,11 @@ WHITESPACE 1 "\n" COLON 1 ":" WHITESPACE 1 " " COLONCOLON 2 "::" +WHITESPACE 1 "\n" +EQ 1 "=" +WHITESPACE 1 " " +FAT_ARROW 2 "=>" +WHITESPACE 1 "\n" +NOT 1 "!" +WHITESPACE 1 " " +NEQ 2 "!="