Skip to content

Latest commit

 

History

History
19 lines (10 loc) · 1.28 KB

parsing_rules.md

File metadata and controls

19 lines (10 loc) · 1.28 KB

Rules

This document contains information related to the rules of the parser for Ruby source code.

As an example, in the documentation of many of the fields of nodes, it's mentioned that a field follows the lexing rules for identifier or constant. This document describes what those rules are.

Constants

Constants in Ruby begin with an upper-case letter. This is followed by any number of underscores, alphanumeric, or non-ASCII characters. The definition of "alphanumeric" and "upper-case letter" are encoding-dependent.

Non-void expression

Most expressions in CRuby are non-void. This means the expression they represent resolves to a value. For example, 1 + 2 is a non-void expression, because it resolves to a method call. Even things like class Foo; end is a non-void expression, because it returns the last evaluated expression in the body of the class (or nil).

Certain nodes, however, are void expressions, and cannot be combined to form larger expressions. For example, BEGIN {}, END {}, alias foo bar, and undef foo.

Identifiers

Identifiers in Ruby begin with an underscore or lower-case letter. This is followed by any number of underscores, alphanumeric, or non-ASCII characters. The definition of "alphanumeric" and "lower-case letter" are encoding-dependent.