Implementing static path
This commit is contained in:
@@ -16,6 +16,9 @@ pub enum TypeExpr {
|
|||||||
Identifier(String),
|
Identifier(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct StaticPath(pub Vec<String>);
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub enum BinaryOp {
|
pub enum BinaryOp {
|
||||||
Plus,
|
Plus,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ float = @{ ASCII_DIGIT+ ~ "." ~ ASCII_DIGIT+ }
|
|||||||
boolean = { "true" | "false" }
|
boolean = { "true" | "false" }
|
||||||
string_lit = { "\"" ~ inner_str ~ "\"" }
|
string_lit = { "\"" ~ inner_str ~ "\"" }
|
||||||
inner_str = @{ (!"\"" ~ ANY)* }
|
inner_str = @{ (!"\"" ~ ANY)* }
|
||||||
|
static_path = { identifier ~ ("::" ~ identifier)* }
|
||||||
|
|
||||||
export = { "public" }
|
export = { "public" }
|
||||||
mutable = { "mut" }
|
mutable = { "mut" }
|
||||||
@@ -72,14 +73,14 @@ while_stmt = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ================= EXPRESSIONS =================
|
// ================= EXPRESSIONS =================
|
||||||
type_expr = { identifier }
|
type_expr = { static_path }
|
||||||
|
|
||||||
primary = {
|
primary = {
|
||||||
integer
|
integer
|
||||||
| float
|
| float
|
||||||
| boolean
|
| boolean
|
||||||
| string_lit
|
| string_lit
|
||||||
| identifier
|
| static_path
|
||||||
}
|
}
|
||||||
|
|
||||||
postfix = {
|
postfix = {
|
||||||
|
|||||||
@@ -45,6 +45,23 @@ impl TryFrom<pest::iterators::Pair<'_, Rule>> for TypeExpr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<pest::iterators::Pair<'_, Rule>> for StaticPath {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn try_from(pair: pest::iterators::Pair<'_, Rule>) -> Result<Self, Self::Error> {
|
||||||
|
if pair.as_str() == "void" {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(match pair.as_rule() {
|
||||||
|
Rule::static_path => {
|
||||||
|
StaticPath(pair.into_inner().map(|i| i.as_str().to_string()).collect())
|
||||||
|
}
|
||||||
|
_ => unimplemented!("{pair:#?}"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<pest::iterators::Pair<'_, Rule>> for FieldList {
|
impl From<pest::iterators::Pair<'_, Rule>> for FieldList {
|
||||||
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
|
fn from(pair: pest::iterators::Pair<Rule>) -> Self {
|
||||||
let params = pair
|
let params = pair
|
||||||
|
|||||||
+1
-3
@@ -1,3 +1 @@
|
|||||||
int test(int mut b) {
|
int test() {}
|
||||||
int mut a = 10;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user