Class: Rucc::Token
- Inherits:
-
Object
- Object
- Rucc::Token
- Defined in:
- lib/rucc/token.rb
Constant Summary collapse
- SPACE_TOKEN =
Token.new(T::SPACE)
- NEWLINE_TOKEN =
Token.new(T::NEWLINE)
- EOF_TOKEN =
Token.new(T::EOF)
Instance Attribute Summary collapse
-
#bol ⇒ Object
Returns the value of attribute bol.
-
#c ⇒ Object
readonly
Returns the value of attribute c.
-
#column ⇒ Object
Returns the value of attribute column.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#enc ⇒ Object
Returns the value of attribute enc.
-
#expanded ⇒ Object
Returns the value of attribute expanded.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#hideset ⇒ Object
Returns the value of attribute hideset.
-
#id ⇒ Object
Returns the value of attribute id.
-
#is_vararg ⇒ Object
readonly
Returns the value of attribute is_vararg.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#line ⇒ Object
Returns the value of attribute line.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#space ⇒ Object
Returns the value of attribute space.
-
#sval ⇒ Object
Returns the value of attribute sval.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(kind, file: nil, count: nil, line: nil, column: nil, hideset: nil, space: false, bol: nil, id: nil, sval: nil, c: nil, enc: nil, is_vararg: nil, position: nil) ⇒ Token
constructor
A new instance of Token.
- #to_s ⇒ String
Constructor Details
#initialize(kind, file: nil, count: nil, line: nil, column: nil, hideset: nil, space: false, bol: nil, id: nil, sval: nil, c: nil, enc: nil, is_vararg: nil, position: nil) ⇒ Token
Returns a new instance of Token.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rucc/token.rb', line 18 def initialize(kind, file: nil, count: nil, # Token number in a file, counting from 0 line: nil, column: nil, # Token location in a file hideset: nil, # used by the preprocessor for macro expansion space: false, # true if the token has a leading space bol: nil, # true if the token is at the beginning of a line id: nil, # KEYWORD sval: nil, c: nil, enc: nil, # STRING or CHAR is_vararg: nil, position: nil # MACRO_PARAM ) @kind = kind @file = file @count = count @line = line; @column = column @hideset = hideset @space = space @bol = bol # value @id = id # KEYWORD @sval = sval; @c = c; @enc = enc; # STRING or CHAR @is_vararg = is_vararg; @position = position # MACRO_PARAM # Flag representing completion of macro expansion = false end |
Instance Attribute Details
#bol ⇒ Object
Returns the value of attribute bol.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def bol @bol end |
#c ⇒ Object (readonly)
Returns the value of attribute c.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def c @c end |
#column ⇒ Object
Returns the value of attribute column.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def column @column end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def count @count end |
#enc ⇒ Object
Returns the value of attribute enc.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def enc @enc end |
#expanded ⇒ Object
Returns the value of attribute expanded.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def file @file end |
#hideset ⇒ Object
Returns the value of attribute hideset.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def hideset @hideset end |
#id ⇒ Object
Returns the value of attribute id.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def id @id end |
#is_vararg ⇒ Object (readonly)
Returns the value of attribute is_vararg.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def is_vararg @is_vararg end |
#kind ⇒ Object
Returns the value of attribute kind.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def kind @kind end |
#line ⇒ Object
Returns the value of attribute line.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def line @line end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def position @position end |
#space ⇒ Object
Returns the value of attribute space.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def space @space end |
#sval ⇒ Object
Returns the value of attribute sval.
45 46 47 |
# File 'lib/rucc/token.rb', line 45 def sval @sval end |
Class Method Details
.is_ident?(tok, s) ⇒ Boolean
105 106 107 |
# File 'lib/rucc/token.rb', line 105 def is_ident?(tok, s) tok.kind == T::IDENT && tok.sval == s end |
.is_keyword?(tok, id) ⇒ Boolean
98 99 100 |
# File 'lib/rucc/token.rb', line 98 def is_keyword?(tok, id) tok.kind == T::KEYWORD && tok.id == id end |
Instance Method Details
#to_s ⇒ String
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rucc/token.rb', line 49 def to_s case kind when T::IDENT return sval when T::KEYWORD case self when Operator, Keyword return str else return "#{id}" end when T::CHAR return "#{encoding_prefix(enc)}'#{Util.quote_char(c)}'" when T::NUMBER return sval when T::STRING return "#{encoding_prefix(enc)}\"#{Util.quote_cstring(sval)}\"" when T::EOF return "(eof)" when T::INVALID return "#{c}" when T::NEWLINE return "(newline)" when T::SPACE return "(space)" when T::MACRO_PARAM return "(macro-param)" else raise "internal error: unknown token kind: #{kind}" end end |