diff --git a/makefile b/makefile index 59d6916..865a539 100644 --- a/makefile +++ b/makefile @@ -8,3 +8,13 @@ run: t: spago test + +docs: + spago docs + +DOCS_HTTPD_ACCESS_LOGS ?= /tmp/parser-docs-access.log +DOCS_HTTPD_ADDR ?= 127.0.0.1 +DOCS_HTTPD_PORT ?= 30000 +DOCS_DIR ?= generated-docs/html +serve-docs: docs + darkhttpd $(DOCS_DIR) --addr $(DOCS_HTTPD_ADDR) --port $(DOCS_HTTPD_PORT) --log $(DOCS_HTTPD_ACCESS_LOGS) diff --git a/src/GenericParser.purs b/src/GenericParser.purs index e186ea3..5fe5df1 100644 --- a/src/GenericParser.purs +++ b/src/GenericParser.purs @@ -1,7 +1,7 @@ module GenericParser ( module GenericParser.Parser - , module GenericParser.DomainParser + , module GenericParser.DomainParserRFC1035 ) where -import GenericParser.Parser (Position, PositionString, Input, Error, Value, Result, Parser(..), parse, current_position, failureError, failure, success, item, sat, digit, lower, upper, letter, alphanum, char, string, ident, nat, int, space, token, identifier, natural, integer, symbol, many1) -import GenericParser.DomainParser (Size, DomainError(..), let_dig, let_dig_hyp, ldh_str, max_label_length, max_domain_length, tryMaybe, try, label, subdomain, eof, sub_eof, domain) +import GenericParser.Parser (alphanum, char, current_position, digit, Error, failure, failureError, ident, identifier, Input, int, integer, item, letter, lower, many1, nat, natural, parse, Parser(..), Position, PositionString, Result, sat, space, string, success, symbol, token, try, tryMaybe, upper, Value) +import GenericParser.DomainParserRFC1035 (domain, DomainError(..), eof, label, ldh_str, let_dig, let_dig_hyp, max_domain_length, max_label_length, Size, subdomain, sub_eof) diff --git a/src/GenericParser/DomainParser.purs b/src/GenericParser/DomainParserRFC1035.purs similarity index 77% rename from src/GenericParser/DomainParser.purs rename to src/GenericParser/DomainParserRFC1035.purs index edbcaf3..0b42ec6 100644 --- a/src/GenericParser/DomainParser.purs +++ b/src/GenericParser/DomainParserRFC1035.purs @@ -1,5 +1,6 @@ --- | `DomainParser` is a simple parser for domain names as described in RFC 1035. -module GenericParser.DomainParser where +-- | `DomainParserRFC1035` is a simple parser for domain names as described in RFC 1035. +-- | See `DomainParser` for a more modern domain parser, accepting underscores in labels for example. +module GenericParser.DomainParserRFC1035 where import Prelude (bind, not, pure, ($), (&&), (*>), (<<<), (<>), (>), (-)) @@ -14,11 +15,14 @@ import Data.String.CodeUnits as CU import GenericParser.Parser (Parser(..) , success, failureError , current_position - , alphanum, char, letter, many1, parse, string) + , alphanum, char, letter, many1, parse, string + , try, tryMaybe) type Size = Int +-- | `DomainError` expresses all possible errors that can occur while parsing a domain. +-- | When an error occurs, the position is given by the Parser along the related `DomainError`. data DomainError - = SubdomainTooLarge Size + = LabelTooLarge Size | DomainTooLarge Size | InvalidCharacter | EOFExpected @@ -46,26 +50,6 @@ max_label_length = 63 max_domain_length :: Int max_domain_length = 255 --- | `tryMaybe` provides a way to accept a faulty parser and --- | just rewinds back to previous input state if an error occurs. -tryMaybe :: forall e a. Parser e a -> Parser e (Maybe a) -tryMaybe p = Parser p' - where p' input = case parse p input of - Left _ -> success input Nothing - Right { suffix, result } -> success suffix (Just result) - --- | `try` provides a way to accept a faulty parser and --- | just rewinds back to previous input state if a non-specific error occurs. --- | The difference with `tryMaybe` is that `try` will forward the error if it is --- | a specific one, meanning that `error` isn't `Nothing`. -try :: forall e a. Parser e a -> Parser e (Maybe a) -try p = Parser p' - where p' input = case parse p input of - Right { suffix, result } -> success suffix (Just result) - Left { position, error } -> case error of - Nothing -> success input Nothing - _ -> failureError position error - -- | From RFC 1035: