Skip to content

Commit

Permalink
located parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
timbod7 committed Aug 14, 2022
1 parent 40e6c99 commit aa5720c
Show file tree
Hide file tree
Showing 7 changed files with 496 additions and 375 deletions.
21 changes: 16 additions & 5 deletions adl/stdlib/sys/adlast2.adl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ struct TypeExpr<R>

struct Field<TE>
{
Ident name;
Spanned<Ident> name;
Ident serializedName;
TE typeExpr;
Maybe<Json> default;
Maybe<Spanned<Json>> default;
Annotations annotations;
};

Expand Down Expand Up @@ -73,7 +73,7 @@ union DeclType<TE>

struct Decl<TE>
{
Ident name;
Spanned<Ident> name;
Maybe<Word32> version;
DeclType<TE> type_;
Annotations annotations;
Expand All @@ -95,10 +95,21 @@ union Import

struct Module<TE>
{
ModuleName name;
Spanned<ModuleName> name;
Vector<Import> imports;
StringMap<Decl<TE>> decls;
Annotations annotations;
};

};
/// The Span start..end contains all values with start <= x < end. It is empty if start >= end.
struct Span {
Word64 start;
Word64 end;
};

struct Spanned<T> {
T value;
Span span;
};

};
4 changes: 2 additions & 2 deletions haskell/tools/scratch-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ run_tests() {
(cd ../cpp/tests; ./run-tests.sh)
}

build_adlc
# build_adlc
build_runtimes
run_tests
# run_tests
18 changes: 18 additions & 0 deletions rust/compiler/Cargo.lock

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

1 change: 1 addition & 0 deletions rust/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ edition = "2021"
serde = { version = "1.0.130", features=["derive"] }
serde_json = "1.0.68"
nom = "7.0.0"
nom_locate = "4.0.0"
49 changes: 42 additions & 7 deletions rust/compiler/src/adlgen/sys/adlast2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ impl<R> TypeExpr<R> {

#[derive(Debug,Deserialize,PartialEq,Serialize)]
pub struct Field<TE> {
pub name: Ident,
pub name: Spanned<Ident>,

#[serde(rename="serializedName")]
pub serialized_name: Ident,

#[serde(rename="typeExpr")]
pub type_expr: TE,

pub default: Maybe<serde_json::Value>,
pub default: Maybe<Spanned<serde_json::Value>>,

pub annotations: Annotations,
}

impl<TE> Field<TE> {
pub fn new(name: Ident, serialized_name: Ident, type_expr: TE, default: Maybe<serde_json::Value>, annotations: Annotations) -> Field<TE> {
pub fn new(name: Spanned<Ident>, serialized_name: Ident, type_expr: TE, default: Maybe<Spanned<serde_json::Value>>, annotations: Annotations) -> Field<TE> {
Field {
name: name,
serialized_name: serialized_name,
Expand Down Expand Up @@ -174,7 +174,7 @@ pub enum DeclType<TE> {

#[derive(Debug,Deserialize,PartialEq,Serialize)]
pub struct Decl<TE> {
pub name: Ident,
pub name: Spanned<Ident>,

pub version: Maybe<u32>,

Expand All @@ -185,7 +185,7 @@ pub struct Decl<TE> {
}

impl<TE> Decl<TE> {
pub fn new(name: Ident, version: Maybe<u32>, r#type: DeclType<TE>, annotations: Annotations) -> Decl<TE> {
pub fn new(name: Spanned<Ident>, version: Maybe<u32>, r#type: DeclType<TE>, annotations: Annotations) -> Decl<TE> {
Decl {
name: name,
version: version,
Expand Down Expand Up @@ -225,7 +225,7 @@ pub enum Import {

#[derive(Debug,Deserialize,PartialEq,Serialize)]
pub struct Module<TE> {
pub name: ModuleName,
pub name: Spanned<ModuleName>,

pub imports: Vec<Import>,

Expand All @@ -235,7 +235,7 @@ pub struct Module<TE> {
}

impl<TE> Module<TE> {
pub fn new(name: ModuleName, imports: Vec<Import>, decls: std::collections::HashMap<String,Decl<TE>>, annotations: Annotations) -> Module<TE> {
pub fn new(name: Spanned<ModuleName>, imports: Vec<Import>, decls: std::collections::HashMap<String,Decl<TE>>, annotations: Annotations) -> Module<TE> {
Module {
name: name,
imports: imports,
Expand All @@ -244,3 +244,38 @@ impl<TE> Module<TE> {
}
}
}

/**
* The Span start..end contains all values with start <= x < end. It is empty if start >= end.
*/
#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub struct Span {
pub start: u64,

pub end: u64,
}

impl Span {
pub fn new(start: u64, end: u64) -> Span {
Span {
start: start,
end: end,
}
}
}

#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub struct Spanned<T> {
pub value: T,

pub span: Span,
}

impl<T> Spanned<T> {
pub fn new(value: T, span: Span) -> Spanned<T> {
Spanned {
value: value,
span: span,
}
}
}
Loading

0 comments on commit aa5720c

Please sign in to comment.