Class: RubyLexer::State

Inherits:
Object
  • Object
show all
Includes:
Values
Defined in:
lib/ruby_lexer.rb

Defined Under Namespace

Modules: Values

Constant Summary

Constants included from Values

Values::EXPR_ARG, Values::EXPR_ARG_ANY, Values::EXPR_BEG, Values::EXPR_BEG_ANY, Values::EXPR_CLASS, Values::EXPR_CMDARG, Values::EXPR_DOT, Values::EXPR_END, Values::EXPR_ENDARG, Values::EXPR_ENDFN, Values::EXPR_END_ANY, Values::EXPR_FITEM, Values::EXPR_FNAME, Values::EXPR_LAB, Values::EXPR_LABEL, Values::EXPR_LABELED, Values::EXPR_LIT, Values::EXPR_MID, Values::EXPR_NONE, Values::EXPR_NUM, Values::EXPR_PAD, Values::EXPR_PAR, Values::STR_DQUOTE, Values::STR_DSYM, Values::STR_DWORD, Values::STR_FUNC_BORING, Values::STR_FUNC_ESCAPE, Values::STR_FUNC_EXPAND, Values::STR_FUNC_ICNTNT, Values::STR_FUNC_INDENT, Values::STR_FUNC_LABEL, Values::STR_FUNC_LIST, Values::STR_FUNC_QWORDS, Values::STR_FUNC_REGEXP, Values::STR_FUNC_SYMBOL, Values::STR_FUNC_TERM, Values::STR_REGEXP, Values::STR_SQUOTE, Values::STR_SSYM, Values::STR_SWORD, Values::STR_XQUOTE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(o, names) ⇒ State

TODO: take a shared hash of strings for inspect/to_s

Raises:

  • (ArgumentError)


1352
1353
1354
1355
1356
1357
# File 'lib/ruby_lexer.rb', line 1352

def initialize o, names
  raise ArgumentError, "bad state: %p" % [o] unless Integer === o # TODO: remove

  self.n = o
  self.names = names
end

Instance Attribute Details

#nObject

Returns the value of attribute n.



1348
1349
1350
# File 'lib/ruby_lexer.rb', line 1348

def n
  @n
end

#namesObject

Returns the value of attribute names.



1349
1350
1351
# File 'lib/ruby_lexer.rb', line 1349

def names
  @names
end

Instance Method Details

#==(o) ⇒ Object



1359
1360
1361
# File 'lib/ruby_lexer.rb', line 1359

def == o
  self.equal?(o) || (o.class == self.class && o.n == self.n)
end

#=~(v) ⇒ Object



1363
1364
1365
# File 'lib/ruby_lexer.rb', line 1363

def =~ v
  (self.n & v.n) != 0
end

#inspectObject Also known as: to_s



1373
1374
1375
1376
1377
1378
1379
1380
# File 'lib/ruby_lexer.rb', line 1373

def inspect
  return "Value(0)" if n.zero? # HACK?

  names.map { |v, k| k if self =~ v }.
    compact.
    join("|").
    gsub(/(?:EXPR_|STR_(?:FUNC_)?)/, "")
end

#|(v) ⇒ Object

Raises:

  • (ArgumentError)


1367
1368
1369
1370
1371
# File 'lib/ruby_lexer.rb', line 1367

def | v
  raise ArgumentError, "Incompatible State: %p vs %p" % [self, v] unless
    self.names == v.names
  self.class.new(self.n | v.n, self.names)
end