Class: Mulang::Code
- Inherits:
-
Object
- Object
- Mulang::Code
- Defined in:
- lib/mulang/code.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#language ⇒ Object
Returns the value of attribute language.
Class Method Summary collapse
- .analyse_many(codes, spec, **options) ⇒ Object
- .ast_many(codes, **options) ⇒ Object
- .external(language_name = nil, content, &tool) ⇒ Object
- .native(language_name, content) ⇒ Object
- .native!(*args) ⇒ Object
- .run_many(codes, key: nil, **options) ⇒ Object
- .transformed_asts_many(codes, operations, **options) ⇒ Object
Instance Method Summary collapse
- #analyse(spec, **options) ⇒ Object
- #analysis(spec, **options) ⇒ Object
- #ast(**options) ⇒ Object
- #ast_analysis(**options) ⇒ Object
- #custom_expect(edl) ⇒ Object (also: #custom_query)
- #expect(binding = '*', inspection) ⇒ Object (also: #query)
- #identifiers(**options) ⇒ Object
-
#initialize(language, content) ⇒ Code
constructor
A new instance of Code.
- #sample ⇒ Object
- #transformed_asts(operations, **options) ⇒ Object
- #transformed_asts_analysis(operations, **options) ⇒ Object
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
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/mulang/code.rb', line 3 def content @content end |
#language ⇒ Object
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, **) run_many(codes, **) { |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, **) run_many(codes, key: 'outputAst', **) { |it| it.ast_analysis(**) } 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, **) result = Mulang.analyse(codes.map { |it| yield it }, **) 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, **) run_many(codes, key: 'transformedAsts', **) { |it| it.transformed_asts_analysis(operations, **) } end |
Instance Method Details
#analyse(spec, **options) ⇒ Object
37 38 39 |
# File 'lib/mulang/code.rb', line 37 def analyse(spec, **) Mulang.analyse analysis(spec), ** end |
#analysis(spec, **options) ⇒ Object
33 34 35 |
# File 'lib/mulang/code.rb', line 33 def analysis(spec, **) @language.build_analysis @content, spec, ** end |
#ast(**options) ⇒ Object
13 14 15 |
# File 'lib/mulang/code.rb', line 13 def ast(**) @language.ast @content, ** end |
#ast_analysis(**options) ⇒ Object
17 18 19 |
# File 'lib/mulang/code.rb', line 17 def ast_analysis(**) @language.ast_analysis @content, ** 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(**) @language.identifiers @content, ** end |
#sample ⇒ Object
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, **) @language.transformed_asts @content, operations, ** end |
#transformed_asts_analysis(operations, **options) ⇒ Object
25 26 27 |
# File 'lib/mulang/code.rb', line 25 def transformed_asts_analysis(operations, **) @language.transformed_asts_analysis @content, operations, ** end |