Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeQL 3.0 #342

Merged
merged 62 commits into from
Jul 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
061db6a
rough undefine
dmitrii-ubskii Jun 14, 2024
6954e3a
clean up type decl module structure + fmt
dmitrii-ubskii Jun 14, 2024
ae222ca
uncomment undifine tests
dmitrii-ubskii Jun 14, 2024
63c0c61
extract schame query tests
dmitrii-ubskii Jun 14, 2024
decfa25
fix function return type parsing order
dmitrii-ubskii Jun 17, 2024
a9f00c3
higher quality generation
dmitrii-ubskii Jun 17, 2024
722801f
disambiguate PEG
dmitrii-ubskii Jun 17, 2024
f5ddb3d
visit_eof_queries
dmitrii-ubskii Jun 17, 2024
5fc6e76
future proof (Iterator::intersperse in future release)
dmitrii-ubskii Jun 17, 2024
b027d39
extract schema visitors + data stub
dmitrii-ubskii Jun 17, 2024
183f61a
relates_annos
dmitrii-ubskii Jun 17, 2024
f130050
extract data query parser mod
dmitrii-ubskii Jun 17, 2024
3a853b8
refactor and repackage modules
dmitrii-ubskii Jun 17, 2024
ec53865
statement_is + VAR
dmitrii-ubskii Jun 17, 2024
b56e8b7
(most of) expression parsing + misc cleanup
dmitrii-ubskii Jun 18, 2024
1ea021d
rest of single statements
dmitrii-ubskii Jun 18, 2024
58d53c6
expression list
dmitrii-ubskii Jun 19, 2024
65ecff0
more statements (venturing into things)
dmitrii-ubskii Jun 19, 2024
7db4364
rest of thing statements + insert & delete
dmitrii-ubskii Jun 20, 2024
fda2fb3
type statement
dmitrii-ubskii Jun 20, 2024
04f6691
lowercase non-literal rules
dmitrii-ubskii Jun 20, 2024
a71d320
stage_put
dmitrii-ubskii Jun 20, 2024
97e4429
restore top-level parsers
dmitrii-ubskii Jun 20, 2024
61a1a61
fix put
dmitrii-ubskii Jun 20, 2024
eebcf5f
stage reduce + modifier
dmitrii-ubskii Jun 21, 2024
0ae752b
restore old match tests
dmitrii-ubskii Jun 21, 2024
b0e89b0
restructure + fndefs
dmitrii-ubskii Jun 25, 2024
b3aa7f5
fetch
dmitrii-ubskii Jun 25, 2024
5420788
undefine, redefine WIP
dmitrii-ubskii Jun 27, 2024
e6223eb
Freeze grammar, parse define
dmitrii-ubskii Jul 1, 2024
44a1438
split parser/schema into define & undefine
dmitrii-ubskii Jul 1, 2024
e8a54a2
type_::{List, Optional}
dmitrii-ubskii Jul 1, 2024
6e3ccbd
undefine
dmitrii-ubskii Jul 1, 2024
9ddd409
redefine + subkey
dmitrii-ubskii Jul 1, 2024
50afb2e
restore data queries + function def
dmitrii-ubskii Jul 1, 2024
cb834c0
update
dmitrii-ubskii Jul 1, 2024
a43f317
schema test: parsing & formatting (no builders yet)
dmitrii-ubskii Jul 1, 2024
8251e1a
match query tests
dmitrii-ubskii Jul 2, 2024
02c8233
rest of handwritten test + refactor
dmitrii-ubskii Jul 2, 2024
5b52a34
more test refactoring
dmitrii-ubskii Jul 3, 2024
4c06b91
merged dependencies
dmitrii-ubskii Jul 4, 2024
ac4f885
refactor + WIP for HIR
dmitrii-ubskii Jul 5, 2024
d9db7d5
rename type_::TypeConstraintBase => type_::ConstraintBase
dmitrii-ubskii Jul 8, 2024
3e7dab5
reintroduce enum_getter!
dmitrii-ubskii Jul 8, 2024
496162a
remove temp allowances in crate root
dmitrii-ubskii Jul 8, 2024
bd935f1
cleanup eof_FOO rules (query, label, fun, and struct only)
dmitrii-ubskii Jul 8, 2024
4eeca3d
Result in parse_string
dmitrii-ubskii Jul 8, 2024
612215b
unmerge label, identifer, variable
dmitrii-ubskii Jul 8, 2024
26459bd
dissolve reduce_limited + fmt
dmitrii-ubskii Jul 8, 2024
3c19088
reduce_all => reduce_value
dmitrii-ubskii Jul 8, 2024
19019bd
statement_anon_relation => statement_relation_anonymous
dmitrii-ubskii Jul 8, 2024
b0c71f7
Make HAS and LINKS optional in delete
dmitrii-ubskii Jul 8, 2024
1357427
unreserve CHECK & FIRST
dmitrii-ubskii Jul 8, 2024
e2d09b5
annotation_kind => annotation_category
dmitrii-ubskii Jul 8, 2024
9241a06
query_stage_final => query_stage_terminal
dmitrii-ubskii Jul 8, 2024
c0734d2
(query_)data => pipeline
dmitrii-ubskii Jul 8, 2024
10d61fb
make stage available at query::stage
dmitrii-ubskii Jul 8, 2024
316947c
value category => value tag
dmitrii-ubskii Jul 8, 2024
f6f2ed9
fix list range syntax (a:b => a..b)
dmitrii-ubskii Jul 8, 2024
bfe1b1e
fill in expr formatting
dmitrii-ubskii Jul 8, 2024
08ec0d9
maven update
dmitrii-ubskii Jul 8, 2024
3fca1d1
checkstyle + fmt
dmitrii-ubskii Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor and repackage modules
dmitrii-ubskii committed Jun 17, 2024
commit 3a853b8ff2c95f0556730f029d2511e1676c2b1e
File renamed without changes.
File renamed without changes.
File renamed without changes.
126 changes: 120 additions & 6 deletions rust/parser/data.rs
Original file line number Diff line number Diff line change
@@ -4,13 +4,127 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

