-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flychecking fails with janet-uri library #1101
Comments
Based on some comments by bakpakin:
I tried moving the two peg grammar definitions inside the functions they were used in [1] (each is only used in one place so this was doable). That seemed to take care of things. May be @andrewchambers has some thoughts about this issue. [1] A diff looked like this: diff --git a/uri.janet b/uri.janet
index 44eff00..81543c8 100644
--- a/uri.janet
+++ b/uri.janet
@@ -82,18 +82,20 @@
# / "*" / "+" / "," / ";" / "="
(import _uri :prefix "" :export true)
-(def- query-grammar ~{
- :main (sequence (opt :query) (not 1))
- :query (sequence :pair (any (sequence "&" :pair)))
- :pair (sequence (cmt (capture :key) ,unescape) "=" (cmt (capture :value) ,unescape))
- :key (any (sequence (not "=") 1))
- :value (any (sequence (not "&") 1))
-})
-
(defn parse-query
[q]
"Parse a uri encoded query string returning a table or nil."
- (when-let [matches (peg/match (comptime (peg/compile query-grammar)) q)]
+ (def query-grammar
+ (comptime
+ (peg/compile
+ ~{:main (sequence (opt :query) (not 1))
+ :query (sequence :pair (any (sequence "&" :pair)))
+ :pair (sequence (cmt (capture :key) ,unescape)
+ "="
+ (cmt (capture :value) ,unescape))
+ :key (any (sequence (not "=") 1))
+ :value (any (sequence (not "&") 1))})))
+ (when-let [matches (peg/match query-grammar q)]
(table ;matches)))
(defn- named-capture
@@ -101,54 +103,6 @@
(default name rule)
~(sequence (constant ,name) (capture ,rule)))
-(def- uri-grammar ~{
- :main (sequence :URI-reference (not 1))
- :URI-reference (choice :URI :relative-ref)
- :URI (sequence ,(named-capture :scheme) ":" :hier-part (opt (sequence "?" ,(named-capture :query :raw-query))) (opt (sequence "#" ,(named-capture :fragment :raw-fragment))))
- :relative-ref (sequence :relative-part (opt (sequence "?" ,(named-capture :query :raw-query))) (opt (sequence "#" ,(named-capture :fragment :raw-fragment))))
- :hier-part (choice (sequence "//" :authority :path-abempty) :path-absolute :path-rootless :path-empty)
- :relative-part (choice (sequence "//" :authority :path-abempty) :path-absolute :path-noscheme :path-empty)
- :scheme (sequence :a (any (choice :a :d "+" "-" ".")))
- :authority (sequence (opt (sequence ,(named-capture :userinfo) "@")) ,(named-capture :host) (opt (sequence ":" ,(named-capture :port))))
- :userinfo (any (choice :unreserved :pct-encoded :sub-delims ":"))
- :host (choice :IP-literal :IPv4address :reg-name)
- :port (any :d)
- :IP-literal (sequence "[" (choice :IPv6address :IPvFuture ) "]" )
- :IPv4address (sequence :dec-octet "." :dec-octet "." :dec-octet "." :dec-octet)
- :IPvFuture (sequence "v" (at-least 1 :hexdig) "." (at-least 1 (sequence :unreserved :sub-delims ":" )))
- :IPv6address (choice
- (sequence (repeat 6 (sequence :h16 ":")) :ls32)
- (sequence "::" (repeat 5 (sequence :h16 ":")) :ls32)
- (sequence (opt :h16) "::" (repeat 4 (sequence :h16 ":")) :ls32)
- (sequence (opt (sequence (at-most 1 (sequence :h16 ":")) :h16)) "::" (repeat 3 (sequence :h16 ":")) :ls32)
- (sequence (opt (sequence (at-most 2 (sequence :h16 ":")) :h16)) "::" (repeat 2 (sequence :h16 ":")) :ls32)
- (sequence (opt (sequence (at-most 3 (sequence :h16 ":")) :h16)) "::" (sequence :h16 ":") :ls32)
- (sequence (opt (sequence (at-most 4 (sequence :h16 ":")) :h16)) "::" :ls32)
- (sequence (opt (sequence (at-most 5 (sequence :h16 ":")) :h16)) "::" :h16)
- (sequence (opt (sequence (at-most 6 (sequence :h16 ":")) :h16)) "::"))
- :h16 (between 1 4 :hexdig)
- :ls32 (choice (sequence :h16 ":" :h16) :IPv4address)
- :dec-octet (choice (sequence "25" (range "05")) (sequence "2" (range "04") :d) (sequence "1" :d :d) (sequence (range "19") :d) :d)
- :reg-name (any (choice :unreserved :pct-encoded :sub-delims))
- :path (choice :path-abempty :path-absolute :path-noscheme :path-rootless :path-empty)
- :path-abempty ,(named-capture ~(any (sequence "/" :segment)) :raw-path)
- :path-absolute ,(named-capture ~(sequence "/" (opt (sequence :segment-nz (any (sequence "/" :segment))))) :raw-path)
- :path-noscheme ,(named-capture ~(sequence :segment-nz-nc (any (sequence "/" :segment))) :raw-path)
- :path-rootless ,(named-capture ~(sequence :segment-nz (any (sequence "/" :segment))) :raw-path)
- :path-empty (not :pchar)
- :segment (any :pchar)
- :segment-nz (some :pchar)
- :segment-nz-nc (some (choice :unreserved :pct-encoded :sub-delims "@" ))
- :pchar (choice :unreserved :pct-encoded :sub-delims ":" "@")
- :query (any (choice :pchar (set "/?")))
- :fragment (any (choice :pchar (set "/?")))
- :pct-encoded (sequence "%" :hexdig :hexdig)
- :unreserved (choice :a :d (set "-._~"))
- :gen-delims (set ":/?#[]@")
- :sub-delims (set "!$&'()*+,;=")
- :hexdig (choice :d (range "AF") (range "af"))
-})
-
(defn parse-raw
"Parse a uri-reference following rfc3986.
@@ -162,7 +116,99 @@
returns nil if the input is not a valid uri.
"
[u &keys {:parse-query parse-query :unescape do-unescape}]
- (when-let [matches (peg/match (comptime (peg/compile uri-grammar)) u)]
+ (def uri-grammar
+ (comptime
+ (peg/compile
+ ~{:main (sequence :URI-reference (not 1))
+ :URI-reference (choice :URI :relative-ref)
+ :URI
+ (sequence
+ ,(named-capture :scheme) ":" :hier-part
+ (opt (sequence "?" ,(named-capture :query :raw-query)))
+ (opt (sequence "#" ,(named-capture :fragment :raw-fragment))))
+ :relative-ref
+ (sequence
+ :relative-part
+ (opt (sequence "?" ,(named-capture :query :raw-query)))
+ (opt (sequence "#" ,(named-capture :fragment :raw-fragment))))
+ :hier-part (choice (sequence "//" :authority :path-abempty)
+ :path-absolute :path-rootless :path-empty)
+ :relative-part (choice (sequence "//" :authority :path-abempty)
+ :path-absolute :path-noscheme :path-empty)
+ :scheme (sequence :a (any (choice :a :d "+" "-" ".")))
+ :authority (sequence (opt (sequence ,(named-capture :userinfo) "@"))
+ ,(named-capture :host)
+ (opt (sequence ":" ,(named-capture :port))))
+ :userinfo (any (choice :unreserved :pct-encoded :sub-delims ":"))
+ :host (choice :IP-literal :IPv4address :reg-name)
+ :port (any :d)
+ :IP-literal (sequence "[" (choice :IPv6address :IPvFuture ) "]" )
+ :IPv4address (sequence :dec-octet "." :dec-octet "."
+ :dec-octet "." :dec-octet)
+ :IPvFuture
+ (sequence "v" (at-least 1 :hexdig) "."
+ (at-least 1
+ (sequence :unreserved :sub-delims ":" )))
+ :IPv6address
+ (choice
+ (sequence (repeat 6 (sequence :h16 ":")) :ls32)
+ (sequence "::" (repeat 5 (sequence :h16 ":")) :ls32)
+ (sequence (opt :h16) "::" (repeat 4 (sequence :h16 ":")) :ls32)
+ (sequence (opt (sequence (at-most 1 (sequence :h16 ":")) :h16))
+ "::" (repeat 3 (sequence :h16 ":")) :ls32)
+ (sequence (opt (sequence (at-most 2 (sequence :h16 ":")) :h16))
+ "::" (repeat 2 (sequence :h16 ":")) :ls32)
+ (sequence (opt (sequence (at-most 3 (sequence :h16 ":")) :h16))
+ "::" (sequence :h16 ":") :ls32)
+ (sequence (opt (sequence (at-most 4 (sequence :h16 ":")) :h16))
+ "::" :ls32)
+ (sequence (opt (sequence (at-most 5 (sequence :h16 ":")) :h16))
+ "::" :h16)
+ (sequence (opt (sequence (at-most 6 (sequence :h16 ":")) :h16))
+ "::"))
+ :h16 (between 1 4 :hexdig)
+ :ls32 (choice (sequence :h16 ":" :h16) :IPv4address)
+ :dec-octet (choice
+ (sequence "25" (range "05"))
+ (sequence "2" (range "04") :d)
+ (sequence "1" :d :d)
+ (sequence (range "19") :d) :d)
+ :reg-name (any (choice :unreserved :pct-encoded :sub-delims))
+ :path (choice :path-abempty :path-absolute
+ :path-noscheme :path-rootless
+ :path-empty)
+ :path-abempty ,(named-capture
+ ~(any (sequence "/" :segment))
+ :raw-path)
+ :path-absolute ,(named-capture
+ ~(sequence
+ "/"
+ (opt (sequence
+ :segment-nz
+ (any (sequence "/" :segment)))))
+ :raw-path)
+ :path-noscheme ,(named-capture
+ ~(sequence :segment-nz-nc
+ (any (sequence "/" :segment)))
+ :raw-path)
+ :path-rootless ,(named-capture
+ ~(sequence :segment-nz
+ (any (sequence "/" :segment)))
+ :raw-path)
+ :path-empty (not :pchar)
+ :segment (any :pchar)
+ :segment-nz (some :pchar)
+ :segment-nz-nc (some (choice :unreserved :pct-encoded
+ :sub-delims "@" ))
+ :pchar (choice :unreserved :pct-encoded :sub-delims ":" "@")
+ :query (any (choice :pchar (set "/?")))
+ :fragment (any (choice :pchar (set "/?")))
+ :pct-encoded (sequence "%" :hexdig :hexdig)
+ :unreserved (choice :a :d (set "-._~"))
+ :gen-delims (set ":/?#[]@")
+ :sub-delims (set "!$&'()*+,;=")
+ :hexdig (choice :d (range "AF") (range "af"))})))
+ (when-let [matches (peg/match uri-grammar u)]
(table ;matches)))
(defn parse |
Hi,
flychecking source files of projects which depend on janet-uri fails with following error:
flycheck-evaluator seems to spit this error on this line.
I'm not sure if this issue is up to
janet
orjanet-uri
, so please correct me if I'm in the wrong neighborhood.The text was updated successfully, but these errors were encountered: