Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CoPaR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Informatik 8
CoPaR
Commits
bd3e3a96
Commit
bd3e3a96
authored
6 years ago
by
Hans-Peter Deifel
Browse files
Options
Downloads
Patches
Plain Diff
Add new lexer primitive to parse hexadecimal numbers
parent
349b3755
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Copar/Parser/Lexer.hs
+8
-0
8 additions, 0 deletions
src/Copar/Parser/Lexer.hs
tests/Copar/Parser/LexerSpec.hs
+17
-0
17 additions, 0 deletions
tests/Copar/Parser/LexerSpec.hs
with
25 additions
and
0 deletions
src/Copar/Parser/Lexer.hs
+
8
−
0
View file @
bd3e3a96
...
...
@@ -23,6 +23,7 @@ module Copar.Parser.Lexer
,
signed
,
adouble
,
complex
,
hex
)
where
import
Data.Char
...
...
@@ -182,3 +183,10 @@ complex inner =
optionalNum
=
fmap
(
fromMaybe
0
)
.
optional
sumOf
p1
p2
=
(,)
<$>
signed
p1
<*>
optionalNum
(
mandatorySigned
p2
)
{-# INLINE complex #-}
-- | Parse a hexadecimal number consisting of the prefix "0x" followed by
-- hexadecimal digits (both upper and lower case).
hex
::
(
MonadParser
m
,
Integral
a
)
=>
m
a
hex
=
lexeme
(
string
"0x"
*>
L
.
hexadecimal
)
{-# INLINE hex #-}
This diff is collapsed.
Click to expand it.
tests/Copar/Parser/LexerSpec.hs
+
17
−
0
View file @
bd3e3a96
...
...
@@ -13,6 +13,7 @@ spec :: Spec
spec
=
do
spaceSpec
complexSpec
hexSpec
spaceSpec
::
Spec
spaceSpec
=
describe
"whitespace"
$
do
...
...
@@ -128,3 +129,19 @@ complexSpec = describe "complex" $ do
it
"parses a sum without whitespace"
$
p
"-8.5-8.5i"
`
shouldParse
`
((
-
8.5
)
:+
(
-
8.5
))
hexSpec
::
Spec
hexSpec
=
describe
"hex"
$
do
let
p
=
parse
(
L
.
hex
<*
eof
)
""
it
"parses uppercase digits"
$
p
"0xDEADBEEF"
`
shouldParse
`
(
0xdeadbeef
::
Word
)
it
"parses lowercase digits"
$
p
"0xdeadbeef"
`
shouldParse
`
(
0xdeadbeef
::
Word
)
it
"parses mixed digits"
$
p
"0xdeadBEEF"
`
shouldParse
`
(
0xdeadbeef
::
Word
)
it
"required the 0x prefix"
$
p
`
shouldFailOn
`
"deadbeef"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment