Parslet is a parsing Ruby library based on PEG (Parsing Expression Grammar)
Questions tagged [parslet]
35 questions
1
vote
2 answers
Parslet : exclusion clause
I am currently writting a Ruby parser using Ruby, and more precisely Parslet, since I think it is far more easier to use than Treetop or Citrus. I create my rules using the official specifications, but there are some statements I can not write,…
user740316
1
vote
1 answer
Trying to group terms by OR operator
I am trying to parse a string so that I can easily identify terms that are separated by " OR ".
I currently have the following rules and parser class setup:
class Parser < Parslet::Parser
rule(:space) { str(' ').repeat(1) }
rule(:word) …

patrick
- 9,290
- 13
- 61
- 112
1
vote
1 answer
How to transform nested arrays string in json like string to structured object using parslet
I have a problem with transforming parsed JSON-like string, which contains nested arrays, to structured object. I am using parslet to do this.
I created parser and transformer, presented below. But I can't handle nested arrays situation.
require…

Mateusz Fryc
- 83
- 7
1
vote
1 answer
How do I parse rtf text using ruby and parslet?
I have the following data from a rich text format (RTF) file:
{\rtf1\ansi\deff3\adeflang1025\n{\fonttbl{\f0\froman\fprq2\fcharset0
Times New Roman;}{\f1\froman\fprq2\fcharset2
Symbol;}{\f2\fswiss\fprq2\fcharset0
…

Davie Overman
- 114
- 1
- 13
1
vote
2 answers
Capturing escaped multi-line syntax with Parslet and Ruby
I want to write a parser with Parslet in Ruby that understands a somewhat simple configuration syntax:
alpha = one
beta = two\
three
gamma = four
From the perspective of the parser, the backslash escapes the new line, so when parsed the value of…

pat
- 16,116
- 5
- 40
- 46
1
vote
1 answer
Ruby:parslet for a system verilog interface parser
I am using Ruby::Parslet.
I am parsing a document similar to an SV interface, eg:
interface my_intf;
protocol validonly;
transmit [Bool] valid;
transmit [Bool] pipeid;
transmit [5:0] incr;
transmit [Bool] …

justrajdeep
- 855
- 3
- 12
- 29
1
vote
2 answers
Parslet grammar for rules starting identical
I want to provide a parser for parsing so called Subversion config auth files (see patch based authorization in the Subversion red book). Here I want to define rules for directories like
[/]
* = r
[/trunk]
@PROJECT = rw
So the part of the grammar…

mliebelt
- 15,345
- 7
- 55
- 92
1
vote
2 answers
in Parslet, how to reconstruct substrings from parse subtrees?
I'm writing a parser for strings with interpolated name-value arguments, e.g.: 'This sentence #{x: 2, y: (2 + 5) + 3} has stuff in it.' The argument values are code, which has its own set of parse rules.
Here's a version of my parser, simplified to…

rcrogers
- 2,281
- 1
- 17
- 14
1
vote
1 answer
How do I get Parslet to tell the the char that failed?
I've got the following in Parslet.
'] at line 1 char 27.
| |- Expected "\n", but got "\\" at line 1 char 27.
| `- Expected "\r\n", but got "\\n" at line 1 char 27.
which I'm slightly confused about as there isn't two slashed in the…

Simmo
- 1,717
- 19
- 37
1
vote
1 answer
Parslet double negation
When parsing quotes and escapes (cf. Why does Parslet (in Ruby) return an empty array when parsing an empty string literal?) I came across an oddity in Parslet: (escape_char.absent? >> str('"')).absent? >> any It seems that Parslet actually…

JMH
- 1,289
- 1
- 10
- 19
1
vote
2 answers
Ruby: How to generate lines of code inside a program?
I am developing a parser in Ruby using the parslet library.
The language I am parsing has a lot of keywords that can be merged into a single parsing rule like this:
rule(:keyword) {
str('keyword1') |
str('keyword2') |
…

zml
- 617
- 7
- 14
1
vote
1 answer
How do I split an atom in Parslet?
I'm building an SQL-like query language. I would like to be able to handle lists of items delimited by commas. I have successfully achieved this with this code:
class QueryParser < Parslet::Parser
rule(:space) { match('\s').repeat(1) }
…
user2005477
1
vote
1 answer
Parslet word until delimeter present
I'm just starting with ruby and parslet, so this might be obvious to others (hopefully).
I'm wanting to get all the words up until a delimiter (^) without consuming it
The following rule works (but consumes the delimeter) with a result of…

Sam J
- 714
- 1
- 9
- 15
1
vote
2 answers
Is backreference available in Parslet?
Is there a way to backreference a previous string in parslet similarly to the \1 functionality in typical regular expressions ?
I want to extract the characters within a block such as:
Marker SomeName
some random text, numbers123
and symbols…

zml
- 617
- 7
- 14
1
vote
3 answers
Parslet: SystemStackError: stack level too deep
I am working on a new programming language rip, and I'm having trouble getting to the bottom of some infinite loops. Is there a way to print out each rule as it gets called, such that I can see the rules that are recursing? I've tried walking…

ravinggenius
- 816
- 1
- 6
- 14