Class: Codeball::Cursor
- Inherits:
-
Object
- Object
- Codeball::Cursor
- Defined in:
- lib/codeball/cursor.rb
Overview
A lexer for codeball-formatted text.
Cursor walks text line by line and classifies each meaningful element as a typed token: Header, Body, or Footer. Borders are delimiters consumed internally – they are never yielded.
Cursor does not correlate tokens or enforce sequencing. Stream handles assembly; Entry enforces invariants.
Defined Under Namespace
Modules: EOF
Constant Summary collapse
- BEGIN_PATTERN =
/\ABEGIN\s+["']?(.+?)["']?\s*\z/- END_PATTERN =
/\AEND\s+["']?(.+?)["']?\s*\z/
Instance Method Summary collapse
-
#initialize(text) ⇒ Cursor
constructor
A new instance of Cursor.
- #next_item ⇒ Object
Constructor Details
#initialize(text) ⇒ Cursor
Returns a new instance of Cursor.
18 19 20 21 22 23 |
# File 'lib/codeball/cursor.rb', line 18 def initialize(text) @lines = text.lines @position = 0 @pending_footer = nil @body_lines = nil end |
Instance Method Details
#next_item ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/codeball/cursor.rb', line 25 def next_item return if @pending_footer skip_borders return EOF if finished? if @body_lines read_body else read_header_or_eof end end |