Tuesday, June 29, 2010

Reia: Pluggable Parsers

One stand-out quality of the Ruby community is a fascination with obtaining and manipulating Ruby parse trees.  Such a fascination exists in many languages, but it's particularly weird in Ruby because until Ruby 1.9 there was no first-class way to obtain a Ruby parse tree.  People went spelunking with C code into Ruby's internals, ripping the parse tree right out and exposing it back to the Ruby environment.  Eventually Ruby parsers were implemented in Ruby itself in various projects.  Yet it remains that while Ruby as a language seems to attract parse tree tinkerers, the language itself does not provide first-class ways to satisfy their needs.

I firmly believe that being able to obtain a parse tree for the programming language you're using is important and should be a first-class language feature.  To that end, Reia supports a String#parse method:

>> "2+2".parse()
=> [(:binary_op,1,:'+',(:integer,1,2),(:integer,1,2))]

This parses the "2+2" string as Reia source code.  The result might remind you a little bit of Lisp: it's a Reia parse tree.  Right now there aren't immediate uses for Reia parse trees, but I'd soon like to add an interface for compiling/executing them.  Erlang supports a feature called "parse transforms" which allow on-the-fly transformations of Erlang syntax.  I'd also like to add such a feature to Reia.

If String#parse were just used to parse Reia source code it'd be a bit of a waste.  However, it can be used for more than just that.  For example, parsing JSON (as of tonight):

>> '{"foo": [1,2,3], "bar": [4,5,6]}'.parse(:json)    
=> {"foo"=>[1,2,3],"bar"=>[4,5,6]}

After some recent problems dealing with JSON libraries in Ruby, I really felt JSON parsing should be part of the standard library.  With this syntax, it almost feels like JSON parsing is part of the core language.  Rubyists generally implement that sort of thing by monkeypatching the core types.  Reia lets anyone define their own String#parse method by defining special module names, with no modifications to the core types required (which Reia doesn't let you do anyway).

To better understand how this works, let's take a look at how Reia implements String#parse:

def parse(format)
  "#{format.to_s().capitalize()}Parser".to_module().parse(self)
end

Given a format of :foobar, String#parse will capitalize the argument into "Foobar", then look for a "FoobarParser" module to parse itself with.  This means anyone can add a parser to the language just by defining a module name that ends with "Parser" and has a parse method which accepts a string as an argument.

In short, anyone can add a parser to the language which can be called with a simple, elegant syntax.  No monkeypatching required.

38 comments:

Unknown said...

The above thought is smart and doesn’t require any further addition. It’s perfect
thought from my side.

==============
top bpo porject in india

Unknown said...

This is a wonderful opinion. The things mentioned are unanimous and needs to be
appreciated by everyone.

============
Bpo Project Available

Knodi said...

Love it, love it, love it

Unknown said...

Thanks for the good things

Good luck
دانلود نرم افزار ویرایشگر دیجیتالی تصاویر – Adobe Photoshop Lightroom 6.0 Final
دانلود آنتی ویروس بایدو Baidu Antivirus 5.4.3.118812
دانلود نرم افزار پاکسازی هارد دیسک – Wise Disk Cleaner 8.44 Build 598

shina said...

cctv camera for home
Pestveda | Pest Control
Termite control
Surveillancekart | CCTV System
cctv installation services
best home security camera system

navya said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai

shabnam praveen said...

Call girls in Kolkata
Call girls in Chandigarh
Call girls in Chandigarh
Call girls in Gurgaon
Call girls in Chandigarh
Call girls in Chandigarh

shabnam praveen said...

Call girls in Lucknow
Call girls in Guwahati
Call girls in Mumbai
Call girls in Jaipur
Call girls in Jaipur
Call girls in Jaipur
Call girls in Bangalore

nhuthuy said...

Thanks for sharing, nice post! Post really provice useful information!

Giaonhan247 chuyên dịch vụ mua hộ hàng hàn quốcorder hàng hàn quốc về VN giá rẻ, hay dịch vụ order hàng đức vận chuyển ship hàng đức về việt nam hay dịch vụ nhận order hàng nhật giá rẻ trên amazon nhật bảnvận chuyển hàng trung quốc về việt nam giá rẻ nhất hiện nay.

anosh said...

عندما يحين وقت الاعتناء بالمكيف وتنظيفة يجب الحرص عند اختيار من يقوم بهذه المهمة الصعبة فإذا أخطأنا ولجأنا لغير المحترفين قد ينتج عن ذلك المزيد من الإضرار فهم ليسوا علي دراية بنوع المكيف أو الطريقة الصحيحة للتعامل معه كما أنهم قد يستخدمون منظفات مجهولة المصدر وغير أمنة تماما علي الصحة العامة وقد تسبب في تأكل جسم المكيف وتراكم الصدأ علي جوانبه مما يشوه مظهره الخارجي وتقليل كفاءته حتي يتوقف عن العمل نهائيا نتيجة الإهمال واللجوء للهواة لذا يجب أن نختار من هم آهل للثقة فشركة تنظيف مكيفات اسبليت بالرياض من أفضل الشركات في هذا المجال فهي الأولي في مجال تنظيف المكيفات بكل أنواعها فطاقم عملها مدرب علي أعلي مستوي ويحصل بشكل دوري علي دورات تدريبية تنظمها الشركة لتحديث كفاءتهم وطلباتهم علي كل ما هو جديد ارقام صيانة مكيفات اسبليت بالرياض
ادوات تنظيف مكيفات اسبليت
سعر غسيل مكيف اسبليت بالرياض
ارخص نجار بالرياض

siska said...

agen sakong online

Kale Co Jakim said...

Great Article
IEEE Final Year Projects for CSE
IEEE Project Centers in Chennai

truongmuunghenhan said...

Thanks for sharing, nice post! Post really provice useful information!

Giaonhan247 chuyên dịch vụ nước hoa pháp chính hãng với những quy định gửi hàng đi mỹ uy tín cho những dịch vụ mua hộ hàng mỹ uy tín và vận chuyển ship hàng từ mỹ về việt nam uy tín cùng với bảng giá ship hàng từ mỹ về việt nam uy tín.

Juliana Kho said...

daftar s128
m bluebet33
agen cbet
kiss918 indonesia
download osg777

live chat osg777

ahmed said...

Not all that is published on the social networking pages useful in the steps of cleaning, the most important steps you take during the cleaning:
شركة النجوم لخدمات التنظيف
شركة نقل عفش بمكة
شركة نقل اثاث بمكة
شركة عزل خزانات بمكة

Periocenter said...

Dental Implants The Woodlands

oasisproperties17 said...
This comment has been removed by the author.
oasisproperties17 said...

We likewise furnish 100% Placement Support with our tie ups with various MNC's and Consultancies, we help our understudies in placement by giving Mock Interviews, Interview Questions and Answers and Real-time case Scenarios utilized in live activities.

For More Info:- SAP PM Course in Gurgaon

dadyar said...

خانواده یکی از پایه های اصلی هر جامعه ای به شمار می رود. اما متاسفانه امروزه می توان به وضوح افزایش علل طلاق مثل مشکلات اقتصادی، اعتیاد و .. را دید و به طور حتم شاهد افزایش انواع طلاق نیز هستیم. اما واقعا تنها همین ها را باید برای طلاق در نظر داشته باشیم!
پس آن همه عشق و علاقه ای که در ابتدای زندگی بود چه می شود. شاید کمی عصبانی هستید و دارید زود تصمیم می گیرید.از خواننده خواهشمندیم کمی صبورانه و با تامل بیشتر به کاری که می خواهد انجام دهد فکر کند. از انواع طلاق می توان به طلاق رجعی و طلاق بائن اشاره کرد که طلاق بائن خود به شش قسمت تقسیم می شود. در این مقاله به اصلی ترین آن ها اشاره کرده ایم.
اقسام و انواع طلاق
طبق ماده 1143 قانون مدنی در کشور ما انواع طلاق بر دو شکل است: طلاق رجعی که در آن مرد اجازه رجوع دارد و طلاق بائن که در حقیقت دادخواست طلاق از طرف زن است و پس از طلاق مرد حق رجوع به زن را ندارد مگر تحت شرایطی که در ادامه توضیح داده خواهد شد.
طلاق رجعی
نوعی از انواع طلاق است که در ایام عده مرد به لحاظ شرعی و قانونی میتواند رجوع کند در حقیقت طلاق رجعی طلاق از طرف مرد است. طلاق رجعی، رابطه زوجیت را از بین نمیبرد مگر با دو عامل طلاق و انقضای عده
زن در مدت عده طلاق رجعی زوجه محصوب می گردد وباید تا پایان عده زن ومرد در یک منزل زندگی کنند، در این زمان که حدود سه ماه (سه طهر، طهر واحد شرعی محاسبه ی عده است که می توانید مقاله عده را در همین سایت بخوانید) است مرد موظف به دادن نفقه ی زوجه می باشد. اگر در این مدت مرد به زوجه رجوع کند که دیگر طلاق منتفی است ودر صورتی که چنین نشود در پایان عده جهت طلاق و ثبت به دفترخانه مراجعه می کنند.
به این موضوع مهم توجه داشته باشید که در صورت وقوع رجوع حداکثر تا یک ماه فرصت ثبت این موضوع در دفترخانه را دارید در غیر این صورت به حبس تعزیری و یا جزای نقدی محکوم خواهید شد.

