class CodeRay::WordList
…
kind = IDENT_KIND[match]
# use it
elsif scan(/[A-Za-z_0-9]*/)
…
def scan_tokens tokens, options
…
add(PREDEFINED_TYPES, :predefined_type)
add(RESERVED_WORDS, :reserved).
IDENT_KIND = WordList.new(:ident).
# make a WordList
]
int long short char void
PREDEFINED_TYPES = %w[
]
asm break case continue default do else
RESERVED_WORDS = %w[
# define word arrays
Example:
For case insensitive words use WordList::CaseIgnoring.
typically to decide whether a given ident is a special token.
WordList is optimized to be used in Scanners,
It is intended to be used for keyword recognition.
A WordList is a Hash with some additional features.
A Hash subclass designed for mapping word lists to token types.
= WordList
def add words, value = true
Add words to the list and associate them with +value+.
def add words, value = true words.each { |word| self[word] = value } self end
def initialize default = false
def initialize default = false super default end