Skip to content

blambeau/anagram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

= Anagram

Anagram aims investigating usefulness of quality Abstract Syntax Tree rewriting tools for 
achieving code generation-centric tasks. Anagram was initially a fork of the Treetop project 
which has given excellent foundations for Parsing Expression Grammars (PEG parsing) in Ruby. 
Anagram tries to go one step further, also providing tools for manipulating parsing results 
easily.

== Installing Anagram

As Anagram is still experimental, there is no official ruby gem so far. To install anagram,
you'll need to download the last build of anagram *and* wlang (version >= 0.8.0) from 
http://code.chefbe.net and install both gems with 'gem install'.

== Starting with Anagram

First of all, you'll need to be PEG grammars aware. To this, some excellent lectures are:
- http://treetop.rubyforge.org/ the home page of the Treetop project, providing a useful 
  tutorial on PEG parsing and the grammar format used by both Treetop and Anagram.
- http://en.wikipedia.org/wiki/Parsing_expression_grammar  a general article on PEG parsing.
- Ford, Bryan (September 2002). "Packrat Parsing: a Practical Linear-Time Algorithm with 
  Backtracking". Massachusetts Institute of Technology. Retrieved on 2007-07-27.
  
Then, install anagram and type 'anagram --help' or, if you have a grammar already written,
'anagram gen [--output PARSER_FILE] GRAMMAR'.

To use the generated parser, the following chunk of code could be useful:

  require 'rubygems'
  require 'anagram'
  
  parser = MyGrammar::Parser.new
  ast = parser.parse_file("a_path_to/a_file_you/need_to/parse.your_extension")
  puts ast.inspect
  
== Parsing result and rewriting

By default, parsers generated by Anagram give you an Abstract Syntax Tree (AST), which is 
in fact really concrete (any space of character of the source text exists in the parsing 
result). Read the documentation of the Anagram::Ast module for details about ASTs. The Ast
Rewriting framework documentation is worth reading too, jump to Anagram::Rewriting. Enjoy!

== Credits

This work is supported by the {department of computer science}[http://www.uclouvain.be/en-ingi.html] of the 
{University of Louvain}[http://www.uclouvain.be/en-index.html] (EPL/INGI, Universite Catholique de Louvain, 
UCL, Louvain-la-Neuve, Belgium).

This work was also partially supported by the Regional Government of Wallonia (ReQuest project, RW Conv. 315592
and GISELE project, RW Conv. 616425) and the MoVES project (PAI program of the Belgian government).

About

Reusable grammars, parsers and rewriting tools

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages