airlang/
syntax.rs

1pub use self::error::ParseError;
2pub use self::error::ReprError;
3pub use self::generator::GenRepr;
4pub use self::generator::escape_symbol;
5pub use self::generator::escape_text;
6pub use self::generator::escape_text_symbol;
7pub use self::parser::ParseRepr;
8pub use self::parser::parse;
9
10_____!();
11
12use derive_more::IsVariant;
13
14use self::generator::COMPACT_FMT;
15use self::generator::PRETTY_FMT;
16use self::generator::SYMBOL_FMT;
17
18pub fn generate_pretty(src: GenRepr) -> String {
19    generator::generate(src, PRETTY_FMT)
20}
21
22pub fn generate_compact(src: GenRepr) -> String {
23    generator::generate(src, COMPACT_FMT)
24}
25
26pub fn generate_symbol(src: GenRepr) -> String {
27    generator::generate(src, SYMBOL_FMT)
28}
29
30// delimiters
31
32pub(crate) const LIST_LEFT: char = '[';
33pub(crate) const LIST_RIGHT: char = ']';
34pub(crate) const MAP_LEFT: char = '{';
35pub(crate) const MAP_RIGHT: char = '}';
36pub(crate) const SCOPE_LEFT: char = '(';
37pub(crate) const SCOPE_RIGHT: char = ')';
38
39pub(crate) const SPACE: char = ' ';
40pub(crate) const SEPARATOR: char = ',';
41
42pub(crate) const TEXT_QUOTE: char = '"';
43pub(crate) const SYMBOL_QUOTE: char = '\'';
44
45// keywords
46
47pub(crate) const COMMENT: &str = "_";
48
49pub(crate) const LEFT: &str = "<";
50pub(crate) const RIGHT: &str = ">";
51
52pub(crate) const UNIT: &str = ".";
53pub(crate) const TRUE: &str = "true";
54pub(crate) const FALSE: &str = "false";
55
56pub(crate) const INT: &str = "integer";
57pub(crate) const NUMBER: &str = "number";
58pub(crate) const BYTE: &str = "byte";
59
60pub(crate) const PAIR: &str = ":";
61
62pub(crate) const QUOTE: char = '`';
63
64pub(crate) fn is_delimiter(c: char) -> bool {
65    matches!(
66        c,
67        SPACE
68            | SEPARATOR
69            | LIST_LEFT
70            | LIST_RIGHT
71            | MAP_LEFT
72            | MAP_RIGHT
73            | SCOPE_LEFT
74            | SCOPE_RIGHT
75            | TEXT_QUOTE
76            | SYMBOL_QUOTE
77    )
78}
79
80pub(crate) fn ambiguous(s: &str) -> bool {
81    matches!(s, UNIT | TRUE | FALSE | PAIR)
82}
83
84#[derive(Default, Copy, Clone, PartialEq, Eq, IsVariant)]
85enum Direction {
86    Left,
87    #[default]
88    Right,
89}
90
91pub mod repr;
92
93mod parser;
94
95mod generator;
96
97mod error;
98
99#[cfg(test)]
100mod test;