Skip to content
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

Document matching end of line #30

Open
alexanderkjeldaas opened this issue Feb 10, 2016 · 7 comments
Open

Document matching end of line #30

alexanderkjeldaas opened this issue Feb 10, 2016 · 7 comments

Comments

@alexanderkjeldaas
Copy link

I couldn't find an example on how I match [0-9]+[.][0-9][0-9]$ - that is, match something at the end of a line.

@UnkindPartition
Copy link
Owner

Use the function to match the whole line, and include the equivalent of .* at the beginning of the pattern.

@alexanderkjeldaas
Copy link
Author

Not sure if this is a good idea, as it isn't very composable.

Say I want to match "(foo($| )|bar)" then now I have to rewrite it to
"(foo ?|bar.*)" that last expression is no longer composable as the first one was.

@UnkindPartition
Copy link
Owner

Well, it is the way at the moment.

I don't have the resources to investigate whether and how this can be implemented, but you can look into it yourself if you wish.

@demokritos
Copy link

I wanted to remove 'index.html' from string. I found out that the following code was working:

stripIndex :: String -> String
stripIndex = takeWhile (/= '\0') .
             replace ((:) <$> sym '/'
                          <*  string "index.html"
                          <*> (concat <$> many query)
                          <*  sym '\0') .
             (++ "\0")
  where
    isDelim = (`elem` ['/', '#', '?'])
    query   = (:) <$> (sym '#' <|> sym '?') <*> many (psym $ not . isDelim)

By generalizing this, can we solve this issue?

@UnkindPartition
Copy link
Owner

@demokritos why do this instead of #30 (comment)?

@demokritos
Copy link

Did you mean this?

stripIndex :: String -> String
stripIndex str = fromMaybe str $
                 match ((\a b c -> a ++ b : c) <$> many anySym
                                               <*> sym '/'
                                               <*  string "index.html"
                                               <*> (concat <$> many query)) str
  where
    query   = (:) <$> (sym '#' <|> sym '?') <*> many (psym (/= '/'))

I didn't know that match can replace.

I wonder whether the syntax below is possible by introducing special boundary indicators.

stripIndex = replace ((:) <$> sym '/'
                          <*  string "index.html"
                          <*> (concat <$> many query)
                          <*  EndOfLine)

Thanks.

@UnkindPartition
Copy link
Owner

Yeah, I think it could be possible.

My answer is the same as 4 years ago (wow, time flies!): I'd consider a carefully motivated and implemented pull request, but I don't have the resources to look into this myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants