Class: Peruby::Lexer::QuoteLike
- Inherits:
-
Object
- Object
- Peruby::Lexer::QuoteLike
- Defined in:
- lib/peruby/lexer/quote_like.rb
Overview
Scans q/qq/qw/qr/m/s/tr/y delimiters without interpreting their contents.
Constant Summary collapse
- PAIRS =
{ '(' => ')', '[' => ']', '{' => '}', '<' => '>' }.freeze
- TWO_PART =
%i[s tr y].freeze
Instance Method Summary collapse
-
#initialize(source, index) ⇒ QuoteLike
constructor
A new instance of QuoteLike.
- #scan(operator) ⇒ Object
Constructor Details
#initialize(source, index) ⇒ QuoteLike
Returns a new instance of QuoteLike.
13 14 15 16 |
# File 'lib/peruby/lexer/quote_like.rb', line 13 def initialize(source, index) @source = source @index = index end |
Instance Method Details
#scan(operator) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/peruby/lexer/quote_like.rb', line 18 def scan(operator) skip_space if TWO_PART.include?(operator) && paired_delimiter? open = take raise CompileError, "Missing delimiter for #{operator}" unless open parts = [scan_part(open)] parts << scan_second(open) if TWO_PART.include?(operator) modifiers = take_while(/[a-z]/) [Quote.new(operator:, parts:, modifiers:, interpolate: open != "'"), @index] end |