aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs45
-rw-r--r--crates/ra_syntax/src/grammar.ron1
-rw-r--r--crates/ra_syntax/src/string_lexing/parser.rs2
-rw-r--r--crates/ra_syntax/src/validation/char.rs2
4 files changed, 48 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index c22e026cf..c5ac90a62 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1838,6 +1838,51 @@ impl<R: TreeRoot<RaTypes>> LoopExprNode<R> {
1838impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {} 1838impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {}
1839impl<'a> LoopExpr<'a> {} 1839impl<'a> LoopExpr<'a> {}
1840 1840
1841// MacroCall
1842#[derive(Debug, Clone, Copy,)]
1843pub struct MacroCallNode<R: TreeRoot<RaTypes> = OwnedRoot> {
1844 pub(crate) syntax: SyntaxNode<R>,
1845}
1846pub type MacroCall<'a> = MacroCallNode<RefRoot<'a>>;
1847
1848impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MacroCallNode<R1>> for MacroCallNode<R2> {
1849 fn eq(&self, other: &MacroCallNode<R1>) -> bool { self.syntax == other.syntax }
1850}
1851impl<R: TreeRoot<RaTypes>> Eq for MacroCallNode<R> {}
1852impl<R: TreeRoot<RaTypes>> Hash for MacroCallNode<R> {
1853 fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
1854}
1855
1856impl<'a> AstNode<'a> for MacroCall<'a> {
1857 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
1858 match syntax.kind() {
1859 MACRO_CALL => Some(MacroCall { syntax }),
1860 _ => None,
1861 }
1862 }
1863 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
1864}
1865
1866impl<R: TreeRoot<RaTypes>> MacroCallNode<R> {
1867 pub fn borrowed(&self) -> MacroCall {
1868 MacroCallNode { syntax: self.syntax.borrowed() }
1869 }
1870 pub fn owned(&self) -> MacroCallNode {
1871 MacroCallNode { syntax: self.syntax.owned() }
1872 }
1873}
1874
1875
1876impl<'a> MacroCall<'a> {
1877 pub fn token_tree(self) -> Option<TokenTree<'a>> {
1878 super::child_opt(self)
1879 }
1880
1881 pub fn path(self) -> Option<Path<'a>> {
1882 super::child_opt(self)
1883 }
1884}
1885
1841// MatchArm 1886// MatchArm
1842#[derive(Debug, Clone, Copy,)] 1887#[derive(Debug, Clone, Copy,)]
1843pub struct MatchArmNode<R: TreeRoot<RaTypes> = OwnedRoot> { 1888pub struct MatchArmNode<R: TreeRoot<RaTypes> = OwnedRoot> {
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index 4bcff4e14..aab4839a9 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -484,6 +484,7 @@ Grammar(
484 484
485 "Name": (), 485 "Name": (),
486 "NameRef": (), 486 "NameRef": (),
487 "MacroCall": ( options: [ "TokenTree", "Path" ] ),
487 "Attr": ( options: [ ["value", "TokenTree"] ] ), 488 "Attr": ( options: [ ["value", "TokenTree"] ] ),
488 "TokenTree": (), 489 "TokenTree": (),
489 "TypeParamList": ( 490 "TypeParamList": (
diff --git a/crates/ra_syntax/src/string_lexing/parser.rs b/crates/ra_syntax/src/string_lexing/parser.rs
index 14c6015c2..e835382fc 100644
--- a/crates/ra_syntax/src/string_lexing/parser.rs
+++ b/crates/ra_syntax/src/string_lexing/parser.rs
@@ -82,7 +82,7 @@ impl<'a> Parser<'a> {
82 82
83 fn parse_escape(&mut self, start: TextUnit) -> StringComponent { 83 fn parse_escape(&mut self, start: TextUnit) -> StringComponent {
84 if self.peek().is_none() { 84 if self.peek().is_none() {
85 return StringComponent::new(TextRange::from_to(start, start), AsciiEscape); 85 return StringComponent::new(TextRange::from_to(start, self.get_pos()), AsciiEscape);
86 } 86 }
87 87
88 let next = self.advance(); 88 let next = self.advance();
diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs
index 19cd3830f..10d3d1dec 100644
--- a/crates/ra_syntax/src/validation/char.rs
+++ b/crates/ra_syntax/src/validation/char.rs
@@ -70,7 +70,7 @@ pub(super) fn validate_char_component(
70 70
71fn validate_ascii_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) { 71fn validate_ascii_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) {
72 if text.len() == 1 { 72 if text.len() == 1 {
73 // Escape sequence consists only of leading `\` 73 // Escape sequence consists only of leading `\` (only occurs at EOF, otherwise e.g. '\' is treated as an unclosed char containing a single quote `'`)
74 errors.push(SyntaxError::new(EmptyAsciiEscape, range)); 74 errors.push(SyntaxError::new(EmptyAsciiEscape, range));
75 } else { 75 } else {
76 let escape_code = text.chars().skip(1).next().unwrap(); 76 let escape_code = text.chars().skip(1).next().unwrap();