parslet

Parse markdown indented code block

女生的网名这么多〃 提交于 2019-12-24 13:42:00
问题 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. Code block continues after blank line. There can be any number of chunks, separated by not more than one blank line. In order to solve this I wrote a minimal example wich replaces the lines (including \n ) with a and blank lines ( \n\n ) with spaces, eg: a

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

不羁岁月 提交于 2019-12-24 04:42:08
问题 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 >> quote end rule(:string) { quoted( (escape_char >> any | quote.absent? >> any).repeat.as(:string) ) } end Obviously, It should parse double-qouted string. And it does. But following result seems strange for me. Parser.new.string.parse '""' This code returns {

Indentation sensitive parser using Parslet in Ruby?

断了今生、忘了曾经 提交于 2019-12-18 10:56:18
问题 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 level1child2 The resulting tree would look like so: [ { :identifier => "level0child0", :children => [] }, { :identifier => "level0child1", :children => [ { :identifier => "level1child0", :children => [] }, { :identifier => "level1child1", :children => [ {

Parslet word until delimeter present

ⅰ亾dé卋堺 提交于 2019-12-11 10:18:03
问题 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 {:wrd=>"otherthings"@0, :delim=>"^"@11} require 'parslet' class Mini < Parslet::Parser rule(:word) { match('[a-zA-Z]').repeat} rule(:delimeter) { str('^') } rule(:othercontent) { word.as(:wrd) >> delimeter.as(:delim) } root(:othercontent) end puts Mini.new

How to transform nested arrays string in json like string to structured object using parslet

萝らか妹 提交于 2019-12-11 06:47:46
问题 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 'parslet' class JSONLikeDataParser < Parslet::Parser rule(:l_map_paren) {str('{')} rule(:r_map_paren) {str('}')} rule(:l_list_paren) {str('[')} rule(:r_list_paren) {str(']')} rule(:map_entry_delimiter) {str(':')} rule(:val_delimiter) {str(',')} rule(

Indentation sensitive parser using Parslet in Ruby?

核能气质少年 提交于 2019-11-30 00:48:42
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 level1child2 The resulting tree would look like so: [ { :identifier => "level0child0", :children => [] }, { :identifier => "level0child1", :children => [ { :identifier => "level1child0", :children => [] }, { :identifier => "level1child1", :children => [ { :identifier => "level2child0", :children => [] } ] }, { :identifier => "level1child2", :children => [] }, ] }