Class: Take::Unit::Scanner
- Inherits:
-
Object
- Object
- Take::Unit::Scanner
- Defined in:
- lib/take/unit/scanner.rb
Instance Attribute Summary collapse
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#initialize(input) ⇒ Scanner
constructor
A new instance of Scanner.
- #scan ⇒ Object
- #scan_body ⇒ Object
- #scan_group(scan = /macro|test|before|after|prefix/) ⇒ Object
- #scan_group_body ⇒ Object
- #scan_nested ⇒ Object
- #scan_whitespace(newlines = true) ⇒ Object
Constructor Details
#initialize(input) ⇒ Scanner
Returns a new instance of Scanner.
9 10 11 12 |
# File 'lib/take/unit/scanner.rb', line 9 def initialize(input) @input = "\n" << input @scanner = StringScanner.new(input) end |
Instance Attribute Details
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
7 8 9 |
# File 'lib/take/unit/scanner.rb', line 7 def tokens @tokens end |
Instance Method Details
#scan ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/take/unit/scanner.rb', line 14 def scan @tokens ||= begin @tokens = [] until @scanner.eos? scan_group_body { error! } end @tokens end end |
#scan_body ⇒ Object
64 65 66 67 68 |
# File 'lib/take/unit/scanner.rb', line 64 def scan_body if @scanner.check(/\s*\{/) emit :block, _scan_block end end |
#scan_group(scan = /macro|test|before|after|prefix/) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/take/unit/scanner.rb', line 50 def scan_group(scan = /macro|test|before|after|prefix/) if @scanner.scan(scan) group_type = @scanner[0] @scanner.scan(/ ([A-Za-z0-9_.-]+)\(/) or error! group_name = @scanner[1] @scanner.scan(/\s*\;/) emit group_type.intern, group_name, _scan_arguments(/\s*\)/, /,\s+/) end end |
#scan_group_body ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/take/unit/scanner.rb', line 24 def scan_group_body pre_scan scan_nested or scan_group or scan_body or scan_whitespace or yield end |
#scan_nested ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/take/unit/scanner.rb', line 33 def scan_nested if scan_group(/group/) scan_whitespace @scanner.scan(/\{/) or error! loop do scan_group_body do if @scanner.scan(/\}/) pre_scan return emit(:group_end) else error! end end end end end |
#scan_whitespace(newlines = true) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/take/unit/scanner.rb', line 70 def scan_whitespace(newlines = true) if newlines @scanner.scan(/\s+/) else @scanner.scan(/[ \t]+/) end end |