From 8717aa3faddef063bfbf303c6b6fd023fcb6e6c2 Mon Sep 17 00:00:00 2001 From: Iron-E Date: Thu, 8 Apr 2021 14:22:32 -0400 Subject: [PATCH] ref(grammars): use YAML for queries 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 --- Cargo.lock | 38 ++++++++- Cargo.toml | 1 + grammars/toml/match.ungram | 8 -- grammars/toml/query/contact.ungram | 57 ------------- grammars/toml/query/invoice_date.ungram | 12 --- grammars/toml/query/location.ungram | 19 ----- grammars/toml/query/person.ungram | 9 -- grammars/toml/query/string.ungram | 18 ---- grammars/toml/types.ungram | 40 --------- grammars/yaml/fields.ungram | 2 + grammars/yaml/match.ungram | 10 +++ grammars/yaml/query/contact.ungram | 71 ++++++++++++++++ grammars/yaml/query/date.ungram | 83 +++++++++++++++++++ grammars/{toml => yaml}/query/employee.ungram | 0 grammars/{toml => yaml}/query/invoice.ungram | 0 grammars/yaml/query/invoice_date.ungram | 13 +++ grammars/{toml => yaml}/query/job.ungram | 0 grammars/yaml/query/location.ungram | 19 +++++ .../{toml => yaml}/query/organization.ungram | 6 +- grammars/yaml/query/person.ungram | 10 +++ grammars/yaml/query/string.ungram | 29 +++++++ .../{toml => yaml}/query/timesheet.ungram | 0 grammars/{toml => yaml}/query/uuid.ungram | 28 ++++--- grammars/yaml/types.ungram | 5 ++ 24 files changed, 300 insertions(+), 178 deletions(-) delete mode 100644 grammars/toml/match.ungram delete mode 100644 grammars/toml/query/contact.ungram delete mode 100644 grammars/toml/query/invoice_date.ungram delete mode 100644 grammars/toml/query/location.ungram delete mode 100644 grammars/toml/query/person.ungram delete mode 100644 grammars/toml/query/string.ungram delete mode 100644 grammars/toml/types.ungram create mode 100644 grammars/yaml/fields.ungram create mode 100644 grammars/yaml/match.ungram create mode 100644 grammars/yaml/query/contact.ungram create mode 100644 grammars/yaml/query/date.ungram rename grammars/{toml => yaml}/query/employee.ungram (100%) rename grammars/{toml => yaml}/query/invoice.ungram (100%) create mode 100644 grammars/yaml/query/invoice_date.ungram rename grammars/{toml => yaml}/query/job.ungram (100%) create mode 100644 grammars/yaml/query/location.ungram rename grammars/{toml => yaml}/query/organization.ungram (57%) create mode 100644 grammars/yaml/query/person.ungram create mode 100644 grammars/yaml/query/string.ungram rename grammars/{toml => yaml}/query/timesheet.ungram (100%) rename grammars/{toml => yaml}/query/uuid.ungram (50%) create mode 100644 grammars/yaml/types.ungram diff --git a/Cargo.lock b/Cargo.lock index 010936ae..e2112be5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -126,6 +126,7 @@ dependencies = [ "clinvoice_export", "dialoguer", "serde", + "serde_yaml", "structopt", "thiserror", "toml", @@ -276,6 +277,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "dtoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0" + [[package]] name = "encode_unicode" version = "0.3.6" @@ -350,6 +357,12 @@ version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +[[package]] +name = "linked-hash-map" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" + [[package]] name = "num-integer" version = "0.1.44" @@ -560,6 +573,18 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_yaml" +version = "0.8.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15654ed4ab61726bf918a39cb8d98a2e2995b002387807fa6ba58fdf7f59bb23" +dependencies = [ + "dtoa", + "linked-hash-map", + "serde", + "yaml-rust", +] + [[package]] name = "sha1" version = "0.6.0" @@ -607,9 +632,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87" +checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" dependencies = [ "proc-macro2", "quote", @@ -772,6 +797,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] + [[package]] name = "zeroize" version = "0.9.3" diff --git a/Cargo.toml b/Cargo.toml index bd522127..97c03749 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ thiserror = "1" # Serialization serde = "1" toml = "0.5" +serde_yaml = "0.8" [features] default = ["bincode"] diff --git a/grammars/toml/match.ungram b/grammars/toml/match.ungram deleted file mode 100644 index eb6dbb86..00000000 --- a/grammars/toml/match.ungram +++ /dev/null @@ -1,8 +0,0 @@ -/// A condition for a `Match` -MatchCondition = 'condition = ' - -/// A `Match` for anything. -MatchAny = MatchCondition '"Any"' - -/// A value for a `MatchCondition`. Not needed for `MatchAny`. -MatchValue = 'value = ' diff --git a/grammars/toml/query/contact.ungram b/grammars/toml/query/contact.ungram deleted file mode 100644 index a604818d..00000000 --- a/grammars/toml/query/contact.ungram +++ /dev/null @@ -1,57 +0,0 @@ -//#include location -//#include ../match -//#include ../types - -/// A query for a `Contact`. -TomlContactQuery = - '[' 'ident_parent.'* 'address]literal_newline' - TomlLocationQuery 'literal_newline' - '[' 'ident_parent.'* 'email]literal_newline' - TomlContactQueryEmail - '[' 'ident_parent.'* 'phone]literal_newline' - TomlContactQueryPhone - -/// A query for the `email` field of a `Contact`. -TomlContactQueryEmail = - MatchAny -| MatchCondition '"EqualTo"literal_newline' - MatchValue Email -| MatchCondition '"HasAll"literal_newline' - MatchValue '[' (Email ',')* ']' -| MatchCondition '"HasAny"literal_newline' - MatchValue '[' (Email ',')* ']' -| MatchCondition '"HasNone"literal_newline' - MatchValue '[' (Email ',')* ']' -| MatchCondition '"InRange"literal_newline' - MatchValue '[' min:Email ',' max:Email ']' - -/// A valid email address NOTE: definition may not comprise all valid email addresses, only most. -/// -/// Example: foo@bar.io -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`. -TomlContactQueryPhone = - MatchAny -| MatchCondition '"EqualTo"literal_newline' - MatchValue Phone -| MatchCondition '"HasAll"literal_newline' - MatchValue '[' (Phone ',')* ']' -| MatchCondition '"HasAny"literal_newline' - MatchValue '[' (Phone ',')* ']' -| MatchCondition '"HasNone"literal_newline' - MatchValue '[' (Phone ',')* ']' -| MatchCondition '"InRange"literal_newline' - MatchValue '[' min:Phone ',' max: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 '"' diff --git a/grammars/toml/query/invoice_date.ungram b/grammars/toml/query/invoice_date.ungram deleted file mode 100644 index 64a869d3..00000000 --- a/grammars/toml/query/invoice_date.ungram +++ /dev/null @@ -1,12 +0,0 @@ -//#include ../match -//#include ../types - -// issued: Match<'m, DateTime>, -// paid: Match<'m, Option>>, - -/// A query for a `Person`. -TomlInvoiceDateQuery = - '[' 'ident_parent.'* 'issued]literal_newline' - TomlUuidQuery 'literal_newline' - '[' 'ident_parent.'* 'paid]literal_newline' - TomlStringQuery diff --git a/grammars/toml/query/location.ungram b/grammars/toml/query/location.ungram deleted file mode 100644 index a4012a34..00000000 --- a/grammars/toml/query/location.ungram +++ /dev/null @@ -1,19 +0,0 @@ -//#include ../match -//#include string -//#include uuid - -/// A query for a `Location`. -TomlLocationQuery = - '[' 'ident_parent.'* 'id]literal_newline' - TomlUuidQuery 'literal_newline' - '[' 'ident_parent.'* 'outer]literal_newline' - TomlLocationQueryOuter 'literal_newline' - '[' 'ident_parent.'* 'name]literal_newline' - TomlStringQuery - -/// A query for the `outer` `Location` of some `Location`. -TomlLocationQueryOuter = - MatchAny -| MatchCondition '"None"' -| MatchCondition '"Some"literal_newline' - TomlLocationQuery diff --git a/grammars/toml/query/person.ungram b/grammars/toml/query/person.ungram deleted file mode 100644 index 3e4449d5..00000000 --- a/grammars/toml/query/person.ungram +++ /dev/null @@ -1,9 +0,0 @@ -//#include string -//#include uuid - -/// A query for a `Person`. -TomlPersonQuery = - '[' 'ident_parent.'* 'id]literal_newline' - TomlUuidQuery 'literal_newline' - '[' 'ident_parent.'* 'name]literal_newline' - TomlStringQuery diff --git a/grammars/toml/query/string.ungram b/grammars/toml/query/string.ungram deleted file mode 100644 index 246922b7..00000000 --- a/grammars/toml/query/string.ungram +++ /dev/null @@ -1,18 +0,0 @@ -//#include ../match - -/// A query for the `String` type. -TomlStringQuery = - MatchAny -| MatchCondition '"EqualTo"literal_newline' - MatchValue String -| MatchCondition '"HasAll"literal_newline' - MatchValue '[' (String ',')* ']' -| MatchCondition '"HasAny"literal_newline' - MatchValue '[' (String ',')* ']' -| MatchCondition '"HasNone"literal_newline' - MatchValue '[' (String ',')* ']' -| MatchCondition '"InRange"literal_newline' - MatchValue '[' min:String ',' max:String ']' - -/// Any string literal. -String = '"' 'literal_character'* '"' diff --git a/grammars/toml/types.ungram b/grammars/toml/types.ungram deleted file mode 100644 index cb8937d2..00000000 --- a/grammars/toml/types.ungram +++ /dev/null @@ -1,40 +0,0 @@ -/// A combination of `Date` and `Time`. The fields are separated by a literal 'T'. -DateTime = '"' Date 'T' Time '"' - -/// A combination of `Year`, `Month`, and `Day` (e.g. 2000-01-01 for January 1st, 2000) -Date = Year '-' Month '-' Day - -/// A combination of `Hour`, `Minute`, and `Second` (e.g. 21:30:00 for 9:30PM). -/// -/// Also includes an offset to allow accounting for different timezones (e.g. -04:00 for EST) -Time = Hour ':' Minute ':' Second '-' offset_hour:Hour ':' offset_minute:Minute - -/// A year (e.g. 2000) -Year = Integer Integer* - -/// A month of the `Year`, where the number equates to which month it is (e.g. 12 for 'December') -Month = - '0' Integer -| '1' ('0'|'1'|'2') - -/// A day of the `Month`. Valid number of days depend on which `Month` it is. -Day = - ('0'|'1'|'2') Integer -| '3' ('0'|'1') - -/// An hour of the `Day`. AM/PM is encoded in 24-hour time (e.g. 14 for 2PM) -Hour = - ('0'|'1') Integer -| '2' ('0'|'1'|'2'|'3') - -/// A minute of the `Hour`. Cannot go over 60— that would be the next `Hour`. -Minute = ('0'|'1'|'2'|'3'|'4'|'5') Integer - -/// Seconds of a `Minute`. Has the same formatting as `Minute`. -Second = Minute - -/// A whole number. -Integer = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' - -/// Lowercase letters of the alphabet. -AlphabetLowercase = 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'|'k'|'l'|'m'|'n'|'o'|'p'|'q'|'r'|'s'|'t'|'u'|'v'|'w'|'x'|'y'|'z' diff --git a/grammars/yaml/fields.ungram b/grammars/yaml/fields.ungram new file mode 100644 index 00000000..be0efc30 --- /dev/null +++ b/grammars/yaml/fields.ungram @@ -0,0 +1,2 @@ +YamlFieldPrefix = 'literal_tab' YamlFieldNamePrefix +YamlFieldNamePrefix = 'literal_tab'* diff --git a/grammars/yaml/match.ungram b/grammars/yaml/match.ungram new file mode 100644 index 00000000..4b8f5108 --- /dev/null +++ b/grammars/yaml/match.ungram @@ -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: ' diff --git a/grammars/yaml/query/contact.ungram b/grammars/yaml/query/contact.ungram new file mode 100644 index 00000000..dc2b3320 --- /dev/null +++ b/grammars/yaml/query/contact.ungram @@ -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: foo@bar.io +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 '"' diff --git a/grammars/yaml/query/date.ungram b/grammars/yaml/query/date.ungram new file mode 100644 index 00000000..23daacfe --- /dev/null +++ b/grammars/yaml/query/date.ungram @@ -0,0 +1,83 @@ +//#include ../fields +//#include ../types + +/// A query for the `DateTime` type. +YamlDateTimeQuery = + MatchAny +| MatchCondition 'EqualTo' 'literal_newline' + MatchValue DateTime +| MatchCondition 'HasAll' 'literal_newline' + MatchValue + ('literal_newline' YamlDateTimeListItem ('literal_newline' YamlDateTimeListItem)* | '[]') +| MatchCondition 'HasAny' 'literal_newline' + MatchValue + ('literal_newline' YamlDateTimeListItem ('literal_newline' YamlDateTimeListItem)* | '[]') +| MatchCondition 'HasNone' 'literal_newline' + MatchValue + ('literal_newline' YamlDateTimeListItem ('literal_newline' YamlDateTimeListItem)* | '[]') +| MatchCondition 'InRange' 'literal_newline' + MatchValue 'literal_newline' + min:YamlDateTimeListItem 'literal_newline' + max:YamlDateTimeListItem + +YamlDateTimeListItem = YamlFieldPrefix '- ' DateTime + +/// A combination of `Date` and `Time`. The fields are separated by a literal 'T'. +DateTime = '"' Date 'T' Time '"' + +/// A combination of `Year`, `Month`, and `Day` (e.g. 2000-01-01 for January 1st, 2000) +Date = Year '-' Month '-' Day + +/// A combination of `Hour`, `Minute`, and `Second` (e.g. 21:30:00 for 9:30PM). +/// +/// Also includes an offset to allow accounting for different timezones (e.g. -04:00 for EST) +Time = Hour ':' Minute ':' Second '-' offset_hour:Hour ':' offset_minute:Minute + +/// A year (e.g. 2000) +Year = Integer Integer* + +/// A month of the `Year`, where the number equates to which month it is (e.g. 12 for 'December') +Month = + '0' Integer +| '1' ('0'|'1'|'2') + +/// A day of the `Month`. Valid number of days depend on which `Month` it is. +Day = + ('0'|'1'|'2') Integer +| '3' ('0'|'1') + +/// An hour of the `Day`. AM/PM is encoded in 24-hour time (e.g. 14 for 2PM) +Hour = + ('0'|'1') Integer +| '2' ('0'|'1'|'2'|'3') + +/// A minute of the `Hour`. Cannot go over 60— that would be the next `Hour`. +Minute = ('0'|'1'|'2'|'3'|'4'|'5') Integer + +/// Seconds of a `Minute`. Has the same formatting as `Minute`. +Second = Minute + +/// A query for the `OptionalDateTime` type. +YamlOptionalDateTimeQuery = + MatchAny +| MatchCondition 'EqualTo' 'literal_newline' + MatchValue OptionalDateTime +| MatchCondition 'HasAll' 'literal_newline' + MatchValue + ('literal_newline' YamlOptionalDateTimeListItem ('literal_newline' YamlOptionalDateTimeListItem)* | '[]') +| MatchCondition 'HasAny' 'literal_newline' + MatchValue + ('literal_newline' YamlOptionalDateTimeListItem ('literal_newline' YamlOptionalDateTimeListItem)* | '[]') +| MatchCondition 'HasNone' 'literal_newline' + MatchValue + ('literal_newline' YamlOptionalDateTimeListItem ('literal_newline' YamlOptionalDateTimeListItem)* | '[]') +| MatchCondition 'InRange' 'literal_newline' + MatchValue 'literal_newline' + min:YamlOptionalDateTimeListItem 'literal_newline' + max:YamlOptionalDateTimeListItem + +YamlOptionalDateTimeListItem = YamlFieldPrefix '- ' OptionalDateTime + +OptionalDateTime = + '~' +| DateTime diff --git a/grammars/toml/query/employee.ungram b/grammars/yaml/query/employee.ungram similarity index 100% rename from grammars/toml/query/employee.ungram rename to grammars/yaml/query/employee.ungram diff --git a/grammars/toml/query/invoice.ungram b/grammars/yaml/query/invoice.ungram similarity index 100% rename from grammars/toml/query/invoice.ungram rename to grammars/yaml/query/invoice.ungram diff --git a/grammars/yaml/query/invoice_date.ungram b/grammars/yaml/query/invoice_date.ungram new file mode 100644 index 00000000..28b6914f --- /dev/null +++ b/grammars/yaml/query/invoice_date.ungram @@ -0,0 +1,13 @@ +//#include ../match +//#include ../types +//#include date + +// issued: Match<'m, DateTime>, +// paid: Match<'m, Option>>, + +/// A query for a `Person`. +YamlInvoiceDateQuery = + YamlFieldNamePrefix 'issued:literal_newline' + YamlDateTimeQuery 'literal_newline' + YamlFieldNamePrefix 'paid:literal_newline' + YamlOptionalDateTimeQuery diff --git a/grammars/toml/query/job.ungram b/grammars/yaml/query/job.ungram similarity index 100% rename from grammars/toml/query/job.ungram rename to grammars/yaml/query/job.ungram diff --git a/grammars/yaml/query/location.ungram b/grammars/yaml/query/location.ungram new file mode 100644 index 00000000..4be645ed --- /dev/null +++ b/grammars/yaml/query/location.ungram @@ -0,0 +1,19 @@ +//#include ../match +//#include string +//#include uuid + +/// A query for a `Location`. +YamlLocationQuery = + YamlFieldNamePrefix 'id:literal_newline' + YamlUuidQuery 'literal_newline' + YamlFieldNamePrefix 'outer:literal_newline' + YamlLocationQueryOuter 'literal_newline' + YamlFieldNamePrefix 'name:literal_newline' + YamlStringQuery + +/// A query for the `outer` `Location` of some `Location`. +YamlLocationQueryOuter = + MatchAny +| MatchCondition 'None' +| MatchCondition 'Some' 'literal_newline' + YamlLocationQuery diff --git a/grammars/toml/query/organization.ungram b/grammars/yaml/query/organization.ungram similarity index 57% rename from grammars/toml/query/organization.ungram rename to grammars/yaml/query/organization.ungram index 7462dc24..2f141718 100644 --- a/grammars/toml/query/organization.ungram +++ b/grammars/yaml/query/organization.ungram @@ -4,9 +4,9 @@ /// A query for an `Organization`. TomlOrganizationQuery = - '[' 'ident_parent.'* 'id]literal_newline' + YamlFieldNamePrefix 'id:literal_newline' TomlUuidQuery 'literal_newline' - '[' 'ident_parent.'* 'location]literal_newline' + YamlFieldNamePrefix 'location:literal_newline' TomlLocationQuery - '[' 'ident_parent.'* 'name]literal_newline' + YamlFieldNamePrefix 'name:literal_newline' TomlStringQuery diff --git a/grammars/yaml/query/person.ungram b/grammars/yaml/query/person.ungram new file mode 100644 index 00000000..b5305163 --- /dev/null +++ b/grammars/yaml/query/person.ungram @@ -0,0 +1,10 @@ +//#include ../fields +//#include string +//#include uuid + +/// A query for a `Person`. +YamlPersonQuery = + YamlFieldNamePrefix 'id:literal_newline' + YamlUuidQuery 'literal_newline' + YamlFieldNamePrefix 'name:literal_newline' + YamlStringQuery diff --git a/grammars/yaml/query/string.ungram b/grammars/yaml/query/string.ungram new file mode 100644 index 00000000..d9365f56 --- /dev/null +++ b/grammars/yaml/query/string.ungram @@ -0,0 +1,29 @@ +//#include ../fields +//#include ../match +//#include ../types + +/// A query for the `String` type. +YamlStringQuery = + MatchAny +| MatchCondition 'EqualTo' 'literal_newline' + MatchValue String +| MatchCondition 'HasAll' 'literal_newline' + MatchValue + ('literal_newline' YamlStringListItem ('literal_newline' YamlStringListItem)* | '[]') +| MatchCondition 'HasAny' 'literal_newline' + MatchValue + ('literal_newline' YamlStringListItem ('literal_newline' YamlStringListItem)* | '[]') +| MatchCondition 'HasNone' 'literal_newline' + MatchValue + ('literal_newline' YamlStringListItem ('literal_newline' YamlStringListItem)* | '[]') +| MatchCondition 'InRange' 'literal_newline' + MatchValue 'literal_newline' + min:YamlStringListItem 'literal_newline' + max:YamlStringListItem + +YamlStringListItem = YamlFieldPrefix '- ' String + +/// Any string literal. +String = + '"' 'literal_character'* '"' +| (Integer|'literal_letter') (Integer|'literal_letter')* diff --git a/grammars/toml/query/timesheet.ungram b/grammars/yaml/query/timesheet.ungram similarity index 100% rename from grammars/toml/query/timesheet.ungram rename to grammars/yaml/query/timesheet.ungram diff --git a/grammars/toml/query/uuid.ungram b/grammars/yaml/query/uuid.ungram similarity index 50% rename from grammars/toml/query/uuid.ungram rename to grammars/yaml/query/uuid.ungram index 384f3d23..28220323 100644 --- a/grammars/toml/query/uuid.ungram +++ b/grammars/yaml/query/uuid.ungram @@ -1,19 +1,27 @@ +//#include ../fields //#include ../match //#include ../types /// A query for the `Uuid` type. -TomlUuidQuery = +YamlUuidQuery = MatchAny -| MatchCondition '"EqualTo"literal_newline' +| MatchCondition 'EqualTo' 'literal_newline' MatchValue Uuid -| MatchCondition '"HasAll"literal_newline' - MatchValue '[' (Uuid ',')* ']' -| MatchCondition '"HasAny"literal_newline' - MatchValue '[' (Uuid ',')* ']' -| MatchCondition '"HasNone"literal_newline' - MatchValue '[' (Uuid ',')* ']' -| MatchCondition '"InRange"literal_newline' - MatchValue '[' min:Uuid ',' max:Uuid ']' +| MatchCondition 'HasAll' 'literal_newline' + MatchValue + ('literal_newline' YamlUuidListItem ('literal_newline' YamlUuidListItem)* | '[]') +| MatchCondition 'HasAny' 'literal_newline' + MatchValue + ('literal_newline' YamlUuidListItem ('literal_newline' YamlUuidListItem)* | '[]') +| MatchCondition 'HasNone' 'literal_newline' + MatchValue + ('literal_newline' YamlUuidListItem ('literal_newline' YamlUuidListItem)* | '[]') +| MatchCondition 'InRange' 'literal_newline' + MatchValue 'literal_newline' + min:YamlUuidListItem 'literal_newline' + max:YamlUuidListItem + +YamlUuidListItem = YamlFieldPrefix '- ' Uuid /// A universally-unique identifier. Uuid = '"' UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter '-' UuidCharacter UuidCharacter UuidCharacter UuidCharacter '-' UuidCharacter UuidCharacter UuidCharacter UuidCharacter '-' UuidCharacter UuidCharacter UuidCharacter UuidCharacter '-' UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter UuidCharacter '"' diff --git a/grammars/yaml/types.ungram b/grammars/yaml/types.ungram new file mode 100644 index 00000000..4af5761a --- /dev/null +++ b/grammars/yaml/types.ungram @@ -0,0 +1,5 @@ +/// Lowercase letters of the alphabet. +AlphabetLowercase = 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'|'k'|'l'|'m'|'n'|'o'|'p'|'q'|'r'|'s'|'t'|'u'|'v'|'w'|'x'|'y'|'z' + +/// A whole number. +Integer = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'