c# - 为什么 Roslyn 每种语言都有两个版本的语法?

标签 c# vb.net parsing roslyn

我一直在查看 Roslyn 代码库并注意到它们有两种语法版本(一种内部版本和一种公共(public)版本)。通常这些似乎被称为“红色”节点和“绿色”节点。我想知道是否有人可以解释为什么有两个这样的语法版本。

最佳答案

来自 Persistence, Facades and Roslyn’s Red-Green Trees :

The “green” tree is immutable, persistent, has no parent references, is built “bottom-up”, and every node tracks its width but not its absolute position. When an edit happens we rebuild only the portions of the green tree that were affected by the edit, which is typically about O(log n) of the total parse nodes in the tree.

The “red” tree is an immutable facade that is built around the green tree; it is built “top-down” on demand and thrown away on every edit. It computes parent references by manufacturing them on demand as you descend through the tree from the top. It manufactures absolute positions by computing them from the widths, again, as you descend.

You, the consumer of the Roslyn API, only ever see the red tree; the green tree is an implementation detail. (And if you use the debugger to peer into the internal state of a parse node you’ll in fact see that there is a reference to another parse node in there of a different type; that’s the green tree node.)

Incidentally, these are called “red/green trees” because those were the whiteboard marker colours we used to draw the data structure in the design meeting. There’s no other meaning to the colours.

关于c# - 为什么 Roslyn 每种语言都有两个版本的语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40266011/

相关文章:

c# - 正则表达式匹配 "target string"

c# - Cron 可观察序列

c# - 如何在 VBCodeProvider 中启用隐式续行?

swift - IOS - 从 Firebase 解析对象 - 下载完成前运行的代码

c# - 从网页获取缩略图

c# - 在 2 个 dll 中具有命名空间名称的不明确类

VB.Net 上的正则表达式仅从左到右获取前几个数字

vb.net - 如何在 VB.NET 中编写异步子程序?

python - BeautifulSoup 无法解析内容,因为页面加载速度太慢

parsing - Scala StandardTokenParsers 与 JavaTokenParsers