有没有Ruby语法的明确参考文档? [英] Is there a definitive reference document for Ruby syntax?

查看:123
本文介绍了有没有Ruby语法的明确参考文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找关于Ruby语法的最终文件。我知道核心API和标准库的最终文件,但是语法本身呢?例如,这样的文档应该涵盖:保留字,字符串文字语法,变量/类/模块的命名规则,所有条件语句及其排列等等。



我知道有很多书籍和教程,是的,但是他们中的每一个本质上都是一个教程,每个教程都有不同的深度和重点。他们所有的,必须简洁和叙述的流程,省略了作者认为不重要的语言的某些细节。



例如,你知道你可以使用case语句没有初始的case值,然后执行第一个true when子句?任何给定的Ruby书籍或教程可能涵盖或可能不涵盖案例语法中特定不那么知名的功能。关于case语句的编程Ruby部分中没有讨论。但是这只是一个小例子。



到目前为止,我发现的最好的文档是rubyspec项目,似乎试图写一个完整的测试套件语言。这不错,但是从实际的角度来看,使用我自己的项目的开发人员有点难以使用。



我只是错过了一些东西, em>可定义整个Ruby语法的可读取文档

解决方案

只有 可以合理地描述为definitive的文档是 parse.y 在YARV源代码树中。



ISO草案规范包含一个39页附录,其中包含语法概要。但是请注意,ISO Ruby是Ruby 1.8和1.9交集的最小子集。 IOW:它没有描述只有1.8或1.9中的任何东西(所以,1.9中的语法添加,如stabby proc和符号哈希没有描述),也不描述一切那个十字路口。 ISO Ruby在这方面有点像ISO HTML。



RubySpec 项目包含Ruby语言的可执行规范。虽然它不包含明确的语法规范。实例中唯一的语法规范是隐式。另外,由于RubySpec是一个基于示例的规范,它只能向您展示有效的Ruby代码的具体示例,但它不能告诉您可能有效的Ruby程序,如语法规范可能。而且,由于RubySpec本身是可执行的Ruby代码,它只能显示有效的示例,而不是无效的示例。



最后一件可以被认为是最终的是 由David Flanagan和Yukihiromatz松本的Ruby编程语言 >

但是,请注意,完整的Ruby语法是一项相当艰巨的任务,因为Ruby的语法非常复杂,因为极大的奇怪角落案例。


I'm searching for a definitive document on Ruby syntax. I know about the definitive documents for the core API and standard library, but what about the syntax itself? For instance, such a document should cover: reserved words, string literals syntax, naming rules for variables/classes/modules, all the conditional statements and their permutations, and so forth.

I know there are many books and tutorials, yes, but every one of them is essentially a tutorial, each one having a range of different depth and focus. They will all, by necessity of brevity and narrative flow, omit certain details of the language that the author deems insignificant.

For instance, did you know that you can use a case statement without an initial case value, and it will then execute the first true when clause? Any given Ruby book or tutorial may or may not cover that particular lesser-known functionality of the case syntax. It's not discussed in the section in "Programming Ruby" about case statements. But that is just one small example.

So far the best documentation I've found is the rubyspec project, which appears to be an attempt to write a complete test suite for the language. That's not bad, but it's a bit hard to use from a practical standpoint as a developer working on my own projects.

Am I just missing something or is there really no definitive readable document defining the whole of Ruby syntax?

解决方案

The only document that can be reasonably described as "definitive" is the source code of parse.y in the YARV source tree.

The ISO Draft Specification contains a 39 page appendix with a summary of the grammar. Note, however, that ISO Ruby is a minimal subset of the intersection of Ruby 1.8 and 1.9. IOW: it doesn't describe anything that is only in 1.8 or only in 1.9 (so, the syntax additions in 1.9 like stabby proc and symbol hashes aren't described), nor does it describe everything in that intersection. ISO Ruby is a bit like ISO HTML in that regard.

The RubySpec project contains executable specifications for the Ruby language. It doesn't contain an explicit specification of the grammar, though. The only specification of the grammar is implicit in the examples themselves. Also, because RubySpec is an example-based spec, it can only show you specific examples of valid Ruby code, but it cannot tell you all possible valid Ruby programs like a grammar spec could. And, because RubySpec is itself executable Ruby code, it can only show you valid examples, not invalid ones.

The last thing that could be considered definitive is the book The Ruby Programming Language by David Flanagan and Yukihiro "matz" Matsumoto.

Note, however, that "the whole of Ruby syntax" is a rather daunting task, because Ruby's syntax is insanely complicated with a ginormous amount of weird corner cases.

这篇关于有没有Ruby语法的明确参考文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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