Questions tagged [parslet]

Parslet is a parsing Ruby library based on PEG (Parsing Expression Grammar)

35 questions
10
votes
2 answers

Indentation sensitive parser using Parslet in Ruby?

I am attempting to parse a simple indentation sensitive syntax using the Parslet library within Ruby. The following is an example of the syntax I am attempting to parse: level0child0 level0child1 level1child0 level1child1 level2child0 …
RyanScottLewis
  • 13,396
  • 16
  • 56
  • 84
5
votes
2 answers

Ruby parslet: parsing multiple lines

I'm looking for a way to match multiple lines Parslet. The code looks like this: rule(:line) { (match('$').absent? >> any).repeat >> match('$') } rule(:lines) { line.repeat } However, lines will always end up in an infinite loop which is because…
Danyel
  • 2,180
  • 18
  • 32
3
votes
3 answers

How to define a fixed-width constraint in parslet

I am looking into parslet to write alot of data import code. Overall, the library looks good, but I'm struggling with one thing. Alot of our input files are fixed width, and the widths differ between formats, even if the actual field doesn't. For…
Jonathan
  • 2,043
  • 2
  • 13
  • 16
3
votes
2 answers

Parslet: recognise anything but a given keyword

I'm trying to write a Ruby/Parslet parser for Handlebars but I'm getting stuck with the {{ else }} keyword. To explain brieflt for those who do not use Handlebars, an if/else is written this way: {{#if my_condition}} show something {{else}} show…
Vincent
  • 620
  • 7
  • 19
3
votes
1 answer

Simple parslet parser for comma-delimited list does not work

Why does the following Parslet parser not work for parsing comma-delimited lists? When I parse, it gets stuck and does not provide an error message: class TestParser < Parslet::Parser rule(:name) { match['a-z'].repeat >> str(',').maybe } …
Sean Mackesey
  • 10,701
  • 11
  • 40
  • 66
3
votes
2 answers

How do I handle C-style comments in Ruby using Parslet?

Taking as a starting point the code example from the Parslet's own creator (available in this link) I need to extend it so as to retrieve all the non-commented text from a file written in a C-like syntax. The provided example is able to successfully…
zml
  • 617
  • 7
  • 14
2
votes
2 answers

Parse before storing in MVC

I'm getting started with parsing data and getting some structure from user supplied strings (mostly pulling out digits and city names). I've run a bit of code in the ruby interpreter, and now I want to use that same code in a web application. I'm…
pedalpete
  • 21,076
  • 45
  • 128
  • 239
2
votes
2 answers

Parslet Not parsing whole string

For the following Parslet Parser require 'parslet' require 'parslet/convenience' class Lines < Parslet::Parser rule(:open_tag) {str('[')} rule(:close_tag) {str(']')} rule(:data) {str('name') | str('name_id') } rule(:text) {…
Darshan Patel
  • 3,176
  • 6
  • 26
  • 49
2
votes
1 answer

Ruby & Lmstat : parslet and structured multi-line block : where to put the newline statement?

I have a Flexlm/Flexnet licenses service and I want parse the outputs of this service. All output are structured block of multi-lines. My first step is to parse the output of lmutil lmstat -c -a to have the usage of licences and…
Scapin
  • 123
  • 5
2
votes
1 answer

How do I use Parslet with strings not Parslet Slices

I've started using Parslet to parse some custom data. In the examples, the resulting parsed data is something like: { :custom_string => "data"@6 } And I've created the Transform something like rule(:custom_string => simple(:x)) { x.to_s } But it…
Simmo
  • 1,717
  • 19
  • 37
2
votes
1 answer

Parse markdown indented code block

I am trying to parse Markdown using a grammar written with Parslet. However, I cannot get past indented code blocks because everything I tried so far got stuck in recursion. They look like this: This is a indented code block. Second line. …
JMH
  • 1,289
  • 1
  • 10
  • 19
2
votes
1 answer

How to perform lookaheads in a PEG without making the rule too greedy?

I'm writing a parser in Parslet. In the file I want to parse, I have the following structure: Item #1 denis calls 20 anna raises 60 denis calls 40 Item #2 another player raises 60 anna calls 60 ... To parse the actions, I did the following: As I…
Denis Lins
  • 816
  • 7
  • 22
2
votes
1 answer

Why does Parslet (in Ruby) return an empty array when parsing an empty string literal?

I'm playing with parslet. This is trivial parser which shows me some non-obvious behavior. require 'parslet' class Parser < Parslet::Parser rule(:quote) { str('"') } rule(:escape_char) { str('\\') } def quoted(term) quote >> term >>…
Viacheslav Kovalev
  • 1,745
  • 12
  • 17
2
votes
2 answers

Parslet subtree doesn't fire

Resume (I shrinked down the following long story to the simple problem) tree = {:properties => [{:a => 'b'}, {:c => 'd'}]} big_tree = {:properties => [{:a => 'b'}, {:c => 'd'}], :moves => [{:a => 'b'}, {:c => 'd'}]} trans = Parslet::Transform.new…
Dahan
  • 163
  • 1
  • 10
2
votes
2 answers

Parslet Alternatives Not parsing whole string

I have the following specs it "parses a document with only an expression" do puts parser.document.should parse("[b]Hello World[/b]") end it "parses a document with only text" do puts parser.document.should parse(" Hello World") end …
DVG
  • 17,392
  • 7
  • 61
  • 88
1
2 3