使用 RegexParsers 解析空白/空格 [英] Parsing a blank / whitespace with RegexParsers

查看:31
本文介绍了使用 RegexParsers 解析空白/空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解析空白/空格有什么问题?

What is the problem with parsing the blank/whitespace?

scala> object BlankParser extends RegexParsers {
         def blank: Parser[Any] = " "
         def foo: Parser[Any] = "foo"
       }
defined module BlankParser

scala> BlankParser.parseAll(BlankParser.foo, "foo")
res15: BlankParser.ParseResult[Any] = [1.4] parsed: foo

scala> BlankParser.parseAll(BlankParser.blank, " ")
res16: BlankParser.ParseResult[Any] =
[1.2] failure: ` ' expected but ` ' found


 ^

scala>

推荐答案

scala 的词法分析器会丢弃空格.尝试覆盖 val skipWhitespace = false避免这种情况.

the lexer for scala throws blankspaces away. try override val skipWhitespace = false to avoid this.

问题已经解决了,所以看起来......用于嵌入在 html 中的语言的 Scala 解析器组合器或文本(如 php)

the question was already solved so it seems... Scala parser combinators for language embedded in html or text (like php)

这篇关于使用 RegexParsers 解析空白/空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