shex_compact/
grammar_structs.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use iri_s::IriS;
use prefixmap::IriRef;
use shex_ast::{IriOrStr, SemAct, ShapeExpr, ShapeExprLabel};

#[derive(Debug, PartialEq)]
pub(crate) enum ShExStatement<'a> {
    PrefixDecl {
        alias: &'a str,
        iri: IriS,
    },
    BaseDecl {
        iri: IriS,
    },
    ImportDecl {
        iri: IriOrStr,
    },
    StartActions {
        actions: Vec<SemAct>,
    },
    StartDecl {
        shape_expr: ShapeExpr,
    },
    ShapeDecl {
        is_abstract: bool,
        shape_label: ShapeExprLabel,
        shape_expr: ShapeExpr,
    },
}

#[derive(PartialEq, Debug)]
pub(crate) enum Qualifier {
    Closed,
    Extra(Vec<IriRef>),
    Extends(ShapeExprLabel),
}

#[derive(PartialEq, Debug)]
pub(crate) struct Cardinality {
    min: Option<i32>,
    max: Option<i32>,
}

impl Cardinality {
    pub fn plus() -> Cardinality {
        Cardinality {
            min: Some(1),
            max: Some(-1),
        }
    }

    pub fn star() -> Cardinality {
        Cardinality {
            min: Some(0),
            max: Some(-1),
        }
    }

    pub fn optional() -> Cardinality {
        Cardinality {
            min: Some(0),
            max: Some(1),
        }
    }

    /*
    pub fn range(min: i32, max: i32) -> Cardinality {
        Cardinality {
            min: Some(min),
            max: Some(max),
        }
    }
    */

    pub fn exact(n: i32) -> Cardinality {
        Cardinality {
            min: Some(n),
            max: Some(n),
        }
    }

    /*
    pub fn only_min(n: i32) -> Cardinality {
        Cardinality {
            min: Some(n),
            max: None,
        }
    }
    */

    pub fn min_max(min: i32, max: i32) -> Cardinality {
        Cardinality {
            min: Some(min),
            max: Some(max),
        }
    }

    pub fn min(&self) -> Option<i32> {
        self.min
    }

    pub fn max(&self) -> Option<i32> {
        self.max
    }
}

impl Default for Cardinality {
    fn default() -> Self {
        Self {
            min: Some(1),
            max: Some(1),
        }
    }
}

pub(crate) enum NumericLength {
    TotalDigits,
    FractionDigits,
}

pub(crate) enum NumericRange {
    MinInclusive,
    MinExclusive,
    MaxInclusive,
    MaxExclusive,
}

pub(crate) struct SenseFlags {
    pub(crate) inverse: Option<bool>,
    pub(crate) negated: Option<bool>,
}

impl SenseFlags {
    pub(crate) fn extract(&self) -> (Option<bool>, Option<bool>) {
        (self.negated, self.inverse)
    }
}