A fast and flexible parser combinator library, accepting any input type that is an instance of an appropriate monoid subclass. [Skip to Readme]
ちょっとしたログ解析にHaskellのParsecを使ってました。 「行に特定の文字列が含まれていたら無視する」というよくある簡単なフィルタ処理です。C++のBoost.Spirit.Qiであれば *(qi::char_ - "[condition]") のように書く処理。これをParsecでやるには、manyTillを使えばいいようです。 import Text.Parsec import Text.Parsec.String parseText :: Parser () parseText = do manyTill anyChar (try (string "[condition]")) return () isIgnore :: String -> Bool isIgnore s = case (parse parseText "" s) of Left _ -> False Ri
Using text.parsec.indent to Parse an Indentation-Sensitive Language with Haskell’s Parsec Library I’ve been working on a toy language with Job Vranish. We decided that we wanted to use indentation to represent blocking instead of braces (like Python). We’re implementing our toy in Haskell using the Parsec parser-combinator library. Luckily, there’s a companion library that handles indentation pars
This webpage was generated by the domain owner using Sedo Domain Parking. Disclaimer: Sedo maintains no relationship with third party advertisers. Reference to any specific service or trade mark is not controlled by Sedo nor does it constitute or imply its association, endorsement or recommendation.
Haskell で parser を書くには (初心者編) 勝手に Haskell Advent Calendar 2011 Haskell Advent Calendar 2011 にはエントリーできませんでしたけど、一人寂しく「勝手に Haskell Advent Calendar 2011」を開催して、わくわくクリスマスを待ちたいと思います。 目的: Parsec3 と attoparsec の基本的使用法, Applicative スタイルを習得する 前置き: Haskell で parser を書くにはどうすればいいのでしょうか? 私は、これを勉強すべく情報源を探しましたが、一体どこからどう始めればいいのか分からず、非常に混乱しました。「この記事を読めば大体概要が全部分かる」という情報源が日本語でも英語でも見つけられなかったからです。なので自分でまとめてみることにしました。 (私
Many parser combinator libraries in Haskell (such as parsec) have both a Monad interface as well as an Applicative interface. (Actually, to be really useful, you also need MonadPlus along with Monad, or Alternative along with Applicative, in order to encode choice; from now on when I talk about Monad and Applicative note that I really have MonadPlus or Alternative in mind as well.) The Applicative
The document describes how to build a parser for Backus-Naur Form (BNF) grammars in Haskell using the attoparsec parsing library. It defines types and parsers to represent BNF syntax, rules, expressions, lists and terms. The parsers use functions like spaces, string, text from attoparsec to parse individual components and combine them using operators like <*>, <|> to build up the full BNF grammar
This document summarizes a presentation on text manipulation in Haskell using the parsec and attoparsec libraries. It discusses splitting strings, designing a split function recursively and with parsec, and comparing the parsec and attoparsec parsing libraries. It also covers the different text types in Haskell - String, ByteString, and Text - and when each would be used.Read less
Haskell Advent Calendar のためのエントリです。 Haskellのライブラリでlanguage-javaというものを見つけたのでご紹介です。 仕事のプログラムでJavaのコード生成を行なっているものがあり、現状ではテンプレートを穴埋めするような処理をPerlで行なっています。 しかしいろいろと要求が複雑になってくると、穴埋め処理のままではJavaのソースコード内の意味の整合を維持するのが次第に面倒になり、ソースコードの構造を意識した処理に置き換えたくなってきました。 Haskellにはそのようなコード生成向けライブラリが無いだろうかと探してみたのがきっかけでした。 http://hackage.haskell.org/package/language-java/ 現状だと4つのモジュールを含んでいます。 それぞれ、javaのレキサ (Language.Java.Lex
コンパイラ屋にとってのFizzBuzzであるbrainfuckを(今更)Haskellで実装してみる。 Haskell実装は型レベルで書いたりピュアに書いたり色々だけど、ここではParsec3の機能を使ってパースと評価を同時にやってみる。 参考サイトHaskell で Brainf*ck interpreter Brainfuck - Wikipedia Parsec 3活用事例: Keepalived構文チェッカ ソースmodule BrainFuck where import Text.Parsec import Control.Applicative hiding ((),many,optional) import Control.Monad.Trans (liftIO) import Control.Arrow (first, second) import Control.Mona
In my first of this pair of articles, I laid out some of the qualities I've been looking for in a parsing library. Before I dive back into detail, I want to show off some numbers. The new Attoparsec code is fast. What did I benchmark? I captured some real HTTP GET requests from a live public web server, averaging 431 bytes per request. I chucked them into a file, and measured the time needed to pa
正規表現を超えるの補足として、CSVファイルを例に挙げて考えてみる。 CSVファイルの定義は、RFC4180にある。 file = record *(CRLF record) [CRLF] record = field *(COMMA field) field = (escaped / non-escaped) escaped = DQUOTE *(TEXTDATA / COMMA / CR / LF / 2DQUOTE) DQUOTE non-escaped = *TEXTDATA TEXTDATA = %x20-21 / %x23-2B / %x2D-7E COMMA = %x2C CRLF = CR LF CR = %x0D LF = %x0A DQUOTE = %x22 これを Haskell の Parsec で書くと、ほとんどそのままの形で実装できる。 import Text.
Parsec には以下のようなコンビネーターが存在する。 many p -- p を 0 回以上 many1 p -- p を 1 回以上 count n p -- p を n 回 しかし、正規表現の"{min,max}"のような範囲指定はない。そこで実装してみた。 import ApplicativeParsec range :: Int -> Int -> GenParser tok st a -> GenParser tok st [a] range n m p = (++) <$> count n p <*> upto (m - n) p upto :: Int -> GenParser tok st a -> GenParser tok st [a] upto 0 _ = return [] upto n p = (:) <$> p <*> upto (n - 1) p <|>
■ [Haskell] 正規表現のパーサーをApplicativeで だいぶ昔にパーサーモナドの勉強のために書いた正規表現のパーサーをApplicativeを使って書き直してみました。 import Control.Applicative import Control.Arrow (first) import Prelude hiding (seq) newtype Parser input output = Parser { runParser :: input -> Maybe (output, input) } instance Functor (Parser input) where fmap f parser = Parser $ \i -> first f <$> runParser parser i instance Applicative (Parser input) wh
お台場のTOKYO CULTURE CULTUREで開かれたHaskellナイトというイベントで、ライトニングトーク「Haskellゴング」に出てでしゃべってきた。 Parsec 3活用事例: Keepalived構文チェッカ (Haskell Gong 2009)View more documents from ma0e. ソースコードはgithubで。 http://github.com/maoe/shiritori http://github.com/maoe/text-keepalived Parsec 3からモナド変換子の実装が入ったことで、パーザ内部でI/Oすることができるようになったため、include文のパーズが簡単になったというお話。text-keepalivedの方は仕事で使っています。アルバイトも募集しています。 Parsec 2に関する補足 id:kazu-yama
SQL parser and type checker, targets PostgreSQL SQL and PL/pgSQL. Pre alpha: works well and is stable for a subset of SQL, but there are lots of unfinished areas and the api is likely to change a lot from release to release at this time. Documentation, examples on the homepage: http://jakewheat.github.com/hssqlppp/. Changes here: https://github.com/JakeWheat/hssqlppp/blob/master/CHANGES [Skip to R
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く