-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
0c65c8f
commit dbec8c9
Showing
11 changed files
with
122 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Language.XML.Name | ||
|
||
import Data.String.Parser | ||
|
||
public export | ||
data Name = MkName String | ||
|
||
%name Name name | ||
|
||
export | ||
Show Name where | ||
show (MkName n) = n | ||
|
||
export | ||
Eq Name where | ||
MkName n1 == MkName n2 = n1 == n2 | ||
|
||
public export | ||
record QName where | ||
constructor MkQName | ||
namespacePrefix : Maybe Name | ||
localPart : Name | ||
|
||
%name QName name | ||
|
||
export | ||
Show QName where | ||
show (MkQName Nothing localPart) = show localPart | ||
show (MkQName (Just namespacePrefix) localPart) = show namespacePrefix ++ ":" ++ show localPart | ||
|
||
export | ||
Eq QName where | ||
n1 == n2 = n1.namespacePrefix == n2.namespacePrefix && n1.localPart == n2.localPart | ||
|
||
public export | ||
isNameStartChar : Char -> Bool | ||
isNameStartChar c = isAlpha c || c == '_' | ||
|
||
public export | ||
isNameChar : Char -> Bool | ||
isNameChar c = isAlphaNum c || c == '.' || c == '-' || c == '_' | ||
|
||
export | ||
name : Parser Name | ||
name = MkName <$> pack <$> [| satisfy isNameStartChar :: many (satisfy isNameChar) |] | ||
|
||
export | ||
qName : Parser QName | ||
qName = do | ||
n <- name | ||
Just localPart <- optional (char ':' *> name) | ||
| Nothing => pure $ MkQName Nothing n | ||
pure $ MkQName (Just n) localPart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Data.String.Parser | ||
|
||
import Language.XML.Name | ||
|
||
main : IO () | ||
main = do | ||
printLn $ MkName "body" | ||
printLn $ MkQName Nothing (MkName "body") | ||
printLn $ MkQName (Just $ MkName "html") (MkName "body") | ||
|
||
let Right (MkName "html", 4) = parse name "html" | ||
| fail => putStrLn "Error parsing XML name, got \{show fail}" | ||
|
||
let Right (MkQName Nothing (MkName "html"), 4) = parse qName "html" | ||
| fail => putStrLn "Error parsing XML name, got \{show fail}" | ||
|
||
let Right (MkQName (Just $ MkName "xml") (MkName "html"), 8) = parse qName "xml:html" | ||
| fail => putStrLn "Error parsing XML name, got \{show fail}" | ||
|
||
pure () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body | ||
body | ||
html:body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
. ../../testutils.sh | ||
|
||
basicTest Name.idr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters