Sha256: 624e6adf1b6f6615def330968e6596d61a071bef6066d599f7d054ae6b8f34fc

Contents?: true

Size: 1.92 KB

Versions: 10

Compression:

Stored size: 1.92 KB

Contents

require 'set'

class Tailor

  # These are important tokens that key certain styling events.  They are taken
  # from:
  # * https://github.com/ruby/ruby/blob/trunk/ext/ripper/eventids2.c
  # * https://github.com/ruby/ruby/blob/trunk/parse.y
  module LexerConstants
    KEYWORDS_TO_INDENT = Set.new [
      'begin',
      'case',
      'class',
      'def',
      'do',
      'else',
      'elsif',
      'ensure',
      'for',
      'if',
      'module',
      'rescue',
      'unless',
      'until',
      'when',
      'while'
    ]

    CONTINUATION_KEYWORDS = Set.new [
      'elsif',
      'else',
      'ensure',
      'rescue',
      'when'
    ]

    KEYWORDS_AND_MODIFIERS = Set.new [
      'if',
      'unless',
      'until',
      'while'
    ]

    MODIFIERS = {
      'if' => :if_mod,
      'rescue' => :rescue_mod,
      'unless' => :unless_mod,
      'until' => :until_mod,
      'while' => :while_mod
    }

    MULTILINE_OPERATORS = Set.new [
      '+', '-', '*', '**', '/', '%',    # +, -, tSTAR, tPOW, /, %
      '<', '>', '<=', '>=',             # <, >, tLEQ, tGEQ
      '=', '+=', '-=', '*=', '**=', '/=', '%=',
      '&&=', '||=', '<<=',              # ...tOP_ASGN...
      '>>', '<<',                       # tRSHFT, tLSHFT
      '!', '&', '?', ':', '^', '~',     # !, tAMPER, ?, :, ^, ~
      #'|',
      '&&', '||',                       # tANDOP, tOROP
      '==', '===', '<=>', '!=',         # tEQ, tEQQ, tCMP, tNEQ
      '=~', '!~',                       # tMATCH, tNMATCH
      '..', '...',                      # tDOT2, tDOT3
      '::',                             # tCOLON2 (not sure about tCOLON3)
      #'[]', '[]=',                      # tAREF, tASET (not sure about these)
      '=>',                             # tASSOC
      '->',                             # tLAMBDA
      '~>'                              # gem_version op
    ]

    LOOP_KEYWORDS = Set.new [
      'for',
      'until',
      'while'
    ]
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tailor-1.2.1 lib/tailor/lexer/lexer_constants.rb
tailor-1.2.0 lib/tailor/lexer/lexer_constants.rb
tailor-1.1.5 lib/tailor/lexer/lexer_constants.rb
tailor-1.1.4 lib/tailor/lexer/lexer_constants.rb
tailor-1.1.3 lib/tailor/lexer/lexer_constants.rb
tailor-1.1.2 lib/tailor/lexer/lexer_constants.rb
tailor-1.1.1 lib/tailor/lexer/lexer_constants.rb
tailor-1.1.0 lib/tailor/lexer/lexer_constants.rb
tailor-1.0.1 lib/tailor/lexer/lexer_constants.rb
tailor-1.0.0 lib/tailor/lexer/lexer_constants.rb