File: lexical/lexer/entry.rb

Overview
Module Structure
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: Lexical#8
  module: Lexer#10
has properties
function: make_initial_lexer / 2 #14
function: lex / 4 #24

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4 
   5 
   6  module Umu
   7 
   8  module Lexical
   9 
  10  module Lexer
  11 
  12  module_function
  13 
  14      def make_initial_lexer(file_name, line_num)
  15          ASSERT.kind_of file_name,   ::String
  16          ASSERT.kind_of line_num,    ::Integer
  17 
  18          loc = LOC.make_location file_name, line_num
  19 
  20          Separator.new(loc, [].freeze).freeze
  21      end
  22 
  23 
  24      def lex(init_tokens, init_lexer, scanner, pref)
  25          ASSERT.kind_of init_tokens,     ::Array
  26          ASSERT.kind_of init_lexer,      LL::Abstract
  27          ASSERT.kind_of scanner,         ::StringScanner
  28          ASSERT.kind_of pref,            E::Preference
  29 
  30          pair = loop.inject(
  31               [init_tokens, init_lexer, 0  ]
  32          ) { |(tokens,      lexer,      before_line_num), _|
  33 
  34              break [tokens, lexer] if scanner.eos?
  35 
  36              event, matched, output_tokens, next_lexer = lexer.lex scanner
  37              ASSERT.kind_of event,           ::Symbol
  38              ASSERT.kind_of matched,         ::String
  39              ASSERT.kind_of output_tokens,   ::Array
  40              ASSERT.kind_of next_lexer,      LL::Abstract
  41 
  42              if block_given?
  43                  yield event, matched, output_tokens,
  44                        next_lexer, before_line_num
  45              end
  46 
  47 
  48              [
  49                  tokens + output_tokens,
  50 
  51                  next_lexer,
  52 
  53                  if output_tokens.empty?
  54                      before_line_num
  55                  else
  56                      output_tokens[0].loc.line_num
  57                  end
  58              ]
  59          }.freeze
  60 
  61          ASSERT.tuple_of pair, [::Array, LL::Abstract]
  62      end
  63 
  64  end # Umu::Lexical::Lexer
  65 
  66  end # Umu::Lexical
  67 
  68  end # Umu