Comments (6)
I added this code to address the issue, 6fec1a3:
(<++>) a b = (++) <$> a <*> b
(<:>) a b = (:) <$> a <*> b
number = many1 digit
subnumber = char '.' <:> number
versionnumber = number <|> number <++> subnumber
versionParser = (\x -> info{_version = read x}) <$> (string "Version: " *> versionnumber)
Ideally, this should be the parser many1 digit `sepBy` char '.'
to get things like version 8.4.3
, but this gives the type error, which I haven't followed through with yet:
• Couldn't match type ‘[Char]’ with ‘Char’
Expected type: Text.Parsec.Prim.ParsecT s u m String
Actual type: Text.Parsec.Prim.ParsecT s u m [[Char]]
• In the second argument of ‘(<$>)’, namely
‘(string "Version: " *> (many1 digit `sepBy` char '.'))’
In the expression:
(\ x -> info {_version = read x})
<$> (string "Version: " *> (many1 digit `sepBy` char '.'))
In an equation for ‘versionParser’:
versionParser
= (\ x -> info {_version = read x})
<$> (string "Version: " *> (many1 digit `sepBy` char '.'))
|
93 | versionParser = (\x -> info{_version = read x}) <$> (string "Version: " *> (many1 digit `sepBy` char '.'))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
from adblock2privoxy.
@qrilka If you have a moment, I have a educational Haskell question I’ve been unable to tackle.
We would like to parse version numbers like 8.4.3
.
The original code’s parser used many1 digit
, and would grab the 8
, but not the .4.3
.
I thought that the obvious fix would be to replace many1 digit
With many1 digit `sepBy` char ‘.’
. But this fails to compile on a mismatched type of String
versus [[Char]]
. So I hacked in the code block above that would parse 8.4
, and omit the .3
.
Why doesn’t the sepBy
work here?
from adblock2privoxy.
@essandess I'm not sure I understand your point about "not work" here - sepBy
works just as it's supposed to work - it constructs a list of values in the end with separator excluded, i.e. for "8.4.3"
you'll get ["8","4","3"]
. I see _version
is an Integer
and I wonder how could you store a multicomponent version there, something line [Int]
would be more sensible if number of version components is not fixed (though I don't yet know how you use that information)
from adblock2privoxy.
Thanks again for the Haskell n00b pointers @qrilka!
What I mean is that the code fragment many1 digit `sepBy` char ‘.’
does not compile in this statement:
-- versionnumber = many1 digit -- this compiles!
versionnumber = many1 digit `sepBy` char ‘.’ -- this doesn't compile!!!
-- versionnumber = (++) <$> many1 digit `sepBy` char ‘.’ -- this doesn't compile either!!!
versionParser = (\x -> info{_version = read x}) <$> (string "Version: " *> versionnumber)
What's the correct sepBy
(or equivalent) parser that will grab the string "8.4.3
" from a line that looks like:
Version: 8.4.3
Just to keep it simple, I'd like to parse the string alone, and ignore that fact that it is comprised of things that could be cast as Int
type.
In Python, this would be something like '.'.join(["8","4","3"])
, after the parser found the "Version: 8.4.3
" and sepBy
converted it to ["8","4","3"]
.
from adblock2privoxy.
@qrilka Thanks again for the pointer. I got it:
intercalate "." <$> many1 digit `sepBy` char '.'
from adblock2privoxy.
I didn't write anything here today :)
Theoretically you could do that in the parser already though it looks not quite pleasant:
λ> parse (do{d1 <- many1 digit; dotDs <- many1 $ (:) <$> char '.' <*> many1 digit; return $ concat (d1:dotDs)}) "" "18.4.3"
Right "18.4.3"
from adblock2privoxy.
Related Issues (20)
- adblock2privoxy segmentation fault HOT 2
- easylist go.*. rule breaks many sites HOT 5
- element hidding whitelists undesired behaviour HOT 1
- empty rules HOT 2
- disregarding information following $ HOT 2
- translated records get dot in front which has adverse effects HOT 3
- TODO: remove matched element conversion HOT 1
- adblock2privoxy compilation fail with GHC 8.4.3 HOT 12
- META: work plan for cureent issues HOT 1
- New feature: duplicate detection HOT 1
- unintended escape characters for [ and ] HOT 3
- update filterlist HOT 4
- Dead Download links. HOT 2
- Filters are not taken effect HOT 4
- Ad2p run breaks with "Illegal instruction" HOT 3
- The site https://projects.zubr.me/wiki/adblock2privoxyDownloads does not open HOT 1
- rsync: link_stat "/root/adblock2privoxy*" failed: No such file or directory (2) HOT 5
- Missing client-header tagger 'ab2p-elemhide-check-debug' HOT 2
- Installation: stack command fails with "specified targets matched no packages"
- *nix installation instructions not working as written HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adblock2privoxy.