Class: Carbon::Compiler::Parser
- Inherits:
-
Object
- Object
- Carbon::Compiler::Parser
- Includes:
- Common, Expressions, Firsts, Helpers, Root, Statements
- Defined in:
- lib/carbon/compiler/parser.rb,
lib/carbon/compiler/parser/root.rb,
lib/carbon/compiler/parser/common.rb,
lib/carbon/compiler/parser/firsts.rb,
lib/carbon/compiler/parser/helpers.rb,
lib/carbon/compiler/parser/root/enum.rb,
lib/carbon/compiler/parser/root/class.rb,
lib/carbon/compiler/parser/root/trait.rb,
lib/carbon/compiler/parser/statements.rb,
lib/carbon/compiler/parser/expressions.rb,
lib/carbon/compiler/parser/root/struct.rb,
lib/carbon/compiler/parser/root/function.rb,
lib/carbon/compiler/parser/statements/if.rb,
lib/carbon/compiler/parser/root/directive.rb,
lib/carbon/compiler/parser/statements/try.rb,
lib/carbon/compiler/parser/statements/match.rb,
lib/carbon/compiler/parser/expressions/primary.rb,
lib/carbon/compiler/parser/expressions/precedence.rb
Overview
The parser. This takes a series of tokens, generated by the Scanner, and derives structure from these tokens. This makes the fundamental bases of creating a concrete representation of what is in the file.
Defined Under Namespace
Modules: Common, Expressions, Firsts, Helpers, Root, Statements
Instance Attribute Summary collapse
-
#scanner ⇒ Scanner
readonly
The scanner that acts as the source of the tokens.
Instance Method Summary collapse
-
#clear! ⇒ void
Destroys the cache for #parse, allowing the parsing to occur again.
-
#initialize(scanner) ⇒ Parser
constructor
Initialize the parser.
-
#inspect ⇒ String
Pretty inspect.
-
#parse ⇒ Parser::Node
(also: #root)
Parses the input.
Methods included from Firsts
Methods included from Helpers
#error, #expect, #peek, #peek?, #shift
Constructor Details
#initialize(scanner) ⇒ Parser
Initialize the parser. It takes a scanner, and the project that the parser is a part of.
33 34 35 36 37 |
# File 'lib/carbon/compiler/parser.rb', line 33 def initialize(scanner) @scanner = scanner @file = @scanner.file @enum = @scanner.each end |
Instance Attribute Details
#scanner ⇒ Scanner (readonly)
The scanner that acts as the source of the tokens.
26 27 28 |
# File 'lib/carbon/compiler/parser.rb', line 26 def scanner @scanner end |
Instance Method Details
#clear! ⇒ void
This method returns an undefined value.
Destroys the cache for #parse, allowing the parsing to occur again.
57 58 59 60 |
# File 'lib/carbon/compiler/parser.rb', line 57 def clear! @enum.reset @_root = nil end |
#inspect ⇒ String
Pretty inspect.
42 43 44 |
# File 'lib/carbon/compiler/parser.rb', line 42 def inspect "#<#{self.class} #{@scanner.file.name}>" end |
#parse ⇒ Parser::Node Also known as: root
Parses the input. This is cached to prevent multiple runs.
49 50 51 |
# File 'lib/carbon/compiler/parser.rb', line 49 def parse @_root ||= parse_root end |