facebook / facebook/duckling

Support for parser combinators

Đang mở
#27 7 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement help wanted
Ngôn ngữ chính
Haskell
Star
4.3k
Fork
740
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Many of the examples of regexes are reached the point where a parser combinator library would be a much better option - a prime example is the URL matcher which can easily be precisely defined using a parser combinator, while at the moment it's fairly ad hoc and loses a lot of information (the path doesn't work for URLs which contain usernames and passwords, something users might want to be able to match on to forbid or warn users who're posting URLs they shouldn't):

```haskell
ruleURL :: Rule
ruleURL = Rule
{ name = "url"
, pattern =
[ regex "((([a-zA-Z]+)://)?(w{2,3}[0-9]*\\.)?(([\\w_-]+\\.)+[a-z]{2,4})(:(\\d+))?(/[^?\\s#]*)?(\\?[^\\s#]+)?)"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (m:_:_protocol:_:domain:_:_:_port:_path:_query:_)):
_) -> Just . Token Url $ url m domain
_ -> Nothing
}
```

(For this specific example, the Network.URI package [already provides](https://hackage.haskell.org/package/network-2.3/docs/Network-URI.html#g:2) `parseURI :: String -> Maybe URI`)

I don't have an implementation for this yet (nor a preference for combinator library) because I don't fully understand how duckling all fits together, and wanted to open this to start discussion about it.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.