Class: Antelope::Ace::Scanner
- Inherits:
-
Object
- Object
- Antelope::Ace::Scanner
- Defined in:
- lib/antelope/ace/scanner.rb,
lib/antelope/ace/scanner/first.rb,
lib/antelope/ace/scanner/third.rb,
lib/antelope/ace/scanner/second.rb
Overview
Scans a given input. The input should be a properly formatted ACE file; see the Ace module for more information. This scanner uses the StringScanner class internally; see the ruby documentation for more on that. This scanner seperates scanning into three seperate stages: First, Second, and Third, for each section of the file, respectively.
Defined Under Namespace
Constant Summary collapse
- CONTENT_BOUNDRY =
The boundry between each section. Placed here to be easily modifiable. MUST be a regular expression.
/%%/- VALUE =
The value regular expression. It should match values; for example, things quoted in strings or word letters without quotes. Must respond to #to_s, since it is embedded within other regular expressions. The regular expression should place the contents of the value in the groups 2 or 3.
%q{(?: (?:("|')((?:\\\\|\\"|\\'|.)+?)\\1) | ([[:word:]]+) )}
Instance Attribute Summary collapse
-
#scanner ⇒ StringScanner
readonly
The string scanner that we're using to scan the string with.
-
#tokens ⇒ Array<Array<(Symbol, Object, ...)>>
readonly
An array of the tokens that the scanner scanned.
Class Method Summary collapse
-
.scan(source) ⇒ Array<Array<(Symbol, Object, ...)>>
Scans a file.
Instance Method Summary collapse
-
#error! ⇒ void
private
Raises an error; first creates a small snippet to give the developer some context.
-
#initialize(input) ⇒ Scanner
constructor
Initialize the scanner with the input.
-
#scan_file ⇒ Array<Array<(Symbol, Object, ...)>>
Scans the file in parts.
-
#scan_whitespace ⇒ Boolean
Scans for whitespace.
Methods included from Third
Methods included from Second
#_scan_block, #scan_second_part, #scan_second_rule, #scan_second_rule_block, #scan_second_rule_body, #scan_second_rule_label, #scan_second_rule_or, #scan_second_rule_part, #scan_second_rule_prec
Methods included from First
#scan_first_copy, #scan_first_directive, #scan_first_part
Constructor Details
#initialize(input) ⇒ Scanner
Initialize the scanner with the input.
64 65 66 67 |
# File 'lib/antelope/ace/scanner.rb', line 64 def initialize(input) @scanner = StringScanner.new(input) @tokens = [] end |
Instance Attribute Details
#scanner ⇒ StringScanner (readonly)
The string scanner that we're using to scan the string with.
26 27 28 |
# File 'lib/antelope/ace/scanner.rb', line 26 def scanner @scanner end |
#tokens ⇒ Array<Array<(Symbol, Object, ...)>> (readonly)
An array of the tokens that the scanner scanned.
31 32 33 |
# File 'lib/antelope/ace/scanner.rb', line 31 def tokens @tokens end |
Class Method Details
.scan(source) ⇒ Array<Array<(Symbol, Object, ...)>>
Scans a file. It returns the tokens resulting from scanning.
57 58 59 |
# File 'lib/antelope/ace/scanner.rb', line 57 def self.scan(source) new(source).scan_file end |
Instance Method Details
#error! ⇒ void (private)
This method returns an undefined value.
Raises an error; first creates a small snippet to give the developer some context.
101 102 103 104 105 106 107 |
# File 'lib/antelope/ace/scanner.rb', line 101 def error! start = [@scanner.pos - 8, 0].max stop = [@scanner.pos + 8, @scanner.string.length].min snip = @scanner.string[start..stop].strip char = @scanner.string[@scanner.pos] raise SyntaxError, "invalid syntax near `#{snip.inspect}' (#{char.inspect})" end |
#scan_file ⇒ Array<Array<(Symbol, Object, ...)>>
Scans the file in parts.
78 79 80 81 82 83 |
# File 'lib/antelope/ace/scanner.rb', line 78 def scan_file scan_first_part scan_second_part scan_third_part tokens end |
#scan_whitespace ⇒ Boolean
Scans for whitespace. If the next character is whitespace, it will consume all whitespace until the next non-whitespace character.
90 91 92 |
# File 'lib/antelope/ace/scanner.rb', line 90 def scan_whitespace @scanner.scan(/\s+/) end |