Validate byte string literals

This commit is contained in:
Adolfo Ochagavía 2018-11-11 20:41:43 +01:00
parent c258b4fdb0
commit 30cd4d5acb
8 changed files with 305 additions and 24 deletions

View file

@ -409,6 +409,43 @@ impl<R: TreeRoot<RaTypes>> ByteNode<R> {
impl<'a> Byte<'a> {}
// ByteString
#[derive(Debug, Clone, Copy,)]
pub struct ByteStringNode<R: TreeRoot<RaTypes> = OwnedRoot> {
pub(crate) syntax: SyntaxNode<R>,
}
pub type ByteString<'a> = ByteStringNode<RefRoot<'a>>;
impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteStringNode<R1>> for ByteStringNode<R2> {
fn eq(&self, other: &ByteStringNode<R1>) -> bool { self.syntax == other.syntax }
}
impl<R: TreeRoot<RaTypes>> Eq for ByteStringNode<R> {}
impl<R: TreeRoot<RaTypes>> Hash for ByteStringNode<R> {
fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
}
impl<'a> AstNode<'a> for ByteString<'a> {
fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
match syntax.kind() {
BYTE_STRING => Some(ByteString { syntax }),
_ => None,
}
}
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
}
impl<R: TreeRoot<RaTypes>> ByteStringNode<R> {
pub fn borrowed(&self) -> ByteString {
ByteStringNode { syntax: self.syntax.borrowed() }
}
pub fn owned(&self) -> ByteStringNode {
ByteStringNode { syntax: self.syntax.owned() }
}
}
impl<'a> ByteString<'a> {}
// CallExpr
#[derive(Debug, Clone, Copy,)]
pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> {