Skip to content

Commit

Permalink
ref(grammars): use YAML for queries
Browse files Browse the repository at this point in the history
This is because TOML does not support `None` in lists. We need to be
able to tell the difference between `Some` and `None` in list items in
order to support `Match<'_, Option<_>>`.

SEE toml-lang/toml#30
  • Loading branch information
Iron-E committed Apr 8, 2021
1 parent 28e8cf0 commit 8717aa3
Show file tree
Hide file tree
Showing 24 changed files with 300 additions and 178 deletions.
38 changes: 36 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ thiserror = "1"
# Serialization
serde = "1"
toml = "0.5"
serde_yaml = "0.8"

[features]
default = ["bincode"]
Expand Down
8 changes: 0 additions & 8 deletions grammars/toml/match.ungram

This file was deleted.

57 changes: 0 additions & 57 deletions grammars/toml/query/contact.ungram

This file was deleted.

12 changes: 0 additions & 12 deletions grammars/toml/query/invoice_date.ungram

This file was deleted.

19 changes: 0 additions & 19 deletions grammars/toml/query/location.ungram

This file was deleted.

9 changes: 0 additions & 9 deletions grammars/toml/query/person.ungram

This file was deleted.

18 changes: 0 additions & 18 deletions grammars/toml/query/string.ungram

This file was deleted.

40 changes: 0 additions & 40 deletions grammars/toml/types.ungram

This file was deleted.

2 changes: 2 additions & 0 deletions grammars/yaml/fields.ungram
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YamlFieldPrefix = 'literal_tab' YamlFieldNamePrefix
YamlFieldNamePrefix = 'literal_tab'*
10 changes: 10 additions & 0 deletions grammars/yaml/match.ungram
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//#include fields

/// A `Match` for anything.
MatchAny = MatchCondition 'Any'

/// A condition for a `Match`
MatchCondition = YamlFieldPrefix 'condition: '

/// A value for a `MatchCondition`. Not needed for `MatchAny`.
MatchValue = YamlFieldPrefix 'value: '
71 changes: 71 additions & 0 deletions grammars/yaml/query/contact.ungram
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//#include location
//#include ../match
//#include ../types

/// A query for a `Contact`.
YamlContactQuery =
YamlFieldNamePrefix 'address:literal_newline'
YamlLocationQuery 'literal_newline'
YamlFieldNamePrefix 'email:literal_newline'
YamlContactQueryEmail
YamlFieldNamePrefix 'phone:literal_newline'
YamlContactQueryPhone

/// A query for the `email` field of a `Contact`.
YamlContactQueryEmail =
MatchAny
| MatchCondition 'EqualTo' 'literal_newline'
MatchValue Email
| MatchCondition 'HasAll' 'literal_newline'
MatchValue
('literal_newline' YamlEmailListItem ('literal_newline' YamlEmailListItem)* | '[]')
| MatchCondition 'HasAny' 'literal_newline'
MatchValue
('literal_newline' YamlEmailListItem ('literal_newline' YamlEmailListItem)* | '[]')
| MatchCondition 'HasNone' 'literal_newline'
MatchValue
('literal_newline' YamlEmailListItem ('literal_newline' YamlEmailListItem)* | '[]')
| MatchCondition 'InRange' 'literal_newline'
MatchValue 'literal_newline'
min:YamlEmailListItem 'literal_newline'
max:YamlEmailListItem

YamlEmailListItem = YamlFieldPrefix '- ' Email

/// A valid email address NOTE: definition may not comprise all valid email addresses, only most.
///
/// Example: [email protected]
Email = '"' EmailPrefix '@' EmailDomain '.top_level_domain' '"'

/// The part of an email before the '@'.
EmailPrefix =
AlphabetLowercase EmailPrefix*
| Integer EmailPrefix*
| (AlphabetLowercase|Integer) ('-'|'_'|'.') (AlphabetLowercase|Integer) EmailPrefix*

/// The part of an email after the '@'.
EmailDomain = (AlphabetLowercase|Integer) (AlphabetLowercase|Integer|'-')* (AlphabetLowercase|Integer)

/// A query for the `phone` field of a `Contact`.
YamlContactQueryPhone =
MatchAny
| MatchCondition 'EqualTo' 'literal_newline'
MatchValue Phone
| MatchCondition 'HasAll' 'literal_newline'
MatchValue
('literal_newline' YamlPhoneListItem ('literal_newline' YamlPhoneListItem)* | '[]')
| MatchCondition 'HasAny' 'literal_newline'
MatchValue
('literal_newline' YamlPhoneListItem ('literal_newline' YamlPhoneListItem)* | '[]')
| MatchCondition 'HasNone' 'literal_newline'
MatchValue
('literal_newline' YamlPhoneListItem ('literal_newline' YamlPhoneListItem)* | '[]')
| MatchCondition 'InRange' 'literal_newline'
MatchValue 'literal_newline'
min:YamlPhoneListItem 'literal_newline'
max:YamlPhoneListItem

YamlPhoneListItem = YamlFieldPrefix '- ' Phone

/// A standard phone number. Contains an optional country code (e.g. 1-555-627-5309 or 555-627-5309).
Phone = '"' (Integer Integer* '-')? Integer Integer Integer '-' Integer Integer Integer '-' Integer Integer Integer Integer '"'
Loading

0 comments on commit 8717aa3

Please sign in to comment.