cargo fmt why not
This commit is contained in:
parent
fd09a6739b
commit
836445d5e2
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -36,6 +36,7 @@ name = "aidl"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"logos 0.13.0",
|
"logos 0.13.0",
|
||||||
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -74,11 +74,11 @@ pub enum NumberLiteral {
|
||||||
U64(u64),
|
U64(u64),
|
||||||
I64(i64),
|
I64(i64),
|
||||||
|
|
||||||
Infer(i64)
|
Infer(i64),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// seg1.seg2.seg3.segN
|
/// seg1.seg2.seg3.segN
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ModulePath {
|
pub struct ModulePath {
|
||||||
pub segments: Vec<String>
|
pub segments: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use std::{ops::{Range, Add}, fmt::Display};
|
use std::{
|
||||||
|
fmt::Display,
|
||||||
|
ops::{Add, Range},
|
||||||
|
};
|
||||||
|
|
||||||
use logos::Logos;
|
use logos::Logos;
|
||||||
|
|
||||||
|
@ -60,7 +63,7 @@ pub enum Ident {
|
||||||
#[token("Use")]
|
#[token("Use")]
|
||||||
Use,
|
Use,
|
||||||
#[regex(r"[A-z]+", |lex| lex.slice().parse().ok())]
|
#[regex(r"[A-z]+", |lex| lex.slice().parse().ok())]
|
||||||
Other(String)
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -76,7 +79,7 @@ impl Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn concat(self, other: Span) -> Self {
|
pub fn concat(self, other: Span) -> Self {
|
||||||
use std::cmp::{min, max};
|
use std::cmp::{max, min};
|
||||||
|
|
||||||
Self(min(self.lower(), other.lower())..max(self.upper(), other.upper()))
|
Self(min(self.lower(), other.lower())..max(self.upper(), other.upper()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,10 @@ const TEST: &str = include_str!("../assets/why.idl");
|
||||||
fn main() {
|
fn main() {
|
||||||
let res = Parser::new(TEST).parse();
|
let res = Parser::new(TEST).parse();
|
||||||
match res {
|
match res {
|
||||||
Ok(ast) => { dbg!(ast); }
|
Ok(ast) => {
|
||||||
Err(e) => println!("{}", e)
|
dbg!(ast);
|
||||||
|
}
|
||||||
|
Err(e) => println!("{}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +23,7 @@ macro_rules! unwrap_match {
|
||||||
($x:expr, $m:pat => $a:expr) => {
|
($x:expr, $m:pat => $a:expr) => {
|
||||||
match $x {
|
match $x {
|
||||||
$m => $a,
|
$m => $a,
|
||||||
_ => unreachable!()
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,11 +73,11 @@ impl<'a> Parser<'a> {
|
||||||
if matcher(self.tokens.peek()?.0) {
|
if matcher(self.tokens.peek()?.0) {
|
||||||
self.tokens.next()
|
self.tokens.next()
|
||||||
} else {
|
} else {
|
||||||
Err(self.unexpected(expected))
|
Err(self.expected(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unexpected(&self, expected: &'static str) -> ParserError {
|
fn expected(&self, expected: &'static str) -> ParserError {
|
||||||
ParserError::Unexpected(expected.to_owned(), self.tokens.current())
|
ParserError::Unexpected(expected.to_owned(), self.tokens.current())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ impl<'a> Parser<'a> {
|
||||||
span = span + v.1;
|
span = span + v.1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => return Err(self.unexpected("a path segment")),
|
_ => return Err(self.expected("a path segment")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,21 +163,21 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ask_constant(&mut self) -> Result<Spanned<ItemConstant>, ParserError> {
|
fn ask_constant(&mut self) -> Result<Spanned<ItemConstant>, ParserError> {
|
||||||
Err(self.unexpected(""))
|
Err(self.expected("the constant to be implemented"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ask_item(&mut self) -> Result<Spanned<Item>, ParserError> {
|
fn ask_item(&mut self) -> Result<Spanned<Item>, ParserError> {
|
||||||
Ok(match self.tokens.peek()?.0 {
|
Ok(match self.tokens.peek()?.0 {
|
||||||
Token::Ident(Ident::Other(_)) => {
|
Token::Ident(Ident::Other(_)) => {
|
||||||
Err(self.unexpected("a keyword, not just an identifier"))?
|
Err(self.expected("a keyword, not just an identifier"))?
|
||||||
}
|
}
|
||||||
Token::Ident(keyword) => match keyword {
|
Token::Ident(keyword) => match keyword {
|
||||||
//Ident::Interface => self.ask_interface()?.map(Item::Interface),
|
//Ident::Interface => self.ask_interface()?.map(Item::Interface),
|
||||||
Ident::Alias => self.ask_alias()?.map(Item::Alias),
|
Ident::Alias => self.ask_alias()?.map(Item::Alias),
|
||||||
Ident::Constant => self.ask_constant()?.map(Item::Constant),
|
Ident::Constant => self.ask_constant()?.map(Item::Constant),
|
||||||
_ => Err(self.unexpected("`Alias` or `Constant`"))?,
|
_ => Err(self.expected("`Alias` or `Constant`"))?,
|
||||||
},
|
},
|
||||||
_ => Err(self.unexpected("a keyword"))?,
|
_ => Err(self.expected("a keyword"))?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue