Questions tagged [ragel]

Ragel finite-state-machine compiler

Ragel compiles a declarative machine description syntax into a source code file in Java, Ruby, or a bunch of C-like languages. In addition, Ragel can generate a graphviz .dot file containing a diagram of the states and interaction of the input machine.

Ragel can be used to generate general purpose Finite State Machines (FSMs), which are commonly used in embedded systems and in protocol-driven applications like telephony and internet servers.

Ragel can also be used to generate a "lexer" (or "scanner") - a piece of code that scans an input text and divides it into "tokens". This lexical analysis is traditionally the first step in interpreting or compiling computer languages:

input ->  lexer  ->  parser  ->  AST  ->  execution or code generation

Links

81 questions
2
votes
1 answer

Simple Ragel grammar with optional whitespace

Ragel is powerfull machine but I have trouble with 'optional' elements in a grammar. I have simple line with number or strings. The trouble is with whitespace. I dont know how put correctly optional whitespace between ',' and variable. Enter will be…
user7673439
2
votes
1 answer

Ragel - validate a String while Input

Assume we want to validate user input, while user is typing in a JTextField. For validating the user input, I wonder if I could use Ragel. Assume the input should follow this example regex: [a-z]{2,5}ABC[0-9]+ How can I do this with ragel? Can…
Kai Mechel
  • 753
  • 8
  • 19
2
votes
1 answer

Ragel alternative to fbreak; but without advance to next symbol?

I'm writing a program what parses HTML to extract URLs from there using Ragel. After finding URL I need to perform some actions on it, and then ready to process next URL. So I need to stop executing main loop at the URL end, execute some actions…
Amdei
  • 223
  • 3
  • 8
2
votes
0 answers

Using Ragel with streaming input to detect URLs?

I need to detect URLs efficiently in an input stream during typesetting. The URL detector will be part of the typesetting flow. It should accept one character at a time as input and should output one character at a time along with the URL the…
bright
  • 4,700
  • 1
  • 34
  • 59
2
votes
1 answer

Is it possible to invocate multiple machines in one Ragel file?

I'm creating a fairly simple parser which has no recursive structures or anything too challenging. What I would like to do is when I run in to a "command" I would like to call a separate parsing function (in host language) such as parseCommandType1…
Dago
  • 1,349
  • 1
  • 11
  • 19
2
votes
1 answer

abusing ragel, possibly need new approach / tool

I'm trying to use Ragel to implement a simple yes/no fsm. Unfortunately the language specification consists of the union of about a thousand regular expressions, with * operators appearing once or more in the majority of them. So, the number of…
paintcan
  • 703
  • 1
  • 6
  • 10
2
votes
1 answer

Every char action for column count in Ragel

What is the preferred way to implement a column counter in a Ragel finite state machine. If it makes any difference, my main machine is a scanner as defined in chapter 6.3 of the Ragel manual. I'm thinking probably that I just need to be able to…
brooks94
  • 3,836
  • 4
  • 30
  • 57
2
votes
3 answers

finite state machine compiler for C to simulate network protocols

I was looking for a good state machine compiler so as to test some custom networking protocols. I looked at a few tools already such as Yakindu, Ragel(compiler), SCXML(language) but I was not sure if any of them could be used for networking…
Shravan B
  • 37
  • 4
2
votes
1 answer

Basic Ragel parser

With a machine like this: main := (any+); When I feed it a chunk of data, more than 1 byte, it seems to consume only 1 byte before coming out (normally) of %%write exec block. I expect it to be greedy and consume all of the provided input. I can…
Setevik
  • 21
  • 2
2
votes
2 answers

Capturing fields with a Ragel parser

I'm thinking of using Ragel to generate a lexer for NMEA GPS data in an embedded system. I would have an arbitrary-sized buffer into which I'd read blocks of data from a UART, and for each read I'd pass that data into the lexer. I'd like to be able…
Isvara
  • 3,403
  • 1
  • 28
  • 42
2
votes
2 answers

String Interpolation in Ragel

I am trying to implement a language, and I'm using Ragel as a lexer (and bison as a parser). I would like to be able to support string interpolation within my language, but I'm not sure how to come about doing this. My lexer uses a scanner like the…
Jeremy Rodi
  • 2,485
  • 2
  • 21
  • 40
2
votes
1 answer

Ragel, final states, and EOF

I do not understand what Ragel considers a "final" state. IIRC the User's Guide says that states that are final before machine simplification remain final thereafter. When exactly is a state final, and how does one recognize this? Application: I'm…
gibbss
  • 2,013
  • 1
  • 15
  • 22
2
votes
1 answer

How ragel read the source from the file?

I do not know How ragel read the source from the file. All the examples I have seen read from stdin. Please can you show me an example in C of interfacing with Ragel where the program does not read from standard in?
whisper
  • 143
  • 2
  • 9
2
votes
3 answers

Pointers difference between C and C++

I've noted that the following C code give "warning: initialization discards qualifiers from pointer target type" but it still compiles and behave as expected (outputting 'W' char). #include int main(int argc, char *argv[]) { char…
Luky
  • 5,346
  • 4
  • 17
  • 15
2
votes
2 answers

Match the start of the file or a newline (Ragel)

I'm using ragel with C as the host language. I can recognise a newline simply with '\n', but I need to recognise the start of the file as an alternative. In other implementations of regex this could be given by \A or $, but $ is reserved for other…
Matt
  • 7,100
  • 3
  • 28
  • 58