Class: Jade::Parsing::Combinators::State
- Inherits:
-
Data
- Object
- Data
- Jade::Parsing::Combinators::State
- Defined in:
- lib/jade/parsing/combinators.rb
Instance Attribute Summary collapse
-
#context_stack ⇒ Object
readonly
Returns the value of attribute context_stack.
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
-
#tolerant ⇒ Object
readonly
Returns the value of attribute tolerant.
Instance Method Summary collapse
- #add_diagnostic(diagnostic) ⇒ Object
- #advance(n = 1) ⇒ Object
- #current ⇒ Object
- #eof? ⇒ Boolean
-
#initialize(tokens:, entry:, position: 0, context_stack: [], tolerant: false, diagnostics: Diagnostics::List.empty, source: nil) ⇒ State
constructor
A new instance of State.
-
#same_line?(pos_a, pos_b) ⇒ Boolean
Two positions on the same source line.
- #skip_until(sync_types) ⇒ Object
Constructor Details
#initialize(tokens:, entry:, position: 0, context_stack: [], tolerant: false, diagnostics: Diagnostics::List.empty, source: nil) ⇒ State
Returns a new instance of State.
179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/jade/parsing/combinators.rb', line 179 def initialize( tokens:, entry:, position: 0, context_stack: [], tolerant: false, diagnostics: Diagnostics::List.empty, source: nil ) super end |
Instance Attribute Details
#context_stack ⇒ Object (readonly)
Returns the value of attribute context_stack
175 176 177 |
# File 'lib/jade/parsing/combinators.rb', line 175 def context_stack @context_stack end |
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics
175 176 177 |
# File 'lib/jade/parsing/combinators.rb', line 175 def diagnostics @diagnostics end |
#entry ⇒ Object (readonly)
Returns the value of attribute entry
175 176 177 |
# File 'lib/jade/parsing/combinators.rb', line 175 def entry @entry end |
#position ⇒ Object (readonly)
Returns the value of attribute position
175 176 177 |
# File 'lib/jade/parsing/combinators.rb', line 175 def position @position end |
#source ⇒ Object (readonly)
Returns the value of attribute source
175 176 177 |
# File 'lib/jade/parsing/combinators.rb', line 175 def source @source end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens
175 176 177 |
# File 'lib/jade/parsing/combinators.rb', line 175 def tokens @tokens end |
#tolerant ⇒ Object (readonly)
Returns the value of attribute tolerant
175 176 177 |
# File 'lib/jade/parsing/combinators.rb', line 175 def tolerant @tolerant end |
Instance Method Details
#add_diagnostic(diagnostic) ⇒ Object
215 216 217 |
# File 'lib/jade/parsing/combinators.rb', line 215 def add_diagnostic(diagnostic) with(diagnostics: diagnostics.add(diagnostic)) end |
#advance(n = 1) ⇒ Object
195 196 197 |
# File 'lib/jade/parsing/combinators.rb', line 195 def advance(n = 1) with(position: position + n) end |
#current ⇒ Object
191 192 193 |
# File 'lib/jade/parsing/combinators.rb', line 191 def current tokens[position] end |
#eof? ⇒ Boolean
199 200 201 |
# File 'lib/jade/parsing/combinators.rb', line 199 def eof? position >= tokens.length end |
#same_line?(pos_a, pos_b) ⇒ Boolean
Two positions on the same source line. Uses the source’s ‘line_starts` index; returns true when source is unavailable so callers degrade to “accept whatever parses” rather than spurious errors.
207 208 209 210 211 212 213 |
# File 'lib/jade/parsing/combinators.rb', line 207 def same_line?(pos_a, pos_b) return true unless source starts = source.line_starts starts.bsearch_index { |ls| ls > pos_a } == starts.bsearch_index { |ls| ls > pos_b } end |
#skip_until(sync_types) ⇒ Object
219 220 221 222 223 |
# File 'lib/jade/parsing/combinators.rb', line 219 def skip_until(sync_types) (position...tokens.length) .find { sync_types.include?(tokens[it].type) } .then { with(position: it || tokens.length) } end |