Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 14 additions & 3 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
# Generated by TypeDB Cargo sync tool.
# Do not modify this file.

features = {}

[package]
name = "typeql"
edition = "2021"
version = "0.0.0"

[features]
default = ["quine"]
quine = ["dep:polyquine", "dep:proc-macro2", "dep:quote"]


[lib]
path = "typeql.rs"

Expand All @@ -35,6 +38,15 @@ features = {}
default-features = false

[dependencies]
quote = { version = "1.0.40", default-features = false, optional = true }
[dependencies.proc-macro2]
version = "1.0.94"
default-features = false
optional = true

[dependencies.polyquine]
version = "0.0.3"
optional = true

[dependencies.pest]
features = ["default", "memchr", "std"]
Expand Down Expand Up @@ -68,4 +80,3 @@ features = {}
[[test]]
path = "tests/behaviour/test_debug.rs"
name = "test_debug"

16 changes: 16 additions & 0 deletions rust/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@

use std::fmt::{self, Write};

#[cfg(feature = "quine")]
use {polyquine::Quine, proc_macro2::TokenStream};

use crate::{
common::{identifier::Identifier, token, Span, Spanned},
util::write_joined,
value::{IntegerLiteral, Literal, StringLiteral},
};

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub enum Annotation {
Abstract(Abstract),
Cardinality(Cardinality),
Expand Down Expand Up @@ -64,6 +68,7 @@ impl fmt::Display for Annotation {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Abstract {
pub span: Option<Span>,
}
Expand All @@ -87,6 +92,7 @@ impl fmt::Display for Abstract {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Cardinality {
pub span: Option<Span>,
pub range: CardinalityRange,
Expand All @@ -111,6 +117,7 @@ impl fmt::Display for Cardinality {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub enum CardinalityRange {
Exact(IntegerLiteral),
Range(IntegerLiteral, Option<IntegerLiteral>),
Expand All @@ -127,6 +134,7 @@ impl fmt::Display for CardinalityRange {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Cascade {
pub span: Option<Span>,
}
Expand All @@ -150,6 +158,7 @@ impl fmt::Display for Cascade {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Distinct {
pub span: Option<Span>,
}
Expand All @@ -173,6 +182,7 @@ impl fmt::Display for Distinct {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Independent {
pub span: Option<Span>,
}
Expand All @@ -196,6 +206,7 @@ impl fmt::Display for Independent {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Key {
pub span: Option<Span>,
}
Expand All @@ -219,6 +230,7 @@ impl fmt::Display for Key {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Range {
pub span: Option<Span>,
pub min: Option<Literal>,
Expand Down Expand Up @@ -253,6 +265,7 @@ impl fmt::Display for Range {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Regex {
pub span: Option<Span>,
pub regex: StringLiteral,
Expand All @@ -277,6 +290,7 @@ impl fmt::Display for Regex {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Subkey {
pub span: Option<Span>,
pub ident: Identifier,
Expand All @@ -301,6 +315,7 @@ impl fmt::Display for Subkey {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Unique {
pub span: Option<Span>,
}
Expand All @@ -324,6 +339,7 @@ impl fmt::Display for Unique {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Values {
pub span: Option<Span>,
pub values: Vec<Literal>,
Expand Down
3 changes: 2 additions & 1 deletion rust/common/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use chrono::{NaiveDateTime, Timelike};

#[allow(dead_code)]
pub(crate) fn parse(date_time_text: &str) -> Option<NaiveDateTime> {
let has_seconds = date_time_text.matches(':').count() == 2;
if has_seconds {
Expand All @@ -23,7 +24,7 @@ pub(crate) fn parse(date_time_text: &str) -> Option<NaiveDateTime> {
NaiveDateTime::parse_from_str(date_time_text, "%Y-%m-%dT%H:%M").ok()
}
}

#[allow(dead_code)]
pub(crate) fn format(date_time: &NaiveDateTime) -> String {
if date_time.time().nanosecond() > 0 {
date_time.format("%Y-%m-%dT%H:%M:%S.%3f").to_string()
Expand Down
4 changes: 4 additions & 0 deletions rust/common/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ use std::{fmt, sync::OnceLock};

use regex::{Regex, RegexBuilder};

#[cfg(feature = "quine")]
use {polyquine::Quine, proc_macro2::TokenStream};

use crate::{
common::{error::TypeQLError, Span, Spanned},
is_reserved_keyword,
pretty::Pretty,
};

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Identifier {
pub span: Option<Span>,
ident: String,
Expand Down
4 changes: 4 additions & 0 deletions rust/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ pub mod token;

pub type Result<T = ()> = std::result::Result<T, Error>;

#[cfg(feature = "quine")]
use {polyquine::Quine, proc_macro2::TokenStream};

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct LineColumn {
pub line: u32,
pub column: u32,
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Span {
pub begin_offset: usize,
pub end_offset: usize,
Expand Down
4 changes: 4 additions & 0 deletions rust/common/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

use std::fmt;

#[cfg(feature = "quine")]
use {polyquine::Quine, proc_macro2::TokenStream};

macro_rules! string_enum {
{$name:ident $($item:ident = $value:tt),* $(,)?} => {
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub enum $name {
$($item),*
}
Expand Down
12 changes: 12 additions & 0 deletions rust/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use std::fmt::{self, Write};

#[cfg(feature = "quine")]
use {polyquine::Quine, proc_macro2::TokenStream};

use crate::{
common::{
identifier::Identifier,
Expand All @@ -19,6 +22,7 @@ use crate::{
};

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct BuiltinFunctionName {
pub span: Option<Span>,
pub token: token::Function,
Expand All @@ -45,6 +49,7 @@ impl fmt::Display for BuiltinFunctionName {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub enum FunctionName {
Builtin(BuiltinFunctionName),
Identifier(Identifier),
Expand All @@ -71,6 +76,7 @@ impl fmt::Display for FunctionName {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct FunctionCall {
pub span: Option<Span>,
pub name: FunctionName,
Expand Down Expand Up @@ -101,6 +107,7 @@ impl fmt::Display for FunctionCall {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Operation {
pub op: ArithmeticOperator,
pub left: Expression,
Expand Down Expand Up @@ -132,6 +139,7 @@ impl fmt::Display for Operation {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Paren {
pub span: Option<Span>,
pub inner: Expression,
Expand All @@ -158,6 +166,7 @@ impl fmt::Display for Paren {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct ListIndex {
pub span: Option<Span>,
pub variable: Variable,
Expand Down Expand Up @@ -185,6 +194,7 @@ impl fmt::Display for ListIndex {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct List {
pub span: Option<Span>,
pub items: Vec<Expression>,
Expand Down Expand Up @@ -214,6 +224,7 @@ impl fmt::Display for List {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct ListIndexRange {
pub span: Option<Span>,
pub var: Variable,
Expand Down Expand Up @@ -242,6 +253,7 @@ impl fmt::Display for ListIndexRange {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub enum Expression {
Variable(Variable),
ListIndex(Box<ListIndex>),
Expand Down
8 changes: 8 additions & 0 deletions rust/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@

use std::fmt::{self, Write};

#[cfg(feature = "quine")]
use {polyquine::Quine, proc_macro2::TokenStream};

use crate::{
common::{token, Span},
pretty::{indent, Pretty},
statement::{thing::Thing, Statement},
};

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Conjunction {
pub span: Option<Span>,
pub patterns: Vec<Pattern>,
Expand Down Expand Up @@ -42,6 +46,7 @@ impl fmt::Display for Conjunction {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Negation {
pub span: Option<Span>,
pub patterns: Vec<Pattern>,
Expand Down Expand Up @@ -73,6 +78,7 @@ impl fmt::Display for Negation {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Optional {
pub span: Option<Span>,
pub patterns: Vec<Pattern>,
Expand Down Expand Up @@ -104,6 +110,7 @@ impl fmt::Display for Optional {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Disjunction {
pub span: Option<Span>,
pub branches: Vec<Vec<Pattern>>,
Expand Down Expand Up @@ -164,6 +171,7 @@ impl fmt::Display for Disjunction {
}

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub enum Pattern {
Conjunction(Conjunction),
Disjunction(Disjunction),
Expand Down
5 changes: 5 additions & 0 deletions rust/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use std::fmt;

#[cfg(feature = "quine")]
use {polyquine::Quine, proc_macro2::TokenStream};

use self::pipeline::stage::{Match, Stage};
pub use self::{
pipeline::{stage, Pipeline},
Expand All @@ -20,6 +23,7 @@ pub mod pipeline;
pub mod schema;

#[derive(Debug, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub struct Query {
pub span: Option<Span>,
pub structure: QueryStructure,
Expand Down Expand Up @@ -56,6 +60,7 @@ impl fmt::Display for Query {
}

#[derive(Debug, Eq, PartialEq)]
#[cfg_attr(feature = "quine", derive(Quine))]
pub enum QueryStructure {
Schema(SchemaQuery),
Pipeline(Pipeline),
Expand Down
Loading