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