Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news. Parslet is a new "simple parser framework" for Ruby built by Kaspar Schiess. It follows the PEG (parsing expression grammar) style of parsing and its primary goals are to be simple, testable, and to have extensive and powerful error reporting features (something that Kaspar states Treetop sorely lacks). If you've already u
require 'parslet' include Parslet # Constructs a parser using a Parser Expression Grammar parser = str('"') >> ( str('\\').ignore >> any | str('"').absent? >> any ).repeat.as(:string) >> str('"') result = parser.parse %Q("this is a valid \\"string\\"") result # => {:string=>"this is a valid \"string\""@1} A small Ruby library for constructing parsers in the PEG (Parsing Expression Grammar) fashion
Scala基礎文法最速マスターを書こうか迷っていたら、既にyuroyoroさんに書かれてしまったので、ちょっと違う方向で。BNFを既に知っている人は、これを読めばPEGの基礎をマスターしてPEGを書くことができるようになるでしょう(ほんとか?)。 基本 Parsing Expression Grammar(PEG)はBNFに似ているけど、ちょっと(かなり?)違う文法の表記法です。BNFはその文法がどのような言語を表現しているかを定めるのに対して、PEGは入力がどのように解析されるかを定めます。PEGとBNFの一番大きな違いは、PEGには曖昧さが無いことです。たとえば、プログラミング言語のif文を表現する次の擬似BNFには曖昧さがあります。 statement ::= if_statement | ...; if_statement ::= IF LPAREN expr RPAREN sta
■ [ruby] Ruby用PEGパーザ、Treetopを使ってみる TreetopはRuby用のPEG(解析表現文法)のpackrat parserである。 よく分かってないけど、そういうものらしい。 PEGの特徴については適宜google検索してもらうとして(ひどい)、ここではTreetopを使って簡単な文法をパーズしてみた。 1. インストール gem install treetop Vim使いはvim用の色付けもインストールしておくと良いかも。 2. 文法を書く パーザといったら(異論もあろうが)四則演算である。リファレンスを参考に、とりあえず足し算だけの文法を定義してみよう。 dentaku.treetop: grammar Dentaku rule additive (number "+" number) / number end rule number [0-9]+ end
Treetop is a language for describing languages. Combining the elegance of Ruby with cutting-edge parsing expression grammars, it helps you analyze syntax with revolutionarily ease. sudo gem install treetop Intuitive Grammar Specifications Parsing expression grammars (PEGs) are simple to write and easy to maintain. They are a simple but powerful generalization of regular expressions that are easie
これまでPEGパーザコンビネータ作ってきた言語は、全て、レキシカルスコープの無名関数やそれに類似の機能を持っていたため、容易に作ることができましたが、C言語には無名関数のような機能が無いため、ちょっと頭をひねりました。とりあえず作ることを優先させたので、メモリ管理とか、ライブラリとしての再利用しやすいようにヘッダファイルに宣言を適切に分離するとか一切考慮してません。たとえば、動的なメモリ確保は、mallocした後、そのまま放置で、freeしてません。あと、C言語は普段使わないので、C言語バリバリに使っている方からすると、メモリ管理とか以外の基本的なところで、ツッコミどころ満載な気もするので、その辺も指摘していただければと思います。 #include <stdio.h> #include <string.h> #include <stdlib.h> #define RULE(name) Pa
Parsing Expression Grammar (PEG)をベースとした構文解析器を生成するパーサジェネレータMetalを作りました。Rubyで書かれており、Rubyのコードを生成します。 Metalの多くはOMeta: an Object-Oriented Language for Pattern MatchingをRubyに移植したものです。 Metalの特徴: Rubyでアクションが書ける オブジェクト指向(継承、Mix-in、委譲、オーバーライド、super) PEGの特徴はそのまま 曖昧さが無い 左再帰が書けない(いまのところ) メモ化する ソースコードはCodeRepos:/lang/ruby/metalにあるので、ガツガツいじれます。 使い方 Ruby gemsでインストールできます。 $ gem install metal 文法定義ファイルを書いて、metalコマンド
"Give him some of the biscuit which famous Rhodes has sent you." —Marcus Valerius Martialis 1 Motivation I was looking for a small and unstrict xml parser. Boost.Spirit and Boost.Xpressive showed a lot of functionality but made big executables. On the other hand, YARD written by Christopher Diggins was simple, small and fast. In time, I found that YARD and Boost.Range could be binded. It was nam
parser combinators for C++ Author: Alex Rubinsteyn Introduction The parsnip library allows you to build complex parsers from a rich set of parser primitives. This method of parser construction is inspired by parsec and other parser combinator libraries for Haskell and ML. Parsnip parsers use packrat parsing as their default parse strategy. Packrat parsing is a dynamic programming optimization of b
peg/leg — recursive-descent parser generators for C peg and leg are tools for generating recursive-descent parsers: programs that perform pattern matching on text. They processes a Parsing Expression Grammar (PEG) [Ford 2004] to produce a program that recognises legal sentences of that grammar. peg processes PEGs written using the original syntax described by Ford; leg processes PEGs written using
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く