Importing
This commit is contained in:
+1
-1
@@ -47,7 +47,7 @@ pub enum BinaryOp {
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum TopLevel {
|
||||
Import(String),
|
||||
Include(StaticPath),
|
||||
StructDecl {
|
||||
export: bool,
|
||||
name: String,
|
||||
|
||||
@@ -12,15 +12,16 @@ string_lit = { "\"" ~ inner_str ~ "\"" }
|
||||
inner_str = @{ (!"\"" ~ ANY)* }
|
||||
static_path = { identifier ~ ("::" ~ identifier)* }
|
||||
|
||||
export = { "public" }
|
||||
mutable = { "mut" }
|
||||
var_decl = { type_expr ~ mutable? ~ identifier }
|
||||
export = { "public" }
|
||||
mutable = { "mut" }
|
||||
sharp = _{ "#" }
|
||||
var_decl = { type_expr ~ mutable? ~ identifier }
|
||||
|
||||
// ================= TOP LEVEL =================
|
||||
|
||||
top_level = _{ import | function_decl | struct_decl }
|
||||
|
||||
import = { "import" ~ string_lit ~ ";" }
|
||||
import = { sharp ~ "include" ~ "<" ~ static_path ~ ">" }
|
||||
|
||||
field_list = { field ~ ("," ~ field)* ~ ","? }
|
||||
field = { export? ~ type_expr ~ identifier }
|
||||
|
||||
+4
-4
@@ -123,10 +123,10 @@ impl TryFrom<pest::iterators::Pair<'_, Rule>> for TopLevel {
|
||||
type Error = ();
|
||||
fn try_from(pair: pest::iterators::Pair<Rule>) -> Result<Self, ()> {
|
||||
match pair.as_rule() {
|
||||
Rule::import => {
|
||||
let path = pair.into_inner().next().unwrap().as_str().to_string();
|
||||
Ok(TopLevel::Import(path))
|
||||
}
|
||||
Rule::import => Ok(TopLevel::Include(StaticPath::from(
|
||||
pair.into_inner().next().unwrap(),
|
||||
))),
|
||||
|
||||
Rule::function_decl => {
|
||||
let mut inner = pair.into_inner();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user