Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Aug 12, 2024
1 parent f41a5b5 commit d9fae92
Show file tree
Hide file tree
Showing 37 changed files with 1,232 additions and 1,086 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nomic:slang@{{ model.slang_version }};
package nomic-foundation:slang@{{ model.slang_version }};

world slang {
export cst;
Expand Down
25 changes: 21 additions & 4 deletions crates/codegen/runtime/cargo/src/runtime/wit/cst.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
use super::{define_rc_wrapper, ffi, rust, FromFFI, IntoFFI};
use crate::wit::{define_rc_wrapper, IntoFFI};

mod ffi {
pub use crate::wit::bindings::exports::nomic_foundation::slang::cst::{
GuestNonterminalNode, GuestTerminalNode, Node, NonterminalNode, NonterminalNodeBorrow,
TerminalNode, TerminalNodeBorrow,
};
pub use crate::wit::bindings::exports::nomic_foundation::slang::kinds::{
NonterminalKind, TerminalKind,
};
pub use crate::wit::bindings::exports::nomic_foundation::slang::text_index::TextIndex;
}

mod rust {
pub use crate::cst::{Node, NonterminalNode, TerminalNode};
pub use crate::text_index::TextIndex;
}

//================================================
//
Expand All @@ -19,9 +35,10 @@ define_rc_wrapper! { NonterminalNode {
todo!()
}

fn create_cursor(&self, text_offset: ffi::TextIndex) -> ffi::Cursor {
std::rc::Rc::clone(self._borrow_ffi()).cursor_with_offset(text_offset._from_ffi())._into_ffi()
}
// TODO: re-enable once we solve circular references:
// fn create_cursor(&self, text_offset: ffi::TextIndex) -> ffi::Cursor {
// std::rc::Rc::clone(self._borrow_ffi()).cursor_with_offset(text_offset._from_ffi())._into_ffi()
// }

fn unparse(&self) -> String {
std::rc::Rc::clone(self._borrow_ffi()).unparse()
Expand Down
27 changes: 20 additions & 7 deletions crates/codegen/runtime/cargo/src/runtime/wit/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
use super::{define_refcell_wrapper, ffi, rust, FromFFI, IntoFFI};
use crate::wit::{define_refcell_wrapper, FromFFI, IntoFFI};

mod ffi {
pub use crate::wit::bindings::exports::nomic_foundation::slang::cursor::{
Cursor, CursorBorrow, EdgeLabel, GuestCursor, Node, NonterminalKind, NonterminalNode,
TerminalKind, TextIndex, TextRange,
};
}

mod rust {
pub use crate::cursor::Cursor;
}

//================================================
//
// resource cursor
Expand Down Expand Up @@ -113,11 +125,12 @@ define_refcell_wrapper! { Cursor {
self._borrow_mut_ffi().go_to_next_nonterminal_with_kinds(&kinds)
}

fn query(&self, queries: Vec<ffi::QueryBorrow<'_>>) -> ffi::QueryMatchIterator {
let queries:Vec<rust::Query> = queries.into_iter().map(|q|{
q._borrow_ffi().clone()
}).collect();
// TODO: re-enable once we solve circular references:
// fn query(&self, queries: Vec<ffi::QueryBorrow<'_>>) -> ffi::QueryMatchIterator {
// let queries:Vec<rust::Query> = queries.into_iter().map(|q|{
// q._borrow_ffi().clone()
// }).collect();

self._borrow_ffi().clone().query(queries)._into_ffi()
}
// self._borrow_ffi().clone().query(queries)._into_ffi()
// }
} }
10 changes: 9 additions & 1 deletion crates/codegen/runtime/cargo/src/runtime/wit/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
use super::{enum_to_enum, ffi, rust};
use crate::wit::enum_to_enum;

mod ffi {
pub use crate::wit::bindings::exports::nomic_foundation::slang::diagnostic::Severity;
}

mod rust {
pub use crate::diagnostic::Severity;
}

//================================================
//
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion crates/codegen/runtime/cargo/src/runtime/wit/kinds.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
use super::{enum_to_enum, ffi, rust};
use crate::wit::enum_to_enum;

mod ffi {
pub use crate::wit::bindings::exports::nomic_foundation::slang::kinds::{
EdgeLabel, NonterminalKind, TerminalKind,
};
}

mod rust {
pub use crate::kinds::{EdgeLabel, NonterminalKind, TerminalKind};
}

//================================================
//
Expand Down
14 changes: 11 additions & 3 deletions crates/codegen/runtime/cargo/src/runtime/wit/language.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
use rust::Diagnostic as _;
use crate::wit::{define_wrapper, FromFFI, IntoFFI};

use super::{define_wrapper, ffi, rust, FromFFI, IntoFFI};
mod ffi {
pub use crate::wit::bindings::exports::nomic_foundation::slang::language::{
GuestLanguage, Language, LanguageBorrow, NonterminalKind,
};
pub use crate::wit::bindings::exports::nomic_foundation::slang::parse_output::ParseOutput;
}

mod rust {
pub use crate::language::Language;
}

//================================================
//
Expand Down Expand Up @@ -31,4 +40,3 @@ define_wrapper! { Language {
self._borrow_ffi().parse(kind._from_ffi(), &input)._into_ffi()
}
} }

44 changes: 1 addition & 43 deletions crates/codegen/runtime/cargo/src/runtime/wit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod text_index;
clippy::cast_ptr_alignment,
clippy::cast_sign_loss,
clippy::cast_lossless,
clippy::items_after_statements,
clippy::match_bool,
clippy::ptr_as_ptr,
clippy::single_match_else,
Expand All @@ -26,29 +27,6 @@ pub mod text_index;
#[path = "generated/generated/bindings.rs"]
mod bindings;

pub mod ffi {
pub use crate::wit::bindings::exports::nomic::slang::parser::{
Cursor, CursorBorrow, EdgeLabel, Guest, GuestCursor, GuestLanguage, GuestNonterminalNode,
GuestParseError, GuestParseOutput, GuestQuery, GuestQueryMatchIterator, GuestTerminalNode,
Language, LanguageBorrow, Node, NonterminalKind, NonterminalNode, NonterminalNodeBorrow,
ParseError, ParseErrorBorrow, ParseOutput, ParseOutputBorrow, Query, QueryBorrow,
QueryError, QueryMatch, QueryMatchIterator, QueryMatchIteratorBorrow, Severity,
TerminalKind, TerminalNode, TerminalNodeBorrow, TextIndex, TextRange,
};
}

pub mod rust {
pub use crate::cst::{Edge, Node, NonterminalNode, TerminalNode};
pub use crate::cursor::Cursor;
pub use crate::diagnostic::{Diagnostic, Severity};
pub use crate::kinds::{EdgeLabel, NonterminalKind, TerminalKind};
pub use crate::language::Language;
pub use crate::parse_error::ParseError;
pub use crate::parse_output::ParseOutput;
pub use crate::query::{Query, QueryError, QueryMatch, QueryMatchIterator};
pub use crate::text_index::{TextIndex, TextRange};
}

trait IntoFFI<F> {
fn _into_ffi(self) -> F;
}
Expand Down Expand Up @@ -236,23 +214,3 @@ macro_rules! enum_to_enum {

// The trick: https://stackoverflow.com/questions/26731243/how-do-i-use-a-macro-across-module-files
pub(crate) use {define_rc_wrapper, define_refcell_wrapper, define_wrapper, enum_to_enum};

#[allow(clippy::upper_case_acronyms)]
pub struct API;

//================================================
//
// interface language
//
//================================================

impl ffi::Guest for API {
type Language = language::LanguageWrapper;
type ParseError = language::ParseErrorWrapper;
type ParseOutput = language::ParseOutputWrapper;
type NonterminalNode = cst::NonterminalNodeWrapper;
type TerminalNode = cst::TerminalNodeWrapper;
type Cursor = cursor::CursorWrapper;
type Query = query::QueryWrapper;
type QueryMatchIterator = query::QueryMatchIteratorWrapper;
}
16 changes: 14 additions & 2 deletions crates/codegen/runtime/cargo/src/runtime/wit/parse_error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
use rust::Diagnostic as _;
use crate::diagnostic::Diagnostic;
use crate::wit::{define_wrapper, IntoFFI};

use super::{define_wrapper, ffi, rust, FromFFI, IntoFFI};
mod ffi {
pub use crate::wit::bindings::exports::nomic_foundation::slang::diagnostic::Severity;
pub use crate::wit::bindings::exports::nomic_foundation::slang::parse_error::GuestParseError;
pub use crate::wit::bindings::exports::nomic_foundation::slang::parse_output::{
ParseError, ParseErrorBorrow,
};
pub use crate::wit::bindings::exports::nomic_foundation::slang::text_index::TextRange;
}

mod rust {
pub use crate::parse_error::ParseError;
}

//================================================
//
Expand Down
15 changes: 13 additions & 2 deletions crates/codegen/runtime/cargo/src/runtime/wit/parse_output.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
use rust::Diagnostic as _;
use crate::wit::{define_wrapper, IntoFFI};

use super::{define_wrapper, ffi, rust, FromFFI, IntoFFI};
mod ffi {
pub use crate::wit::bindings::exports::nomic_foundation::slang::cst::Node;
pub use crate::wit::bindings::exports::nomic_foundation::slang::cursor::Cursor;
pub use crate::wit::bindings::exports::nomic_foundation::slang::parse_error::ParseError;
pub use crate::wit::bindings::exports::nomic_foundation::slang::parse_output::{
GuestParseOutput, ParseOutput, ParseOutputBorrow,
};
}

mod rust {
pub use crate::parse_output::ParseOutput;
}

//================================================
//
Expand Down
13 changes: 12 additions & 1 deletion crates/codegen/runtime/cargo/src/runtime/wit/query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
use super::{define_refcell_wrapper, define_wrapper, ffi, rust, IntoFFI};
use crate::wit::{define_refcell_wrapper, define_wrapper, IntoFFI};

mod ffi {
pub use crate::wit::bindings::exports::nomic_foundation::slang::query::{
GuestQuery, GuestQueryMatchIterator, Query, QueryBorrow, QueryError, QueryMatch,
QueryMatchIterator, QueryMatchIteratorBorrow,
};
}

mod rust {
pub use crate::query::{Query, QueryError, QueryMatch, QueryMatchIterator};
}

//================================================
//
Expand Down
12 changes: 11 additions & 1 deletion crates/codegen/runtime/cargo/src/runtime/wit/text_index.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
use super::{ffi, rust, FromFFI, IntoFFI};
use crate::wit::{FromFFI, IntoFFI};

mod ffi {
pub use crate::wit::bindings::exports::nomic_foundation::slang::text_index::{
TextIndex, TextRange,
};
}

mod rust {
pub use crate::text_index::{TextIndex, TextRange};
}

//================================================
//
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d9fae92

Please sign in to comment.