diff --git a/abnf/hello-abnf/resources/phone_uri.txt b/abnf/hello-abnf/resources/phone_uri.txt new file mode 100644 index 0000000..03bc4f2 --- /dev/null +++ b/abnf/hello-abnf/resources/phone_uri.txt @@ -0,0 +1,32 @@ + telephone-uri = "tel:" telephone-subscriber + telephone-subscriber = global-number / local-number + global-number = global-number-digits *par + local-number = local-number-digits *par context *par + par = parameter / extension / isdn-subaddress + isdn-subaddress = ";isub=" 1*uric + extension = ";ext=" 1*phonedigit + context = ";phone-context=" descriptor + descriptor = domainname / global-number-digits + global-number-digits = "+" *phonedigit DIGIT *phonedigit + local-number-digits = + *phonedigit-hex (HEXDIG / "*" / "#") *phonedigit-hex + domainname = *( domainlabel "." ) toplabel [ "." ] + domainlabel = alphanum + / alphanum *( alphanum / "-" ) alphanum + toplabel = ALPHA / ALPHA *( alphanum / "-" ) alphanum + parameter = ";" pname ["=" pvalue ] + pname = 1*( alphanum / "-" ) + pvalue = 1*paramchar + paramchar = param-unreserved / unreserved / pct-encoded + unreserved = alphanum / mark + mark = "-" / "_" / "." / "!" / "~" / "*" / + "'" / "(" / ")" + pct-encoded = "%" HEXDIG HEXDIG + param-unreserved = "[" / "]" / "/" / ":" / "&" / "+" / "$" + phonedigit = DIGIT / [ visual-separator ] + phonedigit-hex = HEXDIG / "*" / "#" / [ visual-separator ] + visual-separator = "-" / "." / "(" / ")" + alphanum = ALPHA / DIGIT + reserved = ";" / "/" / "?" / ":" / "@" / "&" / + "=" / "+" / "$" / "," + uric = reserved / unreserved / pct-encoded diff --git a/abnf/hello-abnf/src/hello_abnf/core.clj b/abnf/hello-abnf/src/hello_abnf/core.clj index ad32ed9..87c6521 100644 --- a/abnf/hello-abnf/src/hello_abnf/core.clj +++ b/abnf/hello-abnf/src/hello_abnf/core.clj @@ -1,16 +1,9 @@ (ns hello-abnf.core (:require [instaparse.core :as insta])) -(defn foo - "I don't do a whole lot." - [x] - (println x "Hello, World!")) +(def phone-uri-parser + (insta/parser "https://raw.githubusercontent.com/Engelberg/instaparse/master/test/data/phone_uri.txt" + :input-format :abnf)) -(def as-and-bs - (insta/parser - "S = AB* - AB = A B - A = 'a'+ - B = 'b'+")) - -(as-and-bs "aaaaabbbaaaabb") +(phone-uri-parser "tel:+1-201-555-0123") +;; => [:telephone-uri "tel:" [:telephone-subscriber [:global-number [:global-number-digits "+" [:DIGIT "1"] [:phonedigit [:visual-separator "-"]] [:phonedigit [:DIGIT "2"]] [:phonedigit [:DIGIT "0"]] [:phonedigit [:DIGIT "1"]] [:phonedigit [:visual-separator "-"]] [:phonedigit [:DIGIT "5"]] [:phonedigit [:DIGIT "5"]] [:phonedigit [:DIGIT "5"]] [:phonedigit [:visual-separator "-"]] [:phonedigit [:DIGIT "0"]] [:phonedigit [:DIGIT "1"]] [:phonedigit [:DIGIT "2"]] [:phonedigit [:DIGIT "3"]]]]]]