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

Error compiling java code generated by Ragel 6.7

I'm trying to use Ragel to write a simple Lexer, and output it to Java valid code, but the generated code does not compile. Here's the Lexer.rl that I'm using: public class Lexer { %%{ machine simple_lexer; integer =…
Lucas Sampaio
  • 1,568
  • 2
  • 18
  • 36
0
votes
1 answer

ragel parser is not greedy?

I'm trying to write an HTTP parser in C++ using ragel, but finding that the parser generated is not greedy. The first step is to parse a URL, and here is the ragel grammar translated from RFC-3986: #include #include #include…
balus
  • 1
  • 2
0
votes
1 answer

Ragel: How to return different values by matching different expressions

I'm looking for a function that returns different integer values by matching an input string for different expressions. Here is how it could be, but syntax: package main func MatchType(data []byte) int { %% machine scanner; %% write data; …
0
votes
1 answer

How to implement regex /cat[s]?(\b|$)/ with ragel correclty?

I want to speed up my program written in Go and convert regular expressions to finite state machines with ragel. I cannot figure out how to match end of input correctly when converting regular expressions similar to /cat[s]?(\b|$)/ (it matches a…
dimus
  • 8,712
  • 10
  • 45
  • 56
0
votes
1 answer

Extracting tokens out of ES6 template literals with Ragel

JavaScript contains the following syntax: `hello ${name}` I'm wondering how a Ragel machine would split the syntax above. The way I see it, the type of the closing curly brace depends on the parsing state. For example, in the code below the curly…
Maël Nison
  • 7,055
  • 7
  • 46
  • 77
0
votes
1 answer

What is the correct way to scan "Quoted String" in ragel?

I m trying learn ragel with go, but i am not able to find a proper way to scan a Quoted-string This is what i have defined dquote = '"'; quoted_string = dquote (any*?) dquote ; main := |* quoted_string => { …
Ronin Goda
  • 234
  • 5
  • 13
0
votes
1 answer

Difference between Ragel transition actions and state actions

State machines, the terminology, and the tools are all new to me, though I've been trying to wrap my head around them lately with various online resources. This started when I wanted to build a faster parser than regex in Ragel and Go. I'm stumped…
contrapsych
  • 1,919
  • 4
  • 29
  • 44
0
votes
1 answer

Intersection of two regular expressions in Golang using Ragel

The template of the function is as follows: func GetIntersection(firstRegex string, secondRegex string) string { ... } I'm trying to use Ragel to get the intersection of two regular expressions. Not sure if Ragel is the right tool to use,…
aygestan
  • 73
  • 1
  • 8
0
votes
1 answer

How to match against end-of-file?

I want to match either newline ("\n"), semi-colon (";") or eof as being a valid end of statement. The first two are obvious, e.g. eos = "\n" | ";"; but I'm not sure how to also match against the eof in the same way. Is there some way to match…
ioquatix
  • 1,411
  • 17
  • 32
0
votes
2 answers

fgoto on binary variable length protocol with ragel

I tried to write a parser to a simple binary protocol 0 or more out of frame bytes Start of frame with STX (0x02) Two messaje length bytes for messaje length. One command byte . 0 or more data bytes. One checksun byte. The ragel script static int…
0
votes
1 answer

What are the reasons for using Ragel to parse strings in a C++ codebase?

I inherited a C++ project which uses Ragel for string parsing. This is the first time I have seen this being done and I would like to understand why someone would use Ragel instead of C++ to parse a string?
Greg
  • 8,175
  • 16
  • 72
  • 125
0
votes
1 answer

Parsing an integer and HEX value in Ragel

I am trying to design a parser using Ragel and C++ as host langauge. There is a particular case where a parameter can be defined in two formats : a. Integer : eg. SignalValue = 24 b. Hexadecimal : eg. SignalValue = 0x18 I have the below code to…
gst
  • 1,251
  • 1
  • 14
  • 32
0
votes
1 answer

Lin Descriptor File parser

I am trying to research on the possible parsers, as part of developing a PC application that can be used for parsing a Lin Descriptor File. The current parser application is based on flex-bison parsing approach. Now I need to redesign the parser,…
gst
  • 1,251
  • 1
  • 14
  • 32
0
votes
1 answer

What is the DEF state in the Ragel (6.10) document illustrations

The Ragel 6.10 manual has many illustrations of the FSM it generates. Some of which show a state DEF. As best I can tell this is never defined/discussed. What is the DEF state? What are its implications? e.g. if it shows up in your FSM abc…
Hedgehog
  • 5,487
  • 4
  • 36
  • 43
0
votes
1 answer

Can Ragel perform individual command parsing and throw errors accordingly

I am trying to parse a command :LoadSdf 12 abc.ldf I am trying to get errors at each stage( :LoadSdf,12, abc.ldf ) of the command. But I get a different behaviour as shown in the later part of the question. Following is my Ragel pseudo code %% …
gst
  • 1,251
  • 1
  • 14
  • 32