Method: ListTokenSource#column

Defined in:
lib/antlr4/ListTokenSource.rb

#columnObject

@inheritDoc



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/antlr4/ListTokenSource.rb', line 41

def column
    if self.pos < self.tokens.length
        return self.tokens[self.pos].column
    elsif not self.eofToken.nil? 
        return self.eofToken.column
    elsif self.tokens.length > 0
        # have to calculate the result from the line/column of the previous
        # token, along with the text of the token.
        lastToken = self.tokens[-1]
        tokenText = lastToken.getText()
        if not tokenText.nil? then
            lastNewLine = tokenText.rfind('\n')
            if lastNewLine >= 0 
                return tokenText.length - lastNewLine - 1
            end
        end
        return lastToken.column + lastToken.stopIndex - lastToken.startIndex + 1
    end
    # only reach this if tokens is empty, meaning EOF occurs at the first
    # position in the input
    return 0
end