1#!/usr/bin/ruby
2# encoding: utf-8
3
4=begin LICENSE
5
6[The "BSD licence"]
7Copyright (c) 2009-2010 Kyle Yetter
8All rights reserved.
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions
12are met:
13
14 1. Redistributions of source code must retain the above copyright
15    notice, this list of conditions and the following disclaimer.
16 2. Redistributions in binary form must reproduce the above copyright
17    notice, this list of conditions and the following disclaimer in the
18    documentation and/or other materials provided with the distribution.
19 3. The name of the author may not be used to endorse or promote products
20    derived from this software without specific prior written permission.
21
22THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33=end
34
35module ANTLR3
36  
37
38=begin rdoc ANTLR3::Constants
39
40A simple module to keep track of the various built-in token types, channels, and
41token names used by ANTLR throughout the runtime library.
42
43=end
44module Constants
45  # built-in token channel IDs
46  
47  # the channel to which most tokens will be assigned
48  DEFAULT = DEFAULT_CHANNEL = DEFAULT_TOKEN_CHANNEL = :default
49  
50  # the channel for tokens which should not be passed to a parser by a token stream
51  HIDDEN  = HIDDEN_CHANNEL  = :hidden
52  
53  # flag used by recognizers during memoization to
54  # represent a previous prediction failure
55  MEMO_RULE_FAILED = -2
56  
57  # flag used by recognizers during memoization to indicate
58  # that the rule has not been memoized yet
59  MEMO_RULE_UNKNOWN = -1
60  
61  # built-in token types used internally by ANTLR3
62  
63  INVALID_TOKEN_TYPE = 0
64  
65  EOF = -1
66  
67  
68  # Imaginary tree-navigation token type indicating the ascent after moving through the
69  # children of a node
70  UP = 3
71  
72  # Imaginary tree-navigation token type indicating a descent into the children of a node
73  DOWN = 2
74  
75  # End of Rule (used internally by DFAs)
76  EOR_TOKEN_TYPE = 1
77  
78  # The smallest possible value of non-builtin ANTLR-generated token types
79  MIN_TOKEN_TYPE = 4
80  
81  # A hash mapping built in token types to their respective names
82  # returning a string "<UNKNOWN: #{type}>" for non-builtin token
83  # types
84  BUILT_IN_TOKEN_NAMES = Hash.new do |h, k|
85    "<UNKNOWN: #{ k }>"
86  end
87  
88  BUILT_IN_TOKEN_NAMES.update( 
89    0 => "<invalid>".freeze, 1 => "<EOR>".freeze, 
90    2 => "<DOWN>".freeze, 3 => "<UP>".freeze, 
91    -1 => "<EOF>".freeze
92  )
93  
94  
95end
96
97include Constants
98end
99