File: lexical/lexer/separator.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: Lexical#8
  module: Lexer#10
  class: Separator#12
inherits from
  Abstract ( Umu::Lexical::Lexer )
has properties
method: lex / 1 #13

Class Hierarchy

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  class Separator < Abstract
  13      def lex(scanner)
  14          ASSERT.kind_of scanner, ::StringScanner
  15 
  16          case
  17          # Begin-Comment
  18          when scanner.scan(/\(#/)
  19              [
  20                  :BeginComment,
  21 
  22                  scanner.matched,
  23 
  24                  [],
  25 
  26                  __make_comment__(
  27                      self.loc,   # Save current location
  28                      1,
  29                      ''
  30                  )
  31              ]
  32 
  33          # New-line with optional Line-comment
  34          when scanner.scan(/(#.*)?(\R)/)
  35              comment_matched = scanner[1]
  36              newline_matched = scanner[2]
  37 
  38              [
  39                  :NewLine,
  40 
  41                  scanner.matched,
  42 
  43                  (
  44                      if (! comment_matched) || comment_matched.empty?
  45                          []
  46                      else
  47                          [LT.make_comment(loc, comment_matched)]
  48                      end
  49                  ) + [
  50                      LT.make_newline(loc, newline_matched)
  51                  ],
  52 
  53                  __make_separator__(self.loc.next_line_num)
  54              ]
  55 
  56          # Other space-chars
  57          when scanner.scan(/ +/)
  58              [
  59                  :Space,
  60 
  61                  scanner.matched,
  62 
  63                  [LT.make_space(loc, scanner.matched)],
  64 
  65                  self
  66              ]
  67 
  68          # Tab char
  69          when scanner.scan(/\t/)
  70              raise X::LexicalError.new(
  71                  self.loc,
  72                  "Hard tab '\\t' is prohibited",
  73              )
  74 
  75          # Unmatched
  76          else
  77              [
  78                  :Unmatched,
  79 
  80                  '',
  81                  
  82                  [],
  83 
  84                  __make_token__
  85              ]
  86          end
  87      end
  88  end
  89 
  90  end # Umu::Lexical::Lexer
  91 
  92  end # Umu::Lexical
  93 
  94  end # Umu