Class: SeccompTools::Asm::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/seccomp-tools/asm/token.rb

Overview

Records information of a token.

Beyond the token itself, a Token remembers where it was found so that Scanner#format_error can point at it in the source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sym, str, line, col) ⇒ Token

Instantiates a SeccompTools::Asm::Token object.

Parameters:

  • sym (Symbol)

    Type of this token.

  • str (String)

    The matched text.

  • line (Integer)

    Zero-based line number where this token starts.

  • col (Integer)

    Zero-based column number where this token starts.



30
31
32
33
34
35
# File 'lib/seccomp-tools/asm/token.rb', line 30

def initialize(sym, str, line, col)
  @sym = sym
  @str = str
  @line = line
  @col = col
end

Instance Attribute Details

#colInteger (readonly)

Returns Zero-based column number where this token starts.

Returns:

  • (Integer)

    Zero-based column number where this token starts.



19
20
21
# File 'lib/seccomp-tools/asm/token.rb', line 19

def col
  @col
end

#lineInteger (readonly)

Returns Zero-based line number where this token starts.

Returns:

  • (Integer)

    Zero-based line number where this token starts.



17
18
19
# File 'lib/seccomp-tools/asm/token.rb', line 17

def line
  @line
end

#strString (readonly)

Returns The matched text.

Returns:

  • (String)

    The matched text.



15
16
17
# File 'lib/seccomp-tools/asm/token.rb', line 15

def str
  @str
end

#symSymbol (readonly)

Returns Type of this token, e.g. :NEWLINE, :SYMBOL, :GOTO, or :unknown for text the scanner failed to recognize.

Returns:

  • (Symbol)

    Type of this token, e.g. :NEWLINE, :SYMBOL, :GOTO, or :unknown for text the scanner failed to recognize.



13
14
15
# File 'lib/seccomp-tools/asm/token.rb', line 13

def sym
  @sym
end

Instance Method Details

#==(other) ⇒ Boolean

To compare with another SeccompTools::Asm::Token object.

Parameters:

  • other (Token)

    The token to be compared with.

Returns:

  • (Boolean)

    true only if all four attributes are equal.



42
43
44
# File 'lib/seccomp-tools/asm/token.rb', line 42

def ==(other)
  [other.sym, other.str, other.line, other.col] == [sym, str, line, col]
end