Two of the most useful items will be the Child and Adjacent Sibling combinators.
两个最有用的项目将是Child子和adjacent Sibling相邻兄弟选择符。
Before we get into the combinators themselves, it's a good idea to clarify just what they do differently and why that is a good thing.
在我们研究选择符之前,弄清楚他们的不同和为什么它们是好东西的原因是个不错的主意。
In the meantime, let's explore Scala's third option for building parsers: parser combinators, built entirely from the functional side of Scala.
同时,我们来探索Scala构建解析器的第3个选项:解析器组合子(parsercombinators),它完全是从Scala的函数性方面构建的。
To change it to produce instances of our case class AST hierarchy (Expr objects), the return type of the combinators has to be changed to be Parser[Expr].
要将它更改为生成case类AST层次结构的实例(Expr对象),组合子的返回类型必须更改为Parser[Expr]。
Method handles act as both function Pointers and as function combinators, allowing a built-in way to construct a call protocol flow from a caller to a callee.
方法句柄可以同时作为函数的pointer和combinator,允许用内置的方式建立一个从调用器到被调用者的调用协议。
If you make that change on its own, it will fail to compile; the three combinators know how to take in Strings but not how to produce Expr objects from what's parsed.
如果让它自行更改,编译将会失败;这三个组合子知道如何获取String,但不知道如何根据解析的内容生成Expr对象。
There is, and to understand how it works, you'll need to take a short dive into how parser combinators produce non - "standard" elements (that is, not Strings and Lists).
确实有另外一种方法。为了理解这种方法的工作原理,您将需要研究一下解析器组合子是如何产生非“标准”的元素的(即不是String和List)。
That's it for now; in the next set of articles, we'll go back to visiting more of Scala's language capabilities (such as generics, because parser combinators made use of them).
本文到此结束。在下一篇文章中,我们将回顾scala的更多语言功能(比如泛型,因为解析器组合子是由它们组成的)。
Parsers "combine" to provide higher and higher levels of abstraction over the concept of parsing (hence the name "parser combinators"; elements which combine together to provide parsing behavior).
“组合”解析器可以提供解析概念的越来越高级的抽象(因此称为“解析器组合子”;组合在一起的元素提供解析行为)。
Parsers "combine" to provide higher and higher levels of abstraction over the concept of parsing (hence the name "parser combinators"; elements which combine together to provide parsing behavior).
“组合”解析器可以提供解析概念的越来越高级的抽象(因此称为“解析器组合子”;组合在一起的元素提供解析行为)。
应用推荐