Class: RParsec::ParseContext
- Inherits:
-
Object
- Object
- RParsec::ParseContext
- Defined in:
- lib/rparsec/context.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#index ⇒ Object
Returns the value of attribute index.
-
#result ⇒ Object
Returns the value of attribute result.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
Instance Method Summary collapse
- #advance(n) ⇒ Object
- #available ⇒ Object
- #current ⇒ Object
- #eof ⇒ Object
- #error_input ⇒ Object
- #expecting(expected = nil) ⇒ Object
- #failure(msg = nil) ⇒ Object
- #get_current_input ⇒ Object
-
#initialize(src, index = 0, error = nil) ⇒ ParseContext
constructor
A new instance of ParseContext.
- #next ⇒ Object
- #peek(i) ⇒ Object
- #prepare_error ⇒ Object
- #reset_error ⇒ Object
- #retn(val) ⇒ Object
- #scanner ⇒ Object
- #to_msg ⇒ Object
Constructor Details
#initialize(src, index = 0, error = nil) ⇒ ParseContext
Returns a new instance of ParseContext.
11 12 13 14 15 16 |
# File 'lib/rparsec/context.rb', line 11 def initialize(src, index=0, error=nil) @src = src @index = index @error = error @scanner = nil end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
9 10 11 |
# File 'lib/rparsec/context.rb', line 9 def error @error end |
#index ⇒ Object
Returns the value of attribute index.
9 10 11 |
# File 'lib/rparsec/context.rb', line 9 def index @index end |
#result ⇒ Object
Returns the value of attribute result.
9 10 11 |
# File 'lib/rparsec/context.rb', line 9 def result @result end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
8 9 10 |
# File 'lib/rparsec/context.rb', line 8 def src @src end |
Instance Method Details
#advance(n) ⇒ Object
65 66 67 |
# File 'lib/rparsec/context.rb', line 65 def advance n @index += n end |
#available ⇒ Object
53 54 55 |
# File 'lib/rparsec/context.rb', line 53 def available @src.length - @index end |
#current ⇒ Object
45 46 47 |
# File 'lib/rparsec/context.rb', line 45 def current @src[@index] end |
#eof ⇒ Object
49 50 51 |
# File 'lib/rparsec/context.rb', line 49 def eof @index >= @src.length end |
#error_input ⇒ Object
34 35 36 37 38 39 |
# File 'lib/rparsec/context.rb', line 34 def error_input return nil if @error.nil? err = @error err = err.last if err.kind_of? Array err.input end |
#expecting(expected = nil) ⇒ Object
79 80 81 82 |
# File 'lib/rparsec/context.rb', line 79 def expecting(expected=nil) @error = Expected.new(@index, get_current_input, expected) return false end |
#failure(msg = nil) ⇒ Object
74 75 76 77 |
# File 'lib/rparsec/context.rb', line 74 def failure(msg=nil) @error = Failure.new(@index, get_current_input, msg) return false end |
#get_current_input ⇒ Object
84 85 86 87 |
# File 'lib/rparsec/context.rb', line 84 def get_current_input return nil if eof current end |
#next ⇒ Object
61 62 63 |
# File 'lib/rparsec/context.rb', line 61 def next @index += 1 end |
#peek(i) ⇒ Object
57 58 59 |
# File 'lib/rparsec/context.rb', line 57 def peek i @src[@index + i] end |
#prepare_error ⇒ Object
24 25 26 |
# File 'lib/rparsec/context.rb', line 24 def prepare_error @error.flatten! if @error.kind_of?(Array) end |
#reset_error ⇒ Object
41 42 43 |
# File 'lib/rparsec/context.rb', line 41 def reset_error @error = nil end |
#retn(val) ⇒ Object
69 70 71 72 |
# File 'lib/rparsec/context.rb', line 69 def retn(val) @result = val true end |
#scanner ⇒ Object
18 19 20 21 22 |
# File 'lib/rparsec/context.rb', line 18 def scanner @scanner = StringScanner.new(src) if @scanner.nil? @scanner.pos = @index @scanner end |
#to_msg ⇒ Object
28 29 30 31 32 |
# File 'lib/rparsec/context.rb', line 28 def to_msg return '' if @error.nil? return @error.msg unless @error.kind_of?(Array) @error.map { |e| e.msg }.join(' or ') end |