aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorMarcus Klaas de Vries <[email protected]>2019-01-14 19:56:14 +0000
committerMarcus Klaas de Vries <[email protected]>2019-01-14 19:56:14 +0000
commitd67eabb512a08a451a649c7f20e4e9ae1860a8a0 (patch)
tree99c5fb5004f3fb7a6b0855033855c439675cc0ff /crates/ra_syntax
parent26893487722d07b3f31a6addfc88e6948620989c (diff)
Fix type inference for raw (byte) strings
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs56
-rw-r--r--crates/ra_syntax/src/grammar.ron4
-rw-r--r--crates/ra_syntax/src/lexer/strings.rs15
3 files changed, 61 insertions, 14 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index cad845ec0..3471d5226 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1422,6 +1422,8 @@ unsafe impl TransparentNewType for LiteralExpr {
1422pub enum LiteralExprKind<'a> { 1422pub enum LiteralExprKind<'a> {
1423 String(&'a String), 1423 String(&'a String),
1424 ByteString(&'a ByteString), 1424 ByteString(&'a ByteString),
1425 RawString(&'a RawString),
1426 RawByteString(&'a RawByteString),
1425 Char(&'a Char), 1427 Char(&'a Char),
1426 Byte(&'a Byte), 1428 Byte(&'a Byte),
1427 IntNumber(&'a IntNumber), 1429 IntNumber(&'a IntNumber),
@@ -1435,6 +1437,8 @@ impl AstNode for LiteralExpr {
1435 match syntax.kind() { 1437 match syntax.kind() {
1436 | STRING 1438 | STRING
1437 | BYTE_STRING 1439 | BYTE_STRING
1440 | RAW_STRING
1441 | RAW_BYTE_STRING
1438 | CHAR 1442 | CHAR
1439 | BYTE 1443 | BYTE
1440 | INT_NUMBER 1444 | INT_NUMBER
@@ -1453,6 +1457,8 @@ impl LiteralExpr {
1453 match self.syntax.kind() { 1457 match self.syntax.kind() {
1454 STRING => LiteralExprKind::String(String::cast(&self.syntax).unwrap()), 1458 STRING => LiteralExprKind::String(String::cast(&self.syntax).unwrap()),
1455 BYTE_STRING => LiteralExprKind::ByteString(ByteString::cast(&self.syntax).unwrap()), 1459 BYTE_STRING => LiteralExprKind::ByteString(ByteString::cast(&self.syntax).unwrap()),
1460 RAW_STRING => LiteralExprKind::RawString(RawString::cast(&self.syntax).unwrap()),
1461 RAW_BYTE_STRING => LiteralExprKind::RawByteString(RawByteString::cast(&self.syntax).unwrap()),
1456 CHAR => LiteralExprKind::Char(Char::cast(&self.syntax).unwrap()), 1462 CHAR => LiteralExprKind::Char(Char::cast(&self.syntax).unwrap()),
1457 BYTE => LiteralExprKind::Byte(Byte::cast(&self.syntax).unwrap()), 1463 BYTE => LiteralExprKind::Byte(Byte::cast(&self.syntax).unwrap()),
1458 INT_NUMBER => LiteralExprKind::IntNumber(IntNumber::cast(&self.syntax).unwrap()), 1464 INT_NUMBER => LiteralExprKind::IntNumber(IntNumber::cast(&self.syntax).unwrap()),
@@ -2543,6 +2549,56 @@ impl AstNode for RangePat {
2543 2549
2544impl RangePat {} 2550impl RangePat {}
2545 2551
2552// RawByteString
2553#[derive(Debug, PartialEq, Eq, Hash)]
2554#[repr(transparent)]
2555pub struct RawByteString {
2556 pub(crate) syntax: SyntaxNode,
2557}
2558unsafe impl TransparentNewType for RawByteString {
2559 type Repr = rowan::SyntaxNode<RaTypes>;
2560}
2561
2562impl AstNode for RawByteString {
2563 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2564 match syntax.kind() {
2565 RAW_BYTE_STRING => Some(RawByteString::from_repr(syntax.into_repr())),
2566 _ => None,
2567 }
2568 }
2569 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2570 fn to_owned(&self) -> TreeArc<RawByteString> { TreeArc::cast(self.syntax.to_owned()) }
2571}
2572
2573
2574impl ast::AstToken for RawByteString {}
2575impl RawByteString {}
2576
2577// RawString
2578#[derive(Debug, PartialEq, Eq, Hash)]
2579#[repr(transparent)]
2580pub struct RawString {
2581 pub(crate) syntax: SyntaxNode,
2582}
2583unsafe impl TransparentNewType for RawString {
2584 type Repr = rowan::SyntaxNode<RaTypes>;
2585}
2586
2587impl AstNode for RawString {
2588 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
2589 match syntax.kind() {
2590 RAW_STRING => Some(RawString::from_repr(syntax.into_repr())),
2591 _ => None,
2592 }
2593 }
2594 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2595 fn to_owned(&self) -> TreeArc<RawString> { TreeArc::cast(self.syntax.to_owned()) }
2596}
2597
2598
2599impl ast::AstToken for RawString {}
2600impl RawString {}
2601
2546// RefExpr 2602// RefExpr
2547#[derive(Debug, PartialEq, Eq, Hash)] 2603#[derive(Debug, PartialEq, Eq, Hash)]
2548#[repr(transparent)] 2604#[repr(transparent)]
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index 34d2a27d1..bd8c5b411 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -430,7 +430,9 @@ Grammar(
430 "IntNumber": ( traits: ["AstToken"] ), 430 "IntNumber": ( traits: ["AstToken"] ),
431 "FloatNumber": ( traits: ["AstToken"] ), 431 "FloatNumber": ( traits: ["AstToken"] ),
432 "String": ( traits: ["AstToken"] ), 432 "String": ( traits: ["AstToken"] ),
433 "RawString": ( traits: ["AstToken"] ),
433 "Byte": ( traits: ["AstToken"] ), 434 "Byte": ( traits: ["AstToken"] ),
435 "RawByteString": ( traits: ["AstToken"] ),
434 "ByteString": ( traits: ["AstToken"] ), 436 "ByteString": ( traits: ["AstToken"] ),
435 "Char": ( traits: ["AstToken"] ), 437 "Char": ( traits: ["AstToken"] ),
436 "TrueKw": ( traits: ["AstToken"] ), 438 "TrueKw": ( traits: ["AstToken"] ),
@@ -439,6 +441,8 @@ Grammar(
439 enum: [ 441 enum: [
440 "String", 442 "String",
441 "ByteString", 443 "ByteString",
444 "RawString",
445 "RawByteString",
442 "Char", 446 "Char",
443 "Byte", 447 "Byte",
444 "IntNumber", 448 "IntNumber",
diff --git a/crates/ra_syntax/src/lexer/strings.rs b/crates/ra_syntax/src/lexer/strings.rs
index 5090feae6..0865b7f3b 100644
--- a/crates/ra_syntax/src/lexer/strings.rs
+++ b/crates/ra_syntax/src/lexer/strings.rs
@@ -49,7 +49,7 @@ pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind {
49 BYTE_STRING 49 BYTE_STRING
50 } 50 }
51 'r' => { 51 'r' => {
52 scan_raw_byte_string(ptr); 52 scan_raw_string(ptr);
53 RAW_BYTE_STRING 53 RAW_BYTE_STRING
54 } 54 }
55 _ => unreachable!(), 55 _ => unreachable!(),
@@ -108,16 +108,3 @@ fn scan_byte(ptr: &mut Ptr) {
108fn scan_byte_string(ptr: &mut Ptr) { 108fn scan_byte_string(ptr: &mut Ptr) {
109 scan_string(ptr) 109 scan_string(ptr)
110} 110}
111
112fn scan_raw_byte_string(ptr: &mut Ptr) {
113 if !ptr.at('"') {
114 return;
115 }
116 ptr.bump();
117
118 while let Some(c) = ptr.bump() {
119 if c == '"' {
120 return;
121 }
122 }
123}