作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设您只想使用 Perl 6 语法解析大文件的开头。为了避免将整个文件读成字符串,然后调用subparse
在绳子上。读取文件时是否可以进行子解析?
我在 Grammar
类中找不到任何 subparsefile()
方法,所以我猜这很难实现。但理论上应该是可能的,例如How do I search a file for a multiline pattern without reading the whole file into memory?
最佳答案
目前还不能。目前解析任何内容都需要整个字符串存在于内存中。
话虽如此,如果您知道图案可以扩展的最大行数,您可以执行以下操作:
my $max = 3; # maximum number of lines
for "textfile".IO.lines(:!chomp).rotor( $max => -$max + 1 ) -> @lines {
@lines.join.subparse( $grammar)
# and whatever you would like to do
}
这不是最快的方法,但它不必读取内存中的整个文件。
关于grammar - 对文件进行语法子解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47818495/
我是一名优秀的程序员,十分优秀!