Class: Prosereflect::Schema::ContentMatch::TokenStream
- Inherits:
-
Object
- Object
- Prosereflect::Schema::ContentMatch::TokenStream
- Defined in:
- lib/prosereflect/schema/content_match.rb
Overview
Token stream for parsing content expressions
Instance Attribute Summary collapse
-
#node_types ⇒ Object
readonly
Returns the value of attribute node_types.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #accept(tok) ⇒ Object
- #advance ⇒ Object
- #error(message) ⇒ Object
- #expect(tok) ⇒ Object
- #expect_number ⇒ Object
-
#initialize(string, node_types) ⇒ TokenStream
constructor
A new instance of TokenStream.
- #peek ⇒ Object
Constructor Details
#initialize(string, node_types) ⇒ TokenStream
Returns a new instance of TokenStream.
600 601 602 603 604 605 |
# File 'lib/prosereflect/schema/content_match.rb', line 600 def initialize(string, node_types) @string = string @node_types = node_types @pos = 0 @tokens = tokenize(string) end |
Instance Attribute Details
#node_types ⇒ Object (readonly)
Returns the value of attribute node_types.
598 599 600 |
# File 'lib/prosereflect/schema/content_match.rb', line 598 def node_types @node_types end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
598 599 600 |
# File 'lib/prosereflect/schema/content_match.rb', line 598 def string @string end |
Instance Method Details
#accept(tok) ⇒ Object
615 616 617 618 619 620 621 622 |
# File 'lib/prosereflect/schema/content_match.rb', line 615 def accept(tok) if peek == tok @pos += 1 true else false end end |
#advance ⇒ Object
611 612 613 |
# File 'lib/prosereflect/schema/content_match.rb', line 611 def advance @tokens[@pos]&.tap { @pos += 1 } end |
#error(message) ⇒ Object
643 644 645 646 |
# File 'lib/prosereflect/schema/content_match.rb', line 643 def error() raise Prosereflect::SchemaErrors::ContentMatchError, "#{} (in content expression) \"#{@string}\"" end |
#expect(tok) ⇒ Object
624 625 626 627 628 629 630 631 |
# File 'lib/prosereflect/schema/content_match.rb', line 624 def expect(tok) unless accept(tok) raise Prosereflect::SchemaErrors::ContentMatchError, "Expected #{tok}, got #{peek.inspect}" end true end |
#expect_number ⇒ Object
633 634 635 636 637 638 639 640 641 |
# File 'lib/prosereflect/schema/content_match.rb', line 633 def expect_number tok = peek unless /^\d+$/.match?(tok) raise Prosereflect::SchemaErrors::ContentMatchError, "Expected number, got #{tok.inspect}" end advance.to_i end |
#peek ⇒ Object
607 608 609 |
# File 'lib/prosereflect/schema/content_match.rb', line 607 def peek @tokens[@pos] end |