Class: Error

Inherits:
Object
  • Object
show all
Defined in:
lib/aml/error.rb

Instance Method Summary collapse

Constructor Details

#initializeError

Returns a new instance of Error.



4
5
6
7
# File 'lib/aml/error.rb', line 4

def initialize
  @errors = []
  @warnings = []
end

Instance Method Details

#compile(parse, definition, error) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/aml/error.rb', line 49

def compile(parse,definition,error)
  error.syntax(parse,false,false,error)
  #Check Tag, Partial, Mixin Call, and Method Call Attributes for Errors
  parse.watch.each do |file|
    if file[:partial]
      file_path = File.join(AbstractMarkupLanguage::Base.basePath,'partial')
      file_path = File.join(AbstractMarkupLanguage::Base.basePath,file[:bundle],'partial') if file[:bundle]
      partial_parse = Parse.new(file_path,file[:file])
      error.syntax(partial_parse,file[:bundle],file[:partial],error)
    end
  end
  #Check Mixin Definitions for Errors
  definition.mixins.each do |bundle,mixins|
    if(bundle != false and bundle != 'core')
      file_path = File.join(AbstractMarkupLanguage::Base.basePath,bundle)
      mixin_parse = Parse.new(file_path,'mixin.aml')
      error.syntax(mixin_parse,bundle,false,error)
    end
  end
end

#countObject



22
23
24
# File 'lib/aml/error.rb', line 22

def count
  @errors.count
end

#log(bundle, partial, file, line, message, warning = false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/aml/error.rb', line 11

def log(bundle,partial,file,line,message,warning=false)
  file = "partial/#{file}" if partial != false
  file = "#{bundle}/#{file}" if bundle != false
  line = line ? "::#{line}" : nil
  text = "#{file}#{line} #{message}"
  if warning
    @warnings << text
  else
    @errors << text
  end
end

#log_createObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/aml/error.rb', line 31

def log_create
  error_output = ""
  @errors.each do |error|
    error_output += "Error: #{error}\r\n"
  end
  @warnings.each do |warning|
    error_output += "Warning: #{warning}\r\n"
  end
  File.write(File.join(AbstractMarkupLanguage::Base.basePath,'aml-log'),error_output)
end

#log_deleteObject



25
26
27
28
29
30
# File 'lib/aml/error.rb', line 25

def log_delete
  begin
    File.delete(File.join(AbstractMarkupLanguage::Base.basePath,'aml-log'))
  rescue Exception => e
  end
end

#matchObject



46
47
48
# File 'lib/aml/error.rb', line 46

def match
  /\((\w+)\)\:(?<line>\d+)\:(\s{1,})?(?<message>.+)/
end

#outputObject



41
42
43
44
45
# File 'lib/aml/error.rb', line 41

def output
  @errors.each do |error|
    error
  end
end

#syntax(parse, bundle = false, partial = false, error) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/aml/error.rb', line 69

def syntax(parse,bundle=false,partial=false,error)
  parse.file[:line].each do |line|
    if(line[:attributes] && line[:attributes][:abstract_markup_language_exception] or partial && line[:type] == :mixin_def)
      #Mixin definition in partials is not possible...
      if line[:type] == :mixin_def and partial
        file_to_define = bundle ? "#{bundle}/minxin.aml" : AbstractMarkupLanguage::Base.watchFile
        error.log(bundle,partial,parse.file[:name],line[:number],"mixin must be defined in #{file_to_define}; #{line[:name]} cannot be defined in a partial")
      else
        line[:type] = "mixin definition" if line[:type] == :mixin_def
        error.log(bundle,partial,parse.file[:name],line[:number],"attribute syntax error on #{line[:name]} #{line[:type]}") 
      end
    end
    if line[:type] == :method
      begin
        #ap AbstractMarkupLanguage::Base.const_get(definition.camelCase(line[:bundle])).method(line[:name]).call()
      rescue Exception => e
        message = "#{line[:name]} method undefined in #{line[:bundle]} bundle"
        if !AbstractMarkupLanguage::Base.constants.include? definition.camelCase(line[:bundle]).to_sym
          message = "#{line[:bundle]} bundle undefined"
        end
        error.log(bundle,partial,parse.file[:name],line[:number],message)
        false
      end
      #.method(line[:name]).call()
      #ap Base.const_get(line[:bundle]).method(line[:name]).call()
    end
  end
end

#warningsObject



8
9
10
# File 'lib/aml/error.rb', line 8

def warnings
  @warnings
end