Skip to content

Next version #43

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

Merged
merged 70 commits into from
Mar 20, 2018
Merged
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
176af66
Make Sceheme requred for non-relative URIs
garyb Jan 26, 2018
4356849
WIP
garyb Jan 29, 2018
15b8078
WIP
garyb Jan 29, 2018
df02b9e
WIP
garyb Jan 29, 2018
b843e7f
Split "nonstandard" types out
garyb Jan 29, 2018
8b316de
Record for parser/printer components
garyb Jan 29, 2018
aeae895
Free hosts from being an array
garyb Jan 29, 2018
c3decaf
Use functions for component parsing
garyb Jan 30, 2018
f528b7a
Remove some junk from Common, avoid regex parsers (mostly)
garyb Jan 30, 2018
372b3af
Style consistency for imports
garyb Jan 30, 2018
8fbf064
Delete old test for now-deleted `match1`
garyb Jan 30, 2018
14273b0
Add host/port parameters, introduce some encoded-value types
garyb Feb 1, 2018
97534e6
Introduce encoded-value type for Query
garyb Feb 1, 2018
9730451
Split up tests, update path representation
garyb Feb 3, 2018
e5e7b11
More tests, fix some re-exports
garyb Feb 5, 2018
c917296
Update to use preferred test/parse libraries
garyb Feb 5, 2018
2fed7b5
Some progress on valid handling of `,` & multi-host support
garyb Feb 6, 2018
0386d26
Fix warning
garyb Feb 6, 2018
3da1466
Fully parameterise host/port parsing
garyb Feb 6, 2018
49d3168
Safe construction for a few more values
garyb Feb 6, 2018
9a15157
Restore `QueryPairs` extra structure
garyb Feb 6, 2018
d5a5f33
Introduce `MultiHostPortPair`
garyb Feb 6, 2018
25aa142
Merge remote-tracking branch 'slamdata/master' into next
garyb Feb 6, 2018
281a512
Add extra for `user:password` handling in `UserInfo`
garyb Feb 7, 2018
33468dd
use NonEmptyString for RegName and PathSegmentNZ
safareli Feb 27, 2018
2c177fd
use crashWith for Scheme
safareli Feb 27, 2018
17c1408
add Semigroup and Monoid for Path
safareli Feb 27, 2018
3fba380
use NonEmptyString for unsafeFromString
safareli Feb 27, 2018
dcafee8
use NonEmptyString for PathSegmentNZNC
safareli Feb 27, 2018
36c51c0
update unsafe usages
safareli Feb 27, 2018
802dd78
Add crashes for illegal unsafe port/ipv4 address constructions
garyb Feb 28, 2018
4614557
Fix illegal port in tests
garyb Feb 28, 2018
619ed07
Move namespace to just URI
garyb Feb 28, 2018
308c2ee
Add details about the new setup to the README
garyb Mar 1, 2018
c6b8cec
Add doc comments for Scheme / use NES internally
garyb Mar 1, 2018
e26df37
Use NES for UserInfo internally, decouple parser composition
garyb Mar 1, 2018
c4323cc
Decouple parser composition from component parsers
garyb Mar 1, 2018
678bbbe
Clean up NES usage in UserInfo
garyb Mar 1, 2018
4d993d7
Use NonEmptyString for RegName
garyb Mar 1, 2018
56975f1
Simplify tests slightly with `nes` helper
garyb Mar 1, 2018
b11ee9a
Add fragment doc comments
garyb Mar 1, 2018
9cbc350
Add query doc comments
garyb Mar 1, 2018
df188b5
Tweak wording and add examples in UserInfo
garyb Mar 1, 2018
35d0658
Add doc comments for RegName, and print function
garyb Mar 1, 2018
b4843b0
Doc comments for IPv4Address
garyb Mar 1, 2018
a6dfbc2
Add more `Gen`s, doc comments, tests
garyb Mar 1, 2018
2d2f264
Avoid redefining some token parsers & rename some
garyb Mar 2, 2018
0015d5a
Last few doc comments for common
garyb Mar 2, 2018
daae752
Authority doc comments, remove unused synonym
garyb Mar 2, 2018
23df58e
Wording consistency tweak
garyb Mar 2, 2018
78119e5
Doc comments for HostPortPair
garyb Mar 2, 2018
98e99ad
Port doc comments
garyb Mar 2, 2018
64478e6
Tweak examples of authority option types usage
garyb Mar 2, 2018
5d81aa9
HierarchicalPart doc comments
garyb Mar 2, 2018
6316dd0
Newtype instance for UserPassInfo
safareli Mar 2, 2018
f868610
Path doc comments (and added TODO for NEA note)
garyb Mar 2, 2018
8dbdf12
Make `Path` match path-abempty from the spec
garyb Mar 2, 2018
ae42bc5
Doc comments for path varieties
garyb Mar 2, 2018
2d3a801
Adjust some segment stuff for consistency
garyb Mar 2, 2018
131b869
The -> a
garyb Mar 2, 2018
18365fd
Path segment doc comments
garyb Mar 2, 2018
d3cc178
Remove `';'` from `keyPartChar`
safareli Mar 16, 2018
4fb7a71
use in QueryPairs tests
safareli Mar 16, 2018
58a08b7
Add common URI schemes
garyb Mar 19, 2018
5dd71e8
Scheme `fromString` should fail if input is not fully consumed
garyb Mar 19, 2018
8047c1b
Make `pctEncoded` return a `NonEmptyString`
garyb Mar 19, 2018
7e612b3
More doc comment changes
garyb Mar 19, 2018
ed35231
Export char parsers used for printEncoded, etc
garyb Mar 20, 2018
a0ee260
Fix accidental loss of `try` in `URIRef` parser
garyb Mar 20, 2018
4aec4c5
Doc comments for the extras
garyb Mar 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add doc comments for Scheme / use NES internally
  • Loading branch information