use super::{Node, Rule};
use crate::{parser::IntoChildNodes, query::DataQuery};
use super::{statement::visit_statement, IntoChildNodes, Node, Rule};
use crate::{
common::{error::TypeQLError, Spanned},
parser::{statement::visit_statement_things, RuleMatcher},
pattern::{Conjunction, Disjunction, Negation, Pattern, Statement, Try},
query::{
data::stage::{Insert, Match, Stage},
DataQuery,
},
};

pub(super) fn visit_query_data(node: Node<'_>) -> DataQuery {
debug_assert_eq!(node.as_rule(), Rule::query_data);
node.into_children().fold(DataQuery::new(), |_query, stage| {
debug_assert_eq!(stage.as_rule(), Rule::query_stage);
todo!()
})
let span = node.span();
node.into_children().fold(DataQuery::new(span), |query, stage| query.then(visit_query_stage(stage)))
}

fn visit_query_stage(node: Node<'_>) -> Stage {
debug_assert_eq!(node.as_rule(), Rule::query_stage);
let span = node.span();
let child = node.into_child();
match child.as_rule() {
Rule::stage_match => Stage::Match(visit_stage_match(child)),
Rule::stage_insert => Stage::Insert(visit_stage_insert(child)),
Rule::stage_delete => visit_stage_delete(child),
Rule::stage_put => visit_stage_put(child),
Rule::stage_fetch => visit_stage_fetch(child),
Rule::stage_reduce => visit_stage_reduce(child),
Rule::stage_modifier => visit_stage_modifier(child),
_ => unreachable!("{}", TypeQLError::IllegalGrammar { input: child.to_string() }),
}
}

fn visit_stage_match(node: Node<'_>) -> Match {
debug_assert_eq!(node.as_rule(), Rule::stage_match);
let span = node.span();
let mut children = node.into_children();
let patterns = children.skip_expected(Rule::MATCH).consume_expected(Rule::patterns);
Match::new(span, visit_patterns(patterns))
}

fn visit_patterns(node: Node<'_>) -> Vec<Pattern> {
debug_assert_eq!(node.as_rule(), Rule::patterns);
node.into_children().map(visit_pattern).collect()
}

fn visit_pattern(node: Node<'_>) -> Pattern {
debug_assert_eq!(node.as_rule(), Rule::pattern);
let child = node.into_child();
match child.as_rule() {
Rule::pattern_conjunction => Pattern::Conjunction(visit_pattern_conjunction(child)),
Rule::pattern_disjunction => Pattern::Disjunction(visit_pattern_disjunction(child)),
Rule::pattern_negation => Pattern::Negation(visit_pattern_negation(child)),
Rule::pattern_try => Pattern::Try(visit_pattern_try(child)),
Rule::statement => Pattern::Statement(visit_statement(child)),
_ => unreachable!("{}", TypeQLError::IllegalGrammar { input: child.to_string() }),
}
}

