Refactored Path
This commit is contained in:
+8
-11
@@ -20,22 +20,19 @@ pub enum TypePostfix {
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum Attribute {
|
||||
/// #[test]
|
||||
Path(StaticPath),
|
||||
Path(Path),
|
||||
|
||||
/// #[name = "value"]
|
||||
NameValue { path: StaticPath, value: Literal },
|
||||
NameValue { path: Path, value: Literal },
|
||||
|
||||
/// #[derive(Clone, Copy)]
|
||||
List {
|
||||
path: StaticPath,
|
||||
items: Vec<Attribute>,
|
||||
},
|
||||
List { path: Path, items: Vec<Attribute> },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum TypeExprKind {
|
||||
Path(StaticPath),
|
||||
PathParams(StaticPath, Vec<TypeExpr>),
|
||||
Path(Path),
|
||||
PathParams(Path, Vec<TypeExpr>),
|
||||
Tuple(Vec<TypeExpr>),
|
||||
}
|
||||
|
||||
@@ -43,7 +40,7 @@ pub enum TypeExprKind {
|
||||
pub struct TypeExpr(pub TypeExprKind, pub Vec<TypePostfix>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct StaticPath(pub Vec<String>);
|
||||
pub struct Path(pub Vec<String>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum BinaryOp {
|
||||
@@ -65,7 +62,7 @@ pub struct TopLevel(pub TopLevelKind, pub Vec<Attribute>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum TopLevelKind {
|
||||
Include(StaticPath),
|
||||
Include(Path),
|
||||
StructDecl {
|
||||
export: bool,
|
||||
name: String,
|
||||
@@ -156,7 +153,7 @@ pub struct ForStmt {
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum Expression {
|
||||
Literal(Literal),
|
||||
Path(StaticPath),
|
||||
Path(Path),
|
||||
Fix {
|
||||
initial: Box<Expression>,
|
||||
prefixes: Vec<Prefix>,
|
||||
|
||||
+6
-6
@@ -67,7 +67,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for TypeExprKind {
|
||||
match rule {
|
||||
Rule::tuple_type => TypeExprKind::Tuple(inner.map(TypeExpr::from).collect()),
|
||||
Rule::path_type => {
|
||||
let path = StaticPath::from(inner.next().unwrap());
|
||||
let path = Path::from(inner.next().unwrap());
|
||||
let params = inner.map(TypeExpr::from).collect::<Vec<_>>();
|
||||
|
||||
if params.len() == 0 {
|
||||
@@ -81,11 +81,11 @@ impl From<pest::iterators::Pair<'_, Rule>> for TypeExprKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pest::iterators::Pair<'_, Rule>> for StaticPath {
|
||||
impl From<pest::iterators::Pair<'_, Rule>> for Path {
|
||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
||||
match pair.as_rule() {
|
||||
Rule::static_path => {
|
||||
StaticPath(pair.into_inner().map(|i| i.as_str().to_string()).collect())
|
||||
Path(pair.into_inner().map(|i| i.as_str().to_string()).collect())
|
||||
}
|
||||
_ => unimplemented!("{pair:#?}"),
|
||||
}
|
||||
@@ -132,7 +132,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for Attribute {
|
||||
let mut inner = pair.into_inner();
|
||||
|
||||
// first item is always the path
|
||||
let path = StaticPath::from(inner.next().unwrap());
|
||||
let path = Path::from(inner.next().unwrap());
|
||||
|
||||
// check what comes next
|
||||
match inner.next() {
|
||||
@@ -198,7 +198,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for TopLevelKind {
|
||||
let mut inner = pair.into_inner();
|
||||
|
||||
match rule {
|
||||
Rule::import => TopLevelKind::Include(StaticPath::from(inner.next().unwrap())),
|
||||
Rule::import => TopLevelKind::Include(Path::from(inner.next().unwrap())),
|
||||
|
||||
Rule::function_decl => {
|
||||
let export = if let Some(first) = inner.peek() {
|
||||
@@ -378,7 +378,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for Expression {
|
||||
}
|
||||
}
|
||||
Rule::primary => Expression::from(inner.next().unwrap()),
|
||||
Rule::static_path => Expression::Path(StaticPath::from(pair)),
|
||||
Rule::static_path => Expression::Path(Path::from(pair)),
|
||||
Rule::integer => {
|
||||
Expression::Literal(Literal::Int(pair.as_str().parse::<i64>().unwrap()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user