Class: Teeth::Scanner
- Inherits:
-
Object
- Object
- Teeth::Scanner
- Defined in:
- lib/teeth/scanner.rb
Constant Summary collapse
- TEMPLATE =
File.dirname(__FILE__) + "/templates/tokenizer.yy.erb"
Instance Attribute Summary collapse
-
#rdoc ⇒ Object
Returns the value of attribute rdoc.
-
#scanner_defns ⇒ Object
readonly
Returns the value of attribute scanner_defns.
-
#scanner_rules ⇒ Object
readonly
Returns the value of attribute scanner_rules.
Instance Method Summary collapse
- #define(*args) ⇒ Object
- #definitions {|@scanner_defns| ... } ⇒ Object
- #entry_point ⇒ Object
- #extconf ⇒ Object
- #function_prefix ⇒ Object
- #generate ⇒ Object
- #init_function_name ⇒ Object
-
#initialize(name, ext_dir = nil) ⇒ Scanner
constructor
A new instance of Scanner.
- #load_default_definitions_for(*defn_types) ⇒ Object
- #main_function_name ⇒ Object
- #rule(*args) ⇒ Object
- #rules {|scanner_rules| ... } ⇒ Object
- #scanner_name ⇒ Object
- #write! ⇒ Object
Constructor Details
#initialize(name, ext_dir = nil) ⇒ Scanner
Returns a new instance of Scanner.
14 15 16 17 18 |
# File 'lib/teeth/scanner.rb', line 14 def initialize(name, ext_dir=nil) @scanner_base_name, @ext_dir = name, ext_dir @scanner_defns, @scanner_rules = ScannerDefinitionGroup.new, RuleStatementGroup.new ensure_ext_dir_exists if ext_dir end |
Instance Attribute Details
#rdoc ⇒ Object
Returns the value of attribute rdoc.
12 13 14 |
# File 'lib/teeth/scanner.rb', line 12 def rdoc @rdoc end |
#scanner_defns ⇒ Object (readonly)
Returns the value of attribute scanner_defns.
12 13 14 |
# File 'lib/teeth/scanner.rb', line 12 def scanner_defns @scanner_defns end |
#scanner_rules ⇒ Object (readonly)
Returns the value of attribute scanner_rules.
12 13 14 |
# File 'lib/teeth/scanner.rb', line 12 def scanner_rules @scanner_rules end |
Instance Method Details
#define(*args) ⇒ Object
54 55 56 |
# File 'lib/teeth/scanner.rb', line 54 def define(*args) @scanner_defns.add(*args) end |
#definitions {|@scanner_defns| ... } ⇒ Object
58 59 60 |
# File 'lib/teeth/scanner.rb', line 58 def definitions yield @scanner_defns end |
#entry_point ⇒ Object
36 37 38 |
# File 'lib/teeth/scanner.rb', line 36 def entry_point "scan_" + @scanner_base_name.to_s end |
#extconf ⇒ Object
40 41 42 43 44 45 |
# File 'lib/teeth/scanner.rb', line 40 def extconf 'require "mkmf"' + "\n" + '$CFLAGS += " -Wall"' + "\n" + 'have_library("uuid", "uuid_generate_time")' + "\n" + "create_makefile " + %Q|"teeth/#{scanner_name}", "./"\n| end |
#function_prefix ⇒ Object
32 33 34 |
# File 'lib/teeth/scanner.rb', line 32 def function_prefix @scanner_base_name.to_s + "_yy" end |
#generate ⇒ Object
74 75 76 77 78 79 |
# File 'lib/teeth/scanner.rb', line 74 def generate template = ERB.new(IO.read(TEMPLATE)) scanner = self b = binding template.result(b) end |
#init_function_name ⇒ Object
28 29 30 |
# File 'lib/teeth/scanner.rb', line 28 def init_function_name "Init_" + scanner_name end |
#load_default_definitions_for(*defn_types) ⇒ Object
62 63 64 |
# File 'lib/teeth/scanner.rb', line 62 def load_default_definitions_for(*defn_types) @scanner_defns.defaults_for(*defn_types) end |
#main_function_name ⇒ Object
24 25 26 |
# File 'lib/teeth/scanner.rb', line 24 def main_function_name "t_" + scanner_name end |
#rule(*args) ⇒ Object
66 67 68 |
# File 'lib/teeth/scanner.rb', line 66 def rule(*args) scanner_rules.add(*args) end |
#rules {|scanner_rules| ... } ⇒ Object
70 71 72 |
# File 'lib/teeth/scanner.rb', line 70 def rules yield scanner_rules end |
#scanner_name ⇒ Object
20 21 22 |
# File 'lib/teeth/scanner.rb', line 20 def scanner_name "scan_" + @scanner_base_name.to_s end |
#write! ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/teeth/scanner.rb', line 81 def write! raise InvalidExtensionDirectory, "no extension directory specified" unless @ext_dir File.open(@ext_dir + "/extconf.rb", "w") do |extconf_rb| extconf_rb.write extconf end File.open(@ext_dir + "/" + scanner_name + ".yy", "w") do |scanner| scanner.write generate end end |