Importing

This commit is contained in:
2026-05-04 19:29:10 +02:00
parent 544074c26e
commit c717a57f99
4 changed files with 12 additions and 12 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ pub enum BinaryOp {
#[derive(Debug, Clone, Serialize)]
pub enum TopLevel {
Import(String),
Include(StaticPath),
StructDecl {
export: bool,
name: String,
+5 -4
View File
@@ -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
View File
@@ -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();
+2 -3
View File
@@ -195,9 +195,8 @@ impl ToRust for Block {
impl ToRust for TopLevel {
fn to_rust(&self, cg: &mut RustCodegen) {
match self {
TopLevel::Import(path) => {
let path = path.replace('"', "");
cg.addln(&format!("use {};", path));
TopLevel::Include(path) => {
cg.addln(&format!("use {};", path.get_rust()));
}
TopLevel::StructDecl {