diff options
author | Marcus Klaas de Vries <[email protected]> | 2019-01-11 10:27:07 +0000 |
---|---|---|
committer | Marcus Klaas de Vries <[email protected]> | 2019-01-14 12:56:43 +0000 |
commit | 606d66a714bb8fe07f35a6af83d04ab576b9a0e1 (patch) | |
tree | dd69d9e6484d7a67d8545ef10ec736c24d90849e /crates/ra_syntax/src/ast/generated.rs | |
parent | 81bc8e4973fefd0ff31d08206c374fb58aa8b6e0 (diff) |
Start moving literal interpretation to the AST (WIP)
Diffstat (limited to 'crates/ra_syntax/src/ast/generated.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 114 |
1 files changed, 110 insertions, 4 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 94842a514..442659aee 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -664,7 +664,7 @@ pub enum ExprKind<'a> { | |||
664 | PrefixExpr(&'a PrefixExpr), | 664 | PrefixExpr(&'a PrefixExpr), |
665 | RangeExpr(&'a RangeExpr), | 665 | RangeExpr(&'a RangeExpr), |
666 | BinExpr(&'a BinExpr), | 666 | BinExpr(&'a BinExpr), |
667 | Literal(&'a Literal), | 667 | LiteralExpr(&'a LiteralExpr), |
668 | } | 668 | } |
669 | 669 | ||
670 | impl AstNode for Expr { | 670 | impl AstNode for Expr { |
@@ -696,7 +696,7 @@ impl AstNode for Expr { | |||
696 | | PREFIX_EXPR | 696 | | PREFIX_EXPR |
697 | | RANGE_EXPR | 697 | | RANGE_EXPR |
698 | | BIN_EXPR | 698 | | BIN_EXPR |
699 | | LITERAL => Some(Expr::from_repr(syntax.into_repr())), | 699 | | LITERAL_EXPR => Some(Expr::from_repr(syntax.into_repr())), |
700 | _ => None, | 700 | _ => None, |
701 | } | 701 | } |
702 | } | 702 | } |
@@ -733,7 +733,7 @@ impl Expr { | |||
733 | PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(&self.syntax).unwrap()), | 733 | PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(&self.syntax).unwrap()), |
734 | RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(&self.syntax).unwrap()), | 734 | RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(&self.syntax).unwrap()), |
735 | BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(&self.syntax).unwrap()), | 735 | BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(&self.syntax).unwrap()), |
736 | LITERAL => ExprKind::Literal(Literal::cast(&self.syntax).unwrap()), | 736 | LITERAL_EXPR => ExprKind::LiteralExpr(LiteralExpr::cast(&self.syntax).unwrap()), |
737 | _ => unreachable!(), | 737 | _ => unreachable!(), |
738 | } | 738 | } |
739 | } | 739 | } |
@@ -849,6 +849,31 @@ impl AstNode for FieldPatList { | |||
849 | 849 | ||
850 | impl FieldPatList {} | 850 | impl FieldPatList {} |
851 | 851 | ||
852 | // FloatNumber | ||
853 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
854 | #[repr(transparent)] | ||
855 | pub struct FloatNumber { | ||
856 | pub(crate) syntax: SyntaxNode, | ||
857 | } | ||
858 | unsafe impl TransparentNewType for FloatNumber { | ||
859 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
860 | } | ||
861 | |||
862 | impl AstNode for FloatNumber { | ||
863 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
864 | match syntax.kind() { | ||
865 | FLOAT_NUMBER => Some(FloatNumber::from_repr(syntax.into_repr())), | ||
866 | _ => None, | ||
867 | } | ||
868 | } | ||
869 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
870 | fn to_owned(&self) -> TreePtr<FloatNumber> { TreePtr::cast(self.syntax.to_owned()) } | ||
871 | } | ||
872 | |||
873 | |||
874 | impl ast::AstToken for FloatNumber {} | ||
875 | impl FloatNumber {} | ||
876 | |||
852 | // FnDef | 877 | // FnDef |
853 | #[derive(Debug, PartialEq, Eq, Hash)] | 878 | #[derive(Debug, PartialEq, Eq, Hash)] |
854 | #[repr(transparent)] | 879 | #[repr(transparent)] |
@@ -1130,6 +1155,31 @@ impl AstNode for IndexExpr { | |||
1130 | 1155 | ||
1131 | impl IndexExpr {} | 1156 | impl IndexExpr {} |
1132 | 1157 | ||
1158 | // IntNumber | ||
1159 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1160 | #[repr(transparent)] | ||
1161 | pub struct IntNumber { | ||
1162 | pub(crate) syntax: SyntaxNode, | ||
1163 | } | ||
1164 | unsafe impl TransparentNewType for IntNumber { | ||
1165 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1166 | } | ||
1167 | |||
1168 | impl AstNode for IntNumber { | ||
1169 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
1170 | match syntax.kind() { | ||
1171 | INT_NUMBER => Some(IntNumber::from_repr(syntax.into_repr())), | ||
1172 | _ => None, | ||
1173 | } | ||
1174 | } | ||
1175 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1176 | fn to_owned(&self) -> TreePtr<IntNumber> { TreePtr::cast(self.syntax.to_owned()) } | ||
1177 | } | ||
1178 | |||
1179 | |||
1180 | impl ast::AstToken for IntNumber {} | ||
1181 | impl IntNumber {} | ||
1182 | |||
1133 | // ItemList | 1183 | // ItemList |
1134 | #[derive(Debug, PartialEq, Eq, Hash)] | 1184 | #[derive(Debug, PartialEq, Eq, Hash)] |
1135 | #[repr(transparent)] | 1185 | #[repr(transparent)] |
@@ -1315,10 +1365,25 @@ unsafe impl TransparentNewType for Literal { | |||
1315 | type Repr = rowan::SyntaxNode<RaTypes>; | 1365 | type Repr = rowan::SyntaxNode<RaTypes>; |
1316 | } | 1366 | } |
1317 | 1367 | ||
1368 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
1369 | pub enum LiteralKind<'a> { | ||
1370 | String(&'a String), | ||
1371 | ByteString(&'a ByteString), | ||
1372 | Char(&'a Char), | ||
1373 | Byte(&'a Byte), | ||
1374 | IntNumber(&'a IntNumber), | ||
1375 | FloatNumber(&'a FloatNumber), | ||
1376 | } | ||
1377 | |||
1318 | impl AstNode for Literal { | 1378 | impl AstNode for Literal { |
1319 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | 1379 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { |
1320 | match syntax.kind() { | 1380 | match syntax.kind() { |
1321 | LITERAL => Some(Literal::from_repr(syntax.into_repr())), | 1381 | | STRING |
1382 | | BYTE_STRING | ||
1383 | | CHAR | ||
1384 | | BYTE | ||
1385 | | INT_NUMBER | ||
1386 | | FLOAT_NUMBER => Some(Literal::from_repr(syntax.into_repr())), | ||
1322 | _ => None, | 1387 | _ => None, |
1323 | } | 1388 | } |
1324 | } | 1389 | } |
@@ -1326,9 +1391,50 @@ impl AstNode for Literal { | |||
1326 | fn to_owned(&self) -> TreeArc<Literal> { TreeArc::cast(self.syntax.to_owned()) } | 1391 | fn to_owned(&self) -> TreeArc<Literal> { TreeArc::cast(self.syntax.to_owned()) } |
1327 | } | 1392 | } |
1328 | 1393 | ||
1394 | impl Literal { | ||
1395 | pub fn kind(&self) -> LiteralKind { | ||
1396 | match self.syntax.kind() { | ||
1397 | STRING => LiteralKind::String(String::cast(&self.syntax).unwrap()), | ||
1398 | BYTE_STRING => LiteralKind::ByteString(ByteString::cast(&self.syntax).unwrap()), | ||
1399 | CHAR => LiteralKind::Char(Char::cast(&self.syntax).unwrap()), | ||
1400 | BYTE => LiteralKind::Byte(Byte::cast(&self.syntax).unwrap()), | ||
1401 | INT_NUMBER => LiteralKind::IntNumber(IntNumber::cast(&self.syntax).unwrap()), | ||
1402 | FLOAT_NUMBER => LiteralKind::FloatNumber(FloatNumber::cast(&self.syntax).unwrap()), | ||
1403 | _ => unreachable!(), | ||
1404 | } | ||
1405 | } | ||
1406 | } | ||
1329 | 1407 | ||
1330 | impl Literal {} | 1408 | impl Literal {} |
1331 | 1409 | ||
1410 | // LiteralExpr | ||
1411 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
1412 | #[repr(transparent)] | ||
1413 | pub struct LiteralExpr { | ||
1414 | pub(crate) syntax: SyntaxNode, | ||
1415 | } | ||
1416 | unsafe impl TransparentNewType for LiteralExpr { | ||
1417 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
1418 | } | ||
1419 | |||
1420 | impl AstNode for LiteralExpr { | ||
1421 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
1422 | match syntax.kind() { | ||
1423 | LITERAL_EXPR => Some(LiteralExpr::from_repr(syntax.into_repr())), | ||
1424 | _ => None, | ||
1425 | } | ||
1426 | } | ||
1427 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1428 | fn to_owned(&self) -> TreePtr<LiteralExpr> { TreePtr::cast(self.syntax.to_owned()) } | ||
1429 | } | ||
1430 | |||
1431 | |||
1432 | impl LiteralExpr { | ||
1433 | pub fn literal(&self) -> Option<&Literal> { | ||
1434 | super::child_opt(self) | ||
1435 | } | ||
1436 | } | ||
1437 | |||
1332 | // LoopExpr | 1438 | // LoopExpr |
1333 | #[derive(Debug, PartialEq, Eq, Hash)] | 1439 | #[derive(Debug, PartialEq, Eq, Hash)] |
1334 | #[repr(transparent)] | 1440 | #[repr(transparent)] |