Cho thuê xe tải chở hàng said...

Thanks for sharing, nice article!. Thank you
Proship là đơn vị uy tín chuyển cung cấp tới quý khách hàng các dịch vụ vận tải uy tín như: vận chuyển ô tô bắc nam, dịch vụ bốc xếp, dịch vụ ship cod, cho thuê kho vận chuyển xe máy, cho thuê xe tải tại tphcm, vận chuyển container bắc nam,... Các dịch vụ của Proship luôn nhận được sự đánh giá rất cao từ phía khách hàng đã sử dụng.

Nannie Co Pam said...

IEEE Project Domain management in software engineering is distinct from traditional project deveopment in that software projects have a unique lifecycle process that requires multiple rounds of testing, updating, and faculty feedback. A IEEE Domain project Final Year Projects for CSE system development life cycle is essentially a phased project model that defines the organizational constraints of a large-scale systems project. The methods used in a IEEE DOmain Project systems development life cycle strategy Project Centers in Chennai For CSE provide clearly defined phases of work to plan, design, test, deploy, and maintain information systems.


This is enough for me. I want to write software that anyone can use, and virtually everyone who has an internet connected device with a screen can use apps written in JavaScript. JavaScript Training in Chennai JavaScript was used for little more than mouse hover animations and little calculations to make static websites feel more interactive. Let’s assume 90% of all websites using JavaScript use it in a trivial way. That still leaves 150 million substantial JavaScript Training in Chennai JavaScript applications.

steve said...


شركة غسيل خزانات بالمدينة المنورة شركة غسيل خزانات بالمدينة المنورة
افضل شركة تنظيف منازل بالمدينة المنورة شركة تنظيف منازل بالمدينة المنورة

angelisaka97 said...

Permainan poker pastinya banyak di kalangan remaja hingga dewasa yang sangat menggemari permainan poker, apalagi dalam 1 id game ada banyak permainan kartunya silahkan kunjungi situs kami untuk merasakan kenyamanan dalam bermain.

daftar idnplay poker

poker idnplay

daftar idnplay poker pulsa

cara daftar idnplay

daftar idnplay poker deposit pulsa

deposit idnplay pakai pulsa

cara daftar poker idnplay

deposit idnplay poker deposit pulsa

daftar idn poker


turnamen coin idnplay

turnamen poker

turnamen idnplay

turnamen poker idnplay

tcoins

turnamen poker online

turnamen poker berhadiah uang tunai

cara mendaftar turnamen tcoins

cara daftar poker turnamen

aturan beramin turnamen coin


server idnplay

perbedaan idnplay dan pokerv

server idnplay

server pokerv

kelebihan idnplay

kelebihan pokerv

poker online

Midnight Partner said...

Best and Top Interior Designers in Gurgaon If you are confounded? Try not to stress. We offer a free conference to help you in settling on a choice with the best vision and quality that you merit.
||Best Modular Office Furniture in Gurgaon
||modular furniture manufacturerin gurgaon
||office furniture manufacturer in gurgaon
||Best Modular Kitchen Manufacturers In Gurgaon
||Best Modular Kitchen Manufacturers In Delhi
||Best Office Furniture In Gurgaon
||Best Office Furniture In Delhi
||Best Home Furniture Manufacturer in Gurgaon
||Best Home Furniture Manufacturer in Delhi
||Best Wooden Modular Almirah manufacturer in Gurgaon
||Best Wooden Modular Almirah manufacturer in Delhi
||Best Wooden Partition Manufacturers in Gurgaon
||Best Wooden Partition Manufacturers in Delhi
||Best False Ceiling Manufacturer In Gurgaon
||Best False Ceiling Manufacturer In Delhi
||Best Greed False Ceiling Manufacturer In Gurgaon
||Best Greed False Ceiling Manufacturer In Delhi

