Tag: parslet

解析markdown缩进代码块

我试图使用Parslet编写的语法解析Markdown。 但是,我无法通过缩进的代码块,因为我到目前为止尝试的所有东西都被卡在递归中。 它们看起来像这样: 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. 为了解决这个问题,我写了一个最小的例子,用空格替换行(包括\n )和空行( \n\n ),例如: a aaa aa 。 # recurring_group_parser.rb require ‘parslet’ require ‘rspec’ require ‘parslet/rig/rspec’ class RecurringGroupParser > space end rule :space […]

为什么Parslet(在Ruby中)在解析空字符串文字时会返回一个空数组?

我正在玩小册子。 这是一个简单的解析器,它向我展示了一些非显而易见的行为。 require ‘parslet’ class Parser > term >> quote end rule(:string) { quoted( (escape_char >> any | quote.absent? >> any).repeat.as(:string) ) } end 显然,它应该解析双重字符串。 确实如此。 但是以下结果对我来说似乎很奇怪。 Parser.new.string.parse ‘””‘ 此代码返回{:string=>[]} 。 为什么在那里empty array而不是empty string ? 我错过了什么? 我正在使用ruby 2.1.1和parslet 1.6.1

在Ruby中使用Parslet的缩进敏感解析器?

我试图使用Ruby中的Parslet库解析一个简单的缩进敏感语法。 以下是我尝试解析的语法示例: level0child0 level0child1 level1child0 level1child1 level2child0 level1child2 生成的树看起来像这样: [ { :identifier => “level0child0”, :children => [] }, { :identifier => “level0child1”, :children => [ { :identifier => “level1child0”, :children => [] }, { :identifier => “level1child1”, :children => [ { :identifier => “level2child0”, :children => [] } ] }, { :identifier => “level1child2”, :children […]