Class: Paco::Context
- Inherits:
-
Object
- Object
- Paco::Context
- Defined in:
- lib/paco/context.rb
Instance Attribute Summary collapse
-
#callstack ⇒ Object
readonly
Returns the value of attribute callstack.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#last_pos ⇒ Object
readonly
Returns the value of attribute last_pos.
-
#pos ⇒ Object
Returns the value of attribute pos.
Instance Method Summary collapse
- #eof? ⇒ Boolean
- #failure_parse(parser) ⇒ Object
- #index(from = nil) ⇒ Paco::Index
-
#initialize(input, pos: 0, with_callstack: false) ⇒ Context
constructor
A new instance of Context.
- #read(n) ⇒ Object
- #read_all ⇒ Object
- #start_parse(parser) ⇒ Object
- #success_parse(result, parser) ⇒ Object
Constructor Details
Instance Attribute Details
#callstack ⇒ Object (readonly)
Returns the value of attribute callstack.
8 9 10 |
# File 'lib/paco/context.rb', line 8 def callstack @callstack end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
8 9 10 |
# File 'lib/paco/context.rb', line 8 def input @input end |
#last_pos ⇒ Object (readonly)
Returns the value of attribute last_pos.
8 9 10 |
# File 'lib/paco/context.rb', line 8 def last_pos @last_pos end |
#pos ⇒ Object
Returns the value of attribute pos.
9 10 11 |
# File 'lib/paco/context.rb', line 9 def pos @pos end |
Instance Method Details
#eof? ⇒ Boolean
25 26 27 |
# File 'lib/paco/context.rb', line 25 def eof? pos >= input.length end |
#failure_parse(parser) ⇒ Object
36 37 38 |
# File 'lib/paco/context.rb', line 36 def failure_parse(parser) @callstack&.failure(pos: pos, parser: parser.desc) end |
#index(from = nil) ⇒ Paco::Index
31 32 33 |
# File 'lib/paco/context.rb', line 31 def index(from = nil) Index.calculate(input: input, pos: from || pos) end |
#read(n) ⇒ Object
17 18 19 |
# File 'lib/paco/context.rb', line 17 def read(n) input[pos, n] end |
#read_all ⇒ Object
21 22 23 |
# File 'lib/paco/context.rb', line 21 def read_all input[pos..] end |
#start_parse(parser) ⇒ Object
41 42 43 |
# File 'lib/paco/context.rb', line 41 def start_parse(parser) @callstack&.start(pos: pos, parser: parser.desc) end |
#success_parse(result, parser) ⇒ Object
47 48 49 |
# File 'lib/paco/context.rb', line 47 def success_parse(result, parser) @callstack&.success(pos: pos, result: result, parser: parser.desc) end |