This repository contains two closely related projects:
Colm (COmputer Language Machinery): A programming language designed for the analysis and transformation of computer languages. Influenced primarily by TXL.
Ragel: A state machine compiler that generates executable finite state machines from regular expressions and state machine specifications.
The two projects share components and have a build dependency, so a unified repository simplifies development and building. The significant links are:
src/libfsm/) -- finite state machine construction and manipulation, used by both Colm and Ragel.src/cgil/) -- written in Colm, used by both projects for target language code generation.src/ragel/*.lm), so Colm must build first to bootstrap Ragel.A transformation language has a type system based on formal languages.
Rather than defining classes or data structures, one defines grammars.
A parser is constructed automatically from the grammar, and the parser is used for two purposes:
In this setting, grammar-based parsing is critical because it guarantees that both the input and the structural patterns are parsed into trees from the same set of types, allowing comparison.
This is how Colm is greeting the world (hello_world.lm):
print "hello world\n"
Here's a Colm program implementing a little assignment language (assign.lm) and its parse tree synthesis afterwards.
lex
token id / ('a' .. 'z' | 'A' .. 'Z' ) + /
token number / ( '0' .. '9' )+ /
literal `= `;
ignore / [ \t\n]+ /
end
def value
[id] | [number]
def assignment
[id `= value `;]
def assignment_list
[assignment assignment_list]
| [assignment]
| []
parse Simple: assignment_list[ stdin ]
if ( ! Simple ) {
print( "[error]\n" )
exit( 1 )
}
else {
for I:assignment in Simple {
print( $I.id, "->", $I.value, "\n" )
}
}
More real-world programs parsing several languages implemented in Colm can be found in the grammar/ folder.
To immediately compile and run e.g. the hello_world.lm program from above, call
$ colm -r hello_world.lm
hello world
Run colm --help for help on further options.
$ colm --help
usage: colm [options] file
general:
-h, -H, -?, --help print this usage and exit
-v --version print version information and exit
-b <ident> use <ident> as name of C object encapulaing the program
-o <file> if -c given, write C parse object to <file>,
otherwise write binary to <file>
-p <file> write C parse object to <file>
-e <file> write C++ export header to <file>
-x <file> write C++ export code to <file>
-m <file> write C++ commit code to <file>
-a <file> additional code file to include in output program
-E N=V set a string value available in the program
-I <path> additional include path for the compiler
-i activate branchpoint information
-L <path> additional library path for the linker
-l activate logging
-r run output program and replace process
-c compile only (don't produce binary)
-V print dot format (graphiz)
-d print verbose debug information
Ragel compiles regular expressions and state charts to executable finite state machines. The generated code can be output in a variety of host languages.
C, C++, D, Java, Ruby, C#, Go, OCaml, Rust, Julia, JavaScript, GNU ASM x86-64, and Crack.
| Flag | Style |
|---|---|
-T0, -T1 |
Table-driven |
-F0, -F1 |
Flat table-driven |
-G0, -G1, -G2 |
Goto-driven |
Language-specific binaries are also available: ragel-c, ragel-go, ragel-rust, etc.
See the examples/ directory for sample Ragel programs.
For the documentation, install asciidoc and fig2dev as well.
$ ./autogen.sh
$ ./configure
$ make
$ make install
The colm program depends on GCC at runtime. It produces a C program as output, then compiles and links it with a runtime library. The compiled program depends on the colm library.
To find the includes and the runtime library to pass to GCC, colm looks at
argv[0] to decide if it is running out of the source tree. If it is, then the
compile and link flags are derived from argv[0]. Otherwise, it uses the install
location (prefix) to construct the flags.
$ make check
Test suites are under test/ with subdirectories for each component (colm.d, ragel.d, aapl.d, etc.).
There are vim syntax definition files colm.vim and ragel.vim.
Colm and Ragel are free software under the MIT license.
Please see the COPYING file for more details.
26.04.0-2026041...2026-04-29 |