|
|
Ragel compiles executable finite state machines from regular languages. Ragel targets C, C++, Objective-C, D, Java and Ruby. Ragel state machines can not only recognize byte sequences as regular expression machines do, but can also execute code at arbitrary points in the recognition of a regular language. Code embedding is done using inline operators that do not disrupt the regular language syntax.
The core language consists of standard regular expression operators (such as union, concatenation and Kleene star) and action embedding operators. The user's regular expressions are compiled to a deterministic state machine and the embedded actions are associated with the transitions of the machine. Understanding the formal relationship between regular expressions and deterministic finite automata is key to using Ragel effectively.
Ragel also provides operators that let you control any non-determinism that you create, construct scanners, and build state machines using a statechart model. It is also possible to influence the execution of a state machine from inside an embedded action by jumping or calling to other parts of the machine, or reprocessing input.
Ragel provides a very flexible interface to the host language that attempts to place minimal restrictions on how the generated code is integrated into the application. The generated code has no dependencies.
action dgt { printf("DGT: %c\n", fc); } action dec { printf("DEC: .\n"); } action exp { printf("EXP: %c\n", fc); } action exp_sign { printf("SGN: %c\n", fc); } action number { /*NUMBER*/ } number = ( [0-9]+ dgt ( '.' dec [0-9]+ dgt )? ( [eE] ( [+\-] exp_sign )? [0-9]+ exp )? ) number; main := ( number '\n' )*; | => | st0: if ( ++p == pe ) goto out0; if ( 48 <= (*p) && (*p) <= 57 ) goto tr0; goto st_err; tr0: { printf("DGT: %c\n", (*p)); } st1: if ( ++p == pe ) goto out1; switch ( (*p) ) { case 10: goto tr5; case 46: goto tr7; case 69: goto st4; case 101: goto st4; } if ( 48 <= (*p) && (*p) <= 57 ) goto tr0; goto st_err; |
| || \/ |

| [1] | Adrian D. Thurston. "Parsing Computer Languages with an Automaton Compiled from a Single Regular Expression." In 11th International Conference on Implementation and Application of Automata (CIAA 2006), Lecture Notes in Computer Science, volume 4094, pp. 285-286, Taipei, Taiwan, August 2006. pdf. |
Ragel has a user guide available in PDF format as well as a man page. Major version number releases contain language changes. See the ChangeLog and Release Notes for details.
If you use Vim, there is a syntax file ragel.vim for your editing pleasure. If you use TextMate there is a Ragel bundle Ragel.tmbundle.
The Ragel mailing list is available here: ragel-users. Ask for help, post parsing problems, or tell us what you think of Ragel.
|
|
|
Clang: a scanner for a simple C like language. clang.rl Mailbox: parses unix mailbox files. It breaks files into separate messages, the headers within messages and the bodies of messages. mailbox.rl AwkEmu: performs the basic parsing that the awk program performs on input. awkemu.rl Atoi: converts a string to an integer. atoi.rl Concurrent: performs multiple independent tasks concurrently. concurrent.rl |
StateChart: the Atoi machine built with the named state and transition list paradigm. statechart.rl GotoCallRet: demonstrates the use of fgoto, fcall, fret and fhold. gotocallret.rl Params: parses command line arguments. params.rl RagelScan: scans ragel input files. rlscan.rl CppScan: A c++ scanner that uses the longest-match method of scanning cppscan.rl |
|
Development Version: Please use this for creating patches. Tar.Gz: The latest release is version is ragel-6.5.tar.gz (sig). Older: Previous versions are available here. Debian: The homepage for the Debian package of Ragel is here. It is by Robert Lemmen. OpenPKG: Ragel has been included in the OpenPKG project. FreeBSD: A port for Ragel is available in the FreeBSD ports system. NetBSD: There is a package for Ragel in the pkgsrc database. |
Mac OS X: A port is available in the MacPorts repository. Crux: A port for the Crux Linux distribution is available here. Gentoo: A Gentoo port is available. Suse: Packages for Suse can be found here. Windows: Ragel can be compiled using Cygwin or MinGW. Binaries compiled with visual studio are here (6.4+ r766), provided by Joseph Goettgens. Redhat/Fedora: A package for Ragel is available in Fedora Extras. Slackware: A package is available at LinuxPackages.net |
| Version: | 6.5 |
| Date: | May 18, 2009 |
| Change Log: | ChangeLog |
| Tar.Gz: | ragel-6.5.tar.gz (sig) |
| Zip: | ragel-6.5.zip (sig) |
| User Guide PDF: | ragel-guide-6.5.pdf |
The public key for package signing is here.
Ragel is released under the GNU General Public License. A copy of the license is included in the distribution. It is also available from GNU.
Note: parts of Ragel output are copied from Ragel source covered by the GNU GPL. As a special exception to the GPL, you may use the parts of Ragel output copied from Ragel source without restriction. The remainder of Ragel output is derived from the input and inherits the copyright status of the input file. Use of Ragel makes no requirements about the license of generated code.
Ragel was written by Adrian Thurston. It was originally developed in early 2000 and was first released January 2002. Many people have contributed feedback, ideas and code. Please have a look at the CREDITS file.