Class: Rley::Lexical::Token
- Inherits:
-
Object
- Object
- Rley::Lexical::Token
- Defined in:
- lib/rley/lexical/token.rb
Overview
In Rley, a (lexical) token is an object created by a lexer (tokenizer) and passed to the parser. Such token an object is created when a lexer detects that a sequence of characters(a lexeme) from the input stream is an instance of a terminal grammar symbol. Say, that in a particular language, the lexeme 'foo' is an occurrence of the terminal symbol IDENTIFIER. Then the lexer will return a Token object that states the fact that 'foo' is indeed an IDENTIFIER. Basically, a Token is a pair (lexeme, terminal): it asserts that a given lexeme is an instance of given terminal symbol.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#lexeme ⇒ String
readonly
The sequence of character(s) from the input stream that is an occurrence of the related terminal symbol.
-
#position ⇒ Position
The position -in "editor" coordinates- of the lexeme in the source file.
-
#terminal ⇒ String
readonly
The name of terminal symbol matching the lexeme.
Instance Method Summary collapse
-
#initialize(theLexeme, aTerminal, aPosition = nil) ⇒ Token
constructor
Constructor.
Constructor Details
#initialize(theLexeme, aTerminal, aPosition = nil) ⇒ Token
Constructor.
41 42 43 44 45 46 47 |
# File 'lib/rley/lexical/token.rb', line 41 def initialize(theLexeme, aTerminal, aPosition = nil) raise 'Internal error: nil terminal symbol detected' if aTerminal.nil? @lexeme = theLexeme @terminal = aTerminal @position = aPosition end |
Instance Attribute Details
#lexeme ⇒ String (readonly)
The sequence of character(s) from the input stream that is an occurrence of the related terminal symbol.
28 29 30 |
# File 'lib/rley/lexical/token.rb', line 28 def lexeme @lexeme end |
#position ⇒ Position
Returns The position -in "editor" coordinates- of the lexeme in the source file.
34 35 36 |
# File 'lib/rley/lexical/token.rb', line 34 def position @position end |
#terminal ⇒ String (readonly)
Returns The name of terminal symbol matching the lexeme.
31 32 33 |
# File 'lib/rley/lexical/token.rb', line 31 def terminal @terminal end |