- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有语法文件alexa_scrape.tt
:
grammar AlexaScrape
rule document
category_listing*
end
rule category_listing
category_line url_line*
end
rule category_line
category "\n"
end
rule category
("/" [^/]+)+
end
rule url_line
[0-9]+ ". " url "\n"
end
rule url
[^\n]*
end
end
我有一个试图使用它的 ruby 文件:
#!/usr/bin/env ruby -I .
require 'rubygems'
require 'polyglot'
require 'treetop'
require 'alexa_scrape.tt'
parser = AlexaScrapeParser.new
p( parser.parse("") || parser.failure_reason )
p( parser.parse("/x\n") || parser.failure_reason )
但我没有得到预期的结果:
SyntaxNode offset=0, ""
"Expected one of /, \n at line 2, column 1 (byte 4) after /x\n"
它正确解析空字符串(作为 document
的简单匹配,零 category_listing
),但无法解析 "/x\n"
(因为包含单个 category_listing
的文档本身具有零个 url_line
)。
我做错了什么?
最佳答案
看起来 category
中的正则表达式正在通过匹配 category_line
所需的空格前进......这样做:
rule category
("/" [^/\s]+)+ # or perhaps ("/" [^/\n]+)+
end
(而且,哇,Treetop 问题。这是 SO 历史上的第 47 个问题及其 400 万个问题。87,000 个 SO 问题中有一个被标记为 Treetop)。
关于ruby - 我的 Treetop 语法有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13650629/
我有一个只有两条规则的树顶语法: grammar RCFAE rule num [0-9]+ end rule identifier [a-z
我将如何在 Treetop 中做这样的事情? /.+?;/ 似乎唯一的方法是这样做: [^;]+ ';' 哪个有点丑......还有其他方式吗? .+? 似乎不起作用.. 最佳答案 默认情况下 PEG
我刚刚开始使用 TreeTop 来做解析工作。以下是令我困惑的片段: grammar Fortran rule integer [1-9] [0-9]* end
我有语法文件alexa_scrape.tt: grammar AlexaScrape rule document category_listing* end rule catego
我有这个规范: it 'can parse armies with only section headers' do list = <<-LIST :Core :Special :Om
我已经简化了在 Treetop 中表达的语法,并且我正在尝试使用自定义节点将解析器的输出过滤为 AST。 grammar Elem rule top lpar 'top' space
我有一个文件想用 Treetop 解析。如果我想解析整个东西,我会使用 rule document category_listing* end 我真的不想一次将整个文件读入内存。我知道我可以将解析
我正在尝试使用 Treetop解析 ERB 文件。我需要能够处理如下行: 既然 Treetop 是用 Ruby 编写的,而你用 Ruby 编写 Treetop 语法,那么 Treetop 中是否已
我已经定义了使用 Treetop 解析字符串和数字的简单语法,如下所示。 grammar Simple rule value number / string end
使用 Ruby 的正则表达式,我可以写/[0-9]{3,}/我不知道如何在树顶写这个,除了: rule at_least_three_digit_number [0-9] [0-9] [0-9]+
有没有人见过 treetop 的 vim 缩进文件? , Ruby 解析器/生成器?我找到了一个 vim 语法高亮文件,但还没有看到用于缩进的文件。 最佳答案 看起来很简单——我只是创建一个文件 ~/
我正在尝试使用 Ruby 的树顶打开 Packages.gz,但我在使关键字和值明确无误时遇到了麻烦。这是我的树顶语法: grammar Debian rule collection en
我是一名优秀的程序员,十分优秀!