garyb committed Mar 1, 2018
commit c6b8ceccbfe0722fdf7594ee207952e489c77c96
33 changes: 27 additions & 6 deletions src/URI/Scheme.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,57 @@ import Data.Array as Array
import Data.Either (hush)
import Data.Maybe (Maybe(..))
import Data.String as String
import Data.String.NonEmpty (NonEmptyString)
import Data.String.NonEmpty as NES
import Partial.Unsafe (unsafeCrashWith)
import Text.Parsing.Parser (Parser, runParser)
import Text.Parsing.Parser.String (char)
import URI.Common (alpha, alphaNum)

-- | The scheme part of an absolute URI. For example: `http`, `ftp`, `git`.
newtype Scheme = Scheme String
newtype Scheme = Scheme NonEmptyString

derive newtype instance eqScheme ∷ Eq Scheme
derive newtype instance ordScheme ∷ Ord Scheme

instance showScheme ∷ Show Scheme where
show (Scheme s) = "(Scheme.unsafeFromString " <> show s <> ")"
show (Scheme s) = "(Scheme.unsafeFromString " <> show (NES.toString s) <> ")"

-- | Attempts to create a `Scheme` from the passed string. The scheme component
-- | of a URI has no escape sequences, so this function will return `Nothing`
-- | if an invalid value is provided.
-- |
-- | ``` purescript
-- | fromString "http" == Just (Scheme.unsafeFromString "http")
-- | fromString "git+ssh" == Just (Scheme.unsafeFromString "git+ssh")
-- | fromString "!!!" == Nothing
-- | fromString "" == Nothing
-- | ```
fromString ∷ String → Maybe Scheme
fromString = map Scheme <<< hush <<< flip runParser parseScheme

-- | Constructs a `Scheme` part unsafely: if the value is not an acceptable
-- | scheme a runtime error will be thrown.
-- |
-- | This is intended as a convenience when describing `Scheme`s statically in
-- | PureScript code, in all other cases `fromString` should be used.
unsafeFromString ∷ String → Scheme
unsafeFromString s = case fromString s of
Nothing → unsafeCrashWith $ "Got invalid scheme in unsafeFromString : `" <> show s <> "`"
Just s' → s'
Nothing → unsafeCrashWith $ "Scheme value is invalid: `" <> show s <> "`"

-- | A parser for the scheme component of a URI. Expects a scheme string
-- | followed by `':'`.
parser ∷ Parser String Scheme
parser = Scheme <$> parseScheme <* char ':'

parseScheme ∷ Parser String String
parseScheme ∷ Parser String NonEmptyString
parseScheme = do
init ← alpha
rest ← Array.many (alphaNum <|> char '+' <|> char '-' <|> char '.')
pure $ String.singleton init <> String.fromCharArray rest
pure $ NES.singleton init `NES.appendString` String.fromCharArray rest

-- | A printer for the scheme component of a URI. Prints a scheme value
-- | followed by a `':'`.
print ∷ Scheme → String
print (Scheme s) = s <> ":"
print (Scheme s) = NES.toString s <> ":"