fn visit_pattern_conjunction(node: Node<'_>) -> Conjunction {
debug_assert_eq!(node.as_rule(), Rule::pattern_conjunction);
let span = node.span();
Conjunction::new(span, visit_patterns(node.into_child()))
}

fn visit_pattern_disjunction(node: Node<'_>) -> Disjunction {
debug_assert_eq!(node.as_rule(), Rule::pattern_disjunction);
let span = node.span();
let mut branches = Vec::new();
let mut children = node.into_children();
while let Some(branch) = children.try_consume_expected(Rule::patterns) {
branches.push(visit_patterns(branch));
children.try_consume_expected(Rule::OR);
}
debug_assert!(children.try_consume_any().is_none());
Disjunction::new(span, branches)
}

fn visit_pattern_negation(node: Node<'_>) -> Negation {
debug_assert_eq!(node.as_rule(), Rule::pattern_negation);
let span = node.span();
let mut children = node.into_children();
let patterns = children.skip_expected(Rule::NOT).consume_expected(Rule::patterns);
debug_assert!(children.try_consume_any().is_none());
Negation::new(span, visit_patterns(patterns))
}

fn visit_pattern_try(node: Node<'_>) -> Try {
debug_assert_eq!(node.as_rule(), Rule::pattern_try);
let span = node.span();
let mut children = node.into_children();
let patterns = children.skip_expected(Rule::TRY).consume_expected(Rule::patterns);
debug_assert!(children.try_consume_any().is_none());
Try::new(span, visit_patterns(patterns))
}

fn visit_stage_insert(node: Node<'_>) -> Insert {
debug_assert_eq!(node.as_rule(), Rule::stage_insert);
let span = node.span();
let mut children = node.into_children();
let statement_things = children.skip_expected(Rule::INSERT).consume_expected(Rule::statement_things);
// StageInsert::new(span, visit_statement_things(statements))
todo!()
}

fn visit_stage_delete(node: Node<'_>) -> Stage {
todo!()
}

fn visit_stage_put(node: Node<'_>) -> Stage {
todo!()
}

fn visit_stage_fetch(node: Node<'_>) -> Stage {
todo!()
}

fn visit_stage_reduce(node: Node<'_>) -> Stage {
todo!()
}

fn visit_stage_modifier(node: Node<'_>) -> Stage {
todo!()
}
9 changes: 5 additions & 4 deletions rust/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ use crate::{

mod data;
mod schema;
mod statement;

#[cfg(test)]
mod test;
@@ -42,18 +43,18 @@ impl Spanned for Node<'_> {
}

trait IntoChildNodes<'a> {
fn into_child(self) -> Result<Node<'a>>;
fn into_child(self) -> Node<'a>;
fn into_children(self) -> ChildNodes<'a>;
}

impl<'a> IntoChildNodes<'a> for Node<'a> {
fn into_child(self) -> Result<Node<'a>> {
fn into_child(self) -> Node<'a> {
let mut children = self.into_children();
let child = children.consume_any();
match children.try_consume_any() {
None => Ok(child),
None => child,
Some(next) => {
Err(TypeQLError::IllegalGrammar { input: format!("{child} is followed by more tokens: {next}") }.into())
unreachable!("{child} is followed by more tokens: {next}")
}
}
}
9 changes: 5 additions & 4 deletions rust/parser/schema.rs
Original file line number Diff line number Diff line change
@@ -7,13 +7,14 @@
use super::{visit_label, IntoChildNodes, Node, Rule, RuleMatcher};
use crate::{
common::{error::TypeQLError, Spanned},
pattern::{
definition::type_::declaration::{
definition::type_::{
declaration::{
AnnotationOwns, AnnotationRelates, AnnotationSub, AnnotationValueType, Owned, Owns, Played, Plays, Related,
Relates, Sub, ValueType,
},
Definable, Label, Type,
Type,
},
pattern::{Definable, Label},
query::{SchemaQuery, TypeQLDefine, TypeQLUndefine},
};

@@ -75,7 +76,7 @@ fn visit_definition_type(node: Node<'_>) -> Type {
let mut children = node.into_children();
let label = visit_label(children.consume_expected(Rule::label));
children.fold(Type::new(label, span), |type_declaration, constraint| {
let constraint = constraint.into_child().unwrap();
let constraint = constraint.into_child();
match constraint.as_rule() {
Rule::sub_declaration => type_declaration.set_sub(visit_sub_declaration(constraint)),
Rule::value_type_declaration => type_declaration.set_value_type(visit_value_type_declaration(constraint)),
21 changes: 21 additions & 0 deletions rust/parser/statement.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

use super::{IntoChildNodes, Node, Rule};
use crate::{
common::{error::TypeQLError, Spanned},
parser::RuleMatcher,
pattern::{Conjunction, Disjunction, Negation, Pattern, Statement, Try},
query::DataQuery,
};

pub(super) fn visit_statement(node: Node<'_>) -> Statement {
Statement
}

pub(super) fn visit_statement_things(_node: Node<'_>) {
todo!()
}
65 changes: 62 additions & 3 deletions rust/pattern/mod.rs
Original file line number Diff line number Diff line change
@@ -6,10 +6,9 @@

use std::fmt;

pub use self::{definition::Type, label::Label};
use crate::{enum_getter, enum_wrapper};
pub use self::label::Label;
use crate::{common::Span, definition::Type, enum_getter, enum_wrapper};

pub(crate) mod definition;
pub mod label;

#[derive(Debug, Clone, Eq, PartialEq)]
@@ -32,3 +31,63 @@ impl fmt::Display for Definable {
}
}
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Conjunction {
span: Option<Span>,
patterns: Vec<Pattern>,
}

impl Conjunction {
pub(crate) fn new(span: Option<Span>, patterns: Vec<Pattern>) -> Self {
Self { span, patterns }
}
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Negation {
span: Option<Span>,
patterns: Vec<Pattern>,
}

impl Negation {
pub(crate) fn new(span: Option<Span>, patterns: Vec<Pattern>) -> Self {
Self { span, patterns }
}
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Try {
span: Option<Span>,
patterns: Vec<Pattern>,
}

impl Try {
pub(crate) fn new(span: Option<Span>, patterns: Vec<Pattern>) -> Self {
Self { span, patterns }
}
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Disjunction {
span: Option<Span>,
branches: Vec<Vec<Pattern>>,
}

impl Disjunction {
pub(crate) fn new(span: Option<Span>, branches: Vec<Vec<Pattern>>) -> Self {
Self { span, branches }
}
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Statement;

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Pattern {
Conjunction(Conjunction),
Disjunction(Disjunction),
Negation(Negation),
Try(Try),
Statement(Statement),
}
49 changes: 49 additions & 0 deletions rust/query/data/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

use std::fmt;

use crate::{
common::{Span, Spanned},
pattern::Pattern,
};

use self::stage::Stage;

pub mod stage;

#[derive(Debug, Eq, PartialEq)]
pub struct DataQuery {
span: Option<Span>,
stages: Vec<Stage>,
}

impl DataQuery {
pub(crate) fn new(span: Option<Span>) -> Self {
Self { span, stages: Vec::new() }
}

pub fn build() -> Self {
Self::new(None)
}

pub fn then(mut self, stage: Stage) -> Self {
self.stages.push(stage);
self
}
}

impl Spanned for DataQuery {
fn span(&self) -> Option<Span> {
todo!()
}
}

impl fmt::Display for DataQuery {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
todo!()
}
}
22 changes: 22 additions & 0 deletions rust/query/data/stage/insert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

use crate::{
common::{Span, Spanned},
pattern::Pattern,
};

#[derive(Debug, Eq, PartialEq)]
pub struct Insert {
span: Option<Span>,
patterns: Vec<Pattern>,
}

impl Insert {
pub(crate) fn new(span: Option<Span>, patterns: Vec<Pattern>) -> Self {
Self { span, patterns }
}
}
23 changes: 23 additions & 0 deletions rust/query/data/stage/match_.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

use crate::{
common::{Span, Spanned},
pattern::Pattern,
};

#[derive(Debug, Eq, PartialEq)]
pub struct Match {
span: Option<Span>,
patterns: Vec<Pattern>,
}

impl Match {
pub(crate) fn new(span: Option<Span>, patterns: Vec<Pattern>) -> Self {
Self { span, patterns }
}
}

Loading