RAA - syntax

syntax / 0.1

Short description: Syntax classes for specifying BNF-like grammar in Ruby
Category: Library/Parser
Status: prototype
Created: 2005-04-16 04:07:09 GMT
Last update: 2005-04-16 04:07:09 GMT
Owner: Eric Mahurin (Projects of this owner)
Homepage: not available
Download: http://raa.ruby-lang.org/cache/syntax/syntax.rb
License: Ruby's
Dependency:
None
Description:

These classes provide a way of specifying a BNF-like grammar directly in Ruby via operator overloading.

This is early code and the API is likely in flux. I would appreciate any suggestions/comments.

Here are some of the features of the stuff in
syntax.rb:

- allows for BNF-like syntax using operators (+:
sequence, |: alteration, *: loop, unary +/-:
positive/negative lookaheads, ===: compare to a
stream)
- defaults to inifinite lookahead (using a FLUSH
element can control it and where a syntax error is
reported)
- input stream could contain characters or any type of
generic tokens
- both a lexer and parser could be written using the
same classes
- defaults to outputting a parse tree as a multi-level
Array structure which can be converted back to the
original with simply the to_s method (wasn't
overridden).
- code can be associated with syntax objects to modify
the parse tree, qualify, or do the whole thing
- a variety of classes are there for matching atoms:
=== (character, range, string), includes?
(array/string set), [] (array/hash lookup)
- although there is no automatic backtracking like
regular expressions, you can get some of the same
effects with positive/negative lookaheads
- everything seems quite straightforward
- this a first cut. There are probably bugs. The API
probably isn't quite right. Features may be missing.

Edit this project (for project owner)

back to RAA top