Skip to content

Commit

Permalink
feat(Graph relations): Add Declare relation
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Jan 26, 2022
1 parent 9794a54 commit 472ccdb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions rust/graph-triples/src/directions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn direction(relation: &Relation) -> Direction {
Relation::Assign(..) => Direction::To,
Relation::Alter(..) => Direction::To,
Relation::Convert(..) => Direction::To,
Relation::Declare(..) => Direction::To,
Relation::Embed => Direction::From,
Relation::Import(..) => Direction::From,
Relation::Include => Direction::From,
Expand Down
20 changes: 19 additions & 1 deletion rust/graph-triples/src/relations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum Relation {
Assign(Assign),
Alter(Alter),
Convert(Convert),
Declare(Declare),
Embed,
Import(Import),
Include,
Expand All @@ -30,7 +31,24 @@ pub type Range = (usize, usize, usize, usize);
/// in the `subject` the relation is defined.
pub const NULL_RANGE: Range = (0, 0, 0, 0);

/// Assigns a symbol
/// Declares a symbol
///
/// For some languages, variable declaration is distinct to assignment
/// (e.g. `let` in JavaScript). This relation allows for those to be
/// distinguished.
#[derive(Debug, Clone, JsonSchema, Serialize)]
#[schemars(deny_unknown_fields)]
pub struct Declare {
/// The range within code that the assignment is done
pub range: Range,
}

/// Create a new `Declare` relation
pub fn declares(range: Range) -> Relation {
Relation::Declare(Declare { range })
}

/// Assigns to a symbol
#[derive(Debug, Clone, JsonSchema, Serialize)]
#[schemars(deny_unknown_fields)]
pub struct Assign {
Expand Down

0 comments on commit 472ccdb

Please sign in to comment.