Class: TracePreprocessor::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/trace_preprocessor/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDSL

Returns a new instance of DSL.



11
12
13
14
15
16
# File 'lib/trace_preprocessor/dsl.rb', line 11

def initialize
  @lexemes = {}
  @code = ""
  
  workspace "~/.trace_preprocessor"
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



57
58
59
# File 'lib/trace_preprocessor/dsl.rb', line 57

def code
  @code
end

#lexemesObject

Returns the value of attribute lexemes.



56
57
58
# File 'lib/trace_preprocessor/dsl.rb', line 56

def lexemes
  @lexemes
end

#output_token_codeObject

Returns the value of attribute output_token_code.



57
58
59
# File 'lib/trace_preprocessor/dsl.rb', line 57

def output_token_code
  @output_token_code
end

#workspace_pathObject

Returns the value of attribute workspace_path.



58
59
60
# File 'lib/trace_preprocessor/dsl.rb', line 58

def workspace_path
  @workspace_path
end

Instance Method Details

#common_code(code) ⇒ Object



40
41
42
# File 'lib/trace_preprocessor/dsl.rb', line 40

def common_code code
  @code += code
end

#define_lexeme(name, options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/trace_preprocessor/dsl.rb', line 22

def define_lexeme name, options
  lexeme = @lexemes[name] || Lexeme.new(name, options)
  
  converter = options[:converter]
  converter_language = :c
  converter_language = :ruby if converter.instance_of? Proc
  lexeme.converter[converter_language] = converter
  
  @lexemes[lexeme.name] = lexeme
  
  lexeme
end

#init(&block) ⇒ Object



18
19
20
# File 'lib/trace_preprocessor/dsl.rb', line 18

def init &block
  instance_eval &block
end

#output_token(code) ⇒ Object



44
45
46
# File 'lib/trace_preprocessor/dsl.rb', line 44

def output_token code
  @output_token_code = code
end

#use_default_lexemesObject



35
36
37
38
# File 'lib/trace_preprocessor/dsl.rb', line 35

def use_default_lexemes
  default_lexemes_file_name = File.join(File.dirname(__FILE__), "default_lexemes.rb")
  eval open(default_lexemes_file_name, "r") { |fd| fd.read }
end

#workspace(path) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/trace_preprocessor/dsl.rb', line 48

def workspace path
  @workspace_path = File.expand_path path
  
  if not File.exist? @workspace_path
    FileUtils.mkdir_p @workspace_path
  end
end