sara said...

مظلات وسواتر
افكار
مظلات
تركيب مظلات
سواتر
مظلات ساكو
قرميد
بيوت شعر
مظلات خشبية
خيام بيوت شعر
كلادينج

sara said...

شبوك
مظلات لكسان
برجولات
هناجر
مظلات
مظلات حدائق
مظلات مسابح
سواتر حديدية
حداد مظلات

sara said...


نظافة هود
نظافة هود
شركة تنظيف هود المطاعم
شركات تصنيع مداخن المطاعم
تركيب هود المطاعم
هود المطاعم
تنظيف هود مطاعم
تنظيف هود مطاعم
شركات تنظيف هود
شركات تنظيف هود

شركة نظافة
شركة تنظيف
شركات تنظيف

sara said...


----------------------
مقاول مكة
مقاول معماري مكة
مقاول بناء عظم
بناء عظم
مقاول بناء ملاحق
بناء ملاحق
ملاحق
مقاول جدة
مقاول معماري جدة
تشطيب تسليم مفتاح
بناء تسليم مفتاح
مقاول تسليم مفتاح
بناء عظم تسليم مفتاح
نموذج عقد تسليم مفتاح

sara said...

مقاول بناء فلل وعمائر
بناء فلل
بناء عمائر
مقاول بناء فلل
ترميم مباني

تشطيب فلل وعمائر
تشطيب فلل
تشطيب عمائر
مؤسسة مقاولات مكة
مقاولات مكة

مؤسسة مقاولات جدة
مقاولات جدة
هناجر
هناجر ومستودعات

sara said...

شركة نقل عفش
شركات نقل عفش

نقل العفش بالقنفذة
شركة نقل عفش بالقنفذة
شركة نقل عفش القنفذة

شركة نقل عفش بالليث
نقل عفش الليث

نقل العفش بالجموم
شركة نقل عفش بالجموم

دليل شركات نقل عفش بجدة
نقل عفش بجدة
نقل العفش بجدة
شركة نقل عفش بجدة

دليل شركات نقل عفش بمكة

sara said...

شركة نقل عفش بمكة

دليل شركات نقل عفش بالطائف
نقل العفش بالطائف
شركة نقل عفش بالطائف

نقل العفش بالخرمة
نقل اثاث بالخرمة
شركة نقل عفش بالخرمة

شركة نقل عفش بحرة
نقل العفش بحرة
نقل عفش بحره

شركة نقل عفش برابغ
نقل العفش برابع
نقل اثاث برابغ
شركات نقل العفش برابغ

شركة نقل عفش بخليص
نقل العفش بخليص
دليل شركات نقل عفش بخليص

sara said...

محترف الظل
مظلات
سواتر
مظلات اسطح
كلادينج
بيوت شعر
مظلات اسواق
برجولات
مظلات مسابح
مظلات مدارس

sara said...

مظلات خشبية
قرميد
سواتر خشبية
سواتر قماش
سواتر مدارس
مظلات مكة
هناجر
مظلات الشد الانشائي
مظلات هرمية
مظلات محترف الظل

customized gifts for him said...

accent pillows for gray couch
white canvas pillow cases
housewares pillow

Unknown said...

Welcome to best World Escort Directory. Find independent escorts girls and escorts agencies to fulfill your sexual desire.
Vancouver Escorts
Toronto Escorts
Ottawa Escorts
Montreal Escorts
Mississauga Escorts
Edmonton Escorts
Calgary Escorts

No #1 Gurgaon Escorts Service Agency-Gurugram said...




If you want a babe from the house of Escorts in Gurgaonthere are a few things you should know well before making a booking. Firstly our agency here at your city. In simple words is a cut above the rest because of the highly professional services we provide to our clients. Check our other Services...
Escorts Service in Gurgaon
Female Escorts in Gurgaon
Russian Call Girls in Gurgaon
Russian Escorts in Gurgaon
Call Girls in Gurgaon

JAson96 said...

components that transform raw data (textual or raw bytes) into JSON messages suitable for downstream enrichment and indexing. Data flows through the parser bolt via Apache Kafka and into the enrichments topology in Apache Storm.
URL: https://treeremovalmelbournearborists.com/ringwood/

Pankaj Singh said...

Nice blog. OGEN Infosystem is leading web design service Provider Company in delhi. Get the professional web design services and grow your business.
Web Designing Company in Delhi