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
1
vote
1 answer

Optimize Ragel semantic conditions for any data of known length

There is an example in Ragel manual 6.5 Semantic conditions, which demonstrates how to write a grammar for variable size structures, using when clause. action rec_num { i = 0; n = getnumber(); } action test_len { i++ < n } data_fields = ( ’d’ [0-9]+…
Andrew Selivanov
  • 1,306
  • 15
  • 22
1
vote
1 answer

What is the correct way to use a stack with a scanner block in Ragel?

I'm using Ragel 6.10 with Go. I'm sure it's likely an issue with my code but I'm getting some weird errors when I try to use a stack with a scanner block. I'm trying to setup bracket matching and my code looks roughly like this; ObjectValues := |* …
Nathan
  • 553
  • 4
  • 11
1
vote
1 answer

Issues with parsing 'newline' in Ragel

I am using Ragel and C++ as host to parse a few commands. The commands are read from a file and then parsed using the following syntax. The syntax of the command is as follows: Signal_representation { [: ([,…
gst
  • 1,251
  • 1
  • 14
  • 32
1
vote
1 answer

Ragel Parse Key Value Pairs Without delimiter for EOF

So I have a simple string that I was hoping to run through a ragel state machine. key1=value1; key2="value2"; key3=value3 Here is a simplified version of my ragel # Key Value Parts name = ( token+ ) %on_name ; value = ( ascii+ -- (" " | ";" |…
Matt Edwards
  • 133
  • 1
  • 6
1
vote
1 answer

What is the best way to capture ambiguous segments of text?

What would be the best way to capture the inner text in the following case? inner_text = any*; tag_cdata = 'cdata_start %cdata_end ']]>'; The problem is, it seems like the cdata_end action fires several times due to the fact…
ioquatix
  • 1,411
  • 17
  • 32
1
vote
2 answers

My first cup of Ragel

I'm writing my first Ragel program. My goal is to write a Four function calculator. Please do not send me your code. This is intended to be a learning experiance for me. What I want to do is to match a regular expression with a float and print…
stuart
  • 39
  • 1
1
vote
1 answer

Ragel: How to match everything not matched by something else?

I have implemented a pretty simple parser using Ragel. The "main" structure is a scanner. I have something like this implemented: action doSomething { doSomething(fpc); } foo = 'foo'; bar = 'bar'; main := |* foo => { matchFoo(); }; …
Dago
  • 1,349
  • 1
  • 11
  • 19
1
vote
1 answer

Ragel - how to return one token at a time

I want to build a one-token-per-call ragel grammar / thing. I'm relatively new to Ragel (but not new to compilers, etc). I've written a grammar for a json-like notation (three levels deep). It emits C code. My input comes in complete strings (no…
1
vote
1 answer

How to use ragel labels outside the scope of machine instantiation

When an action is executed I want the action to trigger a jump to another state under certain conditions. For code readability I'd also like to define the action outside of the machine instantiation. How can I access the state labels generated by…
monzie
  • 665
  • 1
  • 6
  • 12
1
vote
1 answer

Why my simple Ragel grammar use all memory and crash

I am trying to convert a set of regular expression from Adblock Plus rules into an optimized function I could call from C++. I was expecting to be able to use a lexer generator such as Ragel to do this but when I try with a very small set of Regex…
skyde
  • 2,816
  • 4
  • 34
  • 53
1
vote
2 answers

How do I prioritize two overlapping expressions? (Ragel)

I have 2 expression : ident = alpha . (alnum|[._\-])*; string = (printable1)+; # Printable includes almost all Windows-1252 characters with glyphs. main := ( ident % do_ident | string % do_string ) # The do_* actions have been defined, and…
Jerry B
  • 444
  • 6
  • 14
1
vote
2 answers

Encapsulating a (pure Ruby) Ragel parser for infinite streams?

I want to parse a continuous stream of bytes (from a socket) with a state machine using Ragel However, all the Examples I have found are either parsing a complete file in one pass (like the Gherkin lexer or are using Ragels C Target (like the…
levinalex
  • 5,889
  • 2
  • 34
  • 48
1
vote
1 answer

Ragel FSM for parsing SQL-like statements

I'm having a bit of a problem with Ragel, mostly due to still trying to grasp how the whole thing works. I'm trying to make a simple parser for a language similar to SQL (but less flexible), where you have functions (all uppercase), identifiers (all…
changelog
  • 4,646
  • 4
  • 35
  • 62
1
vote
1 answer

How to implement lookahead in Ragel

I have two states; one is a specific instance of the other, more general, state. I believe that the right way to avoid entering both states simultaneously is to implement lookahead with k>1, but I can't find any examples of how to do this. The…
gibbss
  • 2,013
  • 1
  • 15
  • 22
1
vote
1 answer

How to solve this ambiguity with Ragel?

I am trying to parse the following format: (identifier/)?identifier(/keyword)?, with the first identifier as well as the keyword optional. A keyword may not be used as an identifier. For example, if up is a keyword, then: simple matches the…
Sébastien Le Callonnec
  • 26,254
  • 8
  • 67
  • 80