Class: Mulang::Code

Inherits:
Object
  • Object
show all
Defined in:
lib/mulang/code.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language, content) ⇒ Code

Returns a new instance of Code.



4
5
6
7
# File 'lib/mulang/code.rb', line 4

def initialize(language, content)
  @language = language
  @content  = content
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/mulang/code.rb', line 3

def content
  @content
end

#languageObject

Returns the value of attribute language.



3
4
5
# File 'lib/mulang/code.rb', line 3

def language
  @language
end

Class Method Details

.analyse_many(codes, spec, **options) ⇒ Object



67
68
69
# File 'lib/mulang/code.rb', line 67

def self.analyse_many(codes, spec, **options)
  run_many(codes, **options) { |it| it.analysis(spec)  }
end

.ast_many(codes, **options) ⇒ Object



71
72
73
# File 'lib/mulang/code.rb', line 71

def self.ast_many(codes, **options)
  run_many(codes, key: 'outputAst', **options) { |it| it.ast_analysis(**options) }
end

.external(language_name = nil, content, &tool) ⇒ Object



63
64
65
# File 'lib/mulang/code.rb', line 63

def self.external(language_name = nil, content, &tool)
  new Mulang::Language::External.new(language_name, &tool), content
end

.native(language_name, content) ⇒ Object



55
56
57
# File 'lib/mulang/code.rb', line 55

def self.native(language_name, content)
  new Mulang::Language::Native.new(language_name), content
end

.native!(*args) ⇒ Object



59
60
61
# File 'lib/mulang/code.rb', line 59

def self.native!(*args)
  native(*args).tap { |it| it.expect('Parses') }
end

.run_many(codes, key: nil, **options) ⇒ Object



79
80
81
82
# File 'lib/mulang/code.rb', line 79

def self.run_many(codes, key: nil, **options)
  result = Mulang.analyse(codes.map { |it| yield it }, **options)
  key ? result.map { |it| it[key] } : result
end

.transformed_asts_many(codes, operations, **options) ⇒ Object



75
76
77
# File 'lib/mulang/code.rb', line 75

def self.transformed_asts_many(codes, operations, **options)
  run_many(codes, key: 'transformedAsts', **options) { |it| it.transformed_asts_analysis(operations, **options) }
end

Instance Method Details

#analyse(spec, **options) ⇒ Object



37
38
39
# File 'lib/mulang/code.rb', line 37

def analyse(spec, **options)
  Mulang.analyse analysis(spec), **options
end

#analysis(spec, **options) ⇒ Object



33
34
35
# File 'lib/mulang/code.rb', line 33

def analysis(spec, **options)
  @language.build_analysis @content, spec, **options
end

#ast(**options) ⇒ Object



13
14
15
# File 'lib/mulang/code.rb', line 13

def ast(**options)
  @language.ast @content, **options
end

#ast_analysis(**options) ⇒ Object



17
18
19
# File 'lib/mulang/code.rb', line 17

def ast_analysis(**options)
  @language.ast_analysis @content, **options
end

#custom_expect(edl) ⇒ Object Also known as: custom_query



46
47
48
49
50
# File 'lib/mulang/code.rb', line 46

def custom_expect(edl)
  expectation_results_for(analyse({customExpectations: edl}))
    .map { |e| [e['expectation']['inspection'], e['result']] }
    .to_h
end

#expect(binding = '*', inspection) ⇒ Object Also known as: query



41
42
43
44
# File 'lib/mulang/code.rb', line 41

def expect(binding='*', inspection)
  expectation = Mulang::Expectation.parse(binding: binding, inspection: inspection).as_v2.to_h
  expectation_results_for(analyse({expectations: [expectation]})).first['result']
end

#identifiers(**options) ⇒ Object



9
10
11
# File 'lib/mulang/code.rb', line 9

def identifiers(**options)
  @language.identifiers @content, **options
end

#sampleObject



29
30
31
# File 'lib/mulang/code.rb', line 29

def sample
  @language.sample @content
end

#transformed_asts(operations, **options) ⇒ Object



21
22
23
# File 'lib/mulang/code.rb', line 21

def transformed_asts(operations, **options)
  @language.transformed_asts @content, operations, **options
end

#transformed_asts_analysis(operations, **options) ⇒ Object



25
26
27
# File 'lib/mulang/code.rb', line 25

def transformed_asts_analysis(operations, **options)
  @language.transformed_asts_analysis @content, operations, **options
end