Class: Carbon::Compiler::Scanner
- Inherits:
-
Object
- Object
- Carbon::Compiler::Scanner
- Includes:
- Main, Enumerable
- Defined in:
- lib/carbon/compiler/scanner.rb,
lib/carbon/compiler/scanner/main.rb,
lib/carbon/compiler/scanner/token.rb
Overview
Scans over the file, taking a squence of characters and turning them into tokens.
Defined Under Namespace
Instance Attribute Summary collapse
-
#file ⇒ Project::File
readonly
The file that the scanner will run over.
Instance Method Summary collapse
-
#each {|token| ... } ⇒ Enumerator<Token>
Yields each token to the block, if one is given.
-
#initialize(file) ⇒ Scanner
constructor
Initialize the scanner.
-
#inspect ⇒ void
Pretty inspect.
Constructor Details
#initialize(file) ⇒ Scanner
Initialize the scanner. Takes a file, which contains information about the file, and can read from the file.
24 25 26 27 28 29 |
# File 'lib/carbon/compiler/scanner.rb', line 24 def initialize(file) @file = file @scanner = StringScanner.new(@file.read) @line = 1 @last = 0 end |
Instance Attribute Details
#file ⇒ Project::File (readonly)
The file that the scanner will run over.
18 19 20 |
# File 'lib/carbon/compiler/scanner.rb', line 18 def file @file end |
Instance Method Details
#each {|token| ... } ⇒ Enumerator<Token>
Yields each token to the block, if one is given. Returns an enumerator that enumerates over all generated tokens.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/carbon/compiler/scanner.rb', line 44 def each return to_enum unless block_given? until @scanner.eos? token = scan yield token if token.is_a?(Token) end yield Token.new(:EOF, "", location) @scanner.reset end |
#inspect ⇒ void
This method returns an undefined value.
Pretty inspect.
34 35 36 |
# File 'lib/carbon/compiler/scanner.rb', line 34 def inspect "#<#{self.class} #{@file.name}>" end |