jaina 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b071350b636b4d475d51836639fa20c3b62f5518eddd4d0e71aa70cf9a9a1f9
4
- data.tar.gz: eec63665a26dc9de484fd162795332e79762e2b4da24a637753468b06c5cfd8b
3
+ metadata.gz: 021a99a70e1f530c83857667a7c0defdd785abc635931167fe2a9bd45bf1393f
4
+ data.tar.gz: fe1956e513688b643365ed85a55a02226a18b5adc75ee202130f7b1dab8404ab
5
5
  SHA512:
6
- metadata.gz: 56422133b95ab2bbfdcb720aea41a320d0c147e26ffca1de3fcf1a7cc013af2bb2cc9462634eee9dc4f1296584a6488b9fc63555aafc6bd37814e01d000c6f35
7
- data.tar.gz: e5127b38022694809fd58644d86b9434bd4e368d1467b2a13d36ebe22103b5117a29bc2aaa11b6298dae0109f1ae6dea9f0d11983db52e45c3f1b447000ee54b
6
+ metadata.gz: 0d147dbfe65aef16511b703b52100b00f28b81695c1e18906b166180c49629cd6b8cc07ccf362022a04fc7897f0e9625e3a10969d52ad2a7f3606755941c8a6e
7
+ data.tar.gz: 39ca3e5fadb5341a29f363f4ec3426395edb214c4041620ccea19282d49602edeef417b641659dc38d17e01a81b9baf696258e8f86b3455f20f4cf9979791610
data/.travis.yml CHANGED
@@ -15,5 +15,5 @@ sudo: false
15
15
  cache: bundler
16
16
  before_install: gem install bundler
17
17
  script:
18
- - bundke exec rubocop
18
+ - bundle exec rubocop
19
19
  - bundle exec rspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## [0.2.0] - 2019-06-21
5
+ ### Added
6
+ - `#evaluate(context)` implementation for all core operators (`AND`, `OR`, `NOT`);
7
+
8
+ ## [0.1.0] - 2018-06-19
9
+ - Release :)
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Jaina · [![Gem Version](https://badge.fury.io/rb/jaina.svg)](https://badge.fury.io/rb/jaina) [![Build Status](https://travis-ci.org/0exp/jaina.svg?branch=master)](https://travis-ci.org/0exp/jaina) [![Coverage Status](https://coveralls.io/repos/github/0exp/jaina/badge.svg?branch=master)](https://coveralls.io/github/0exp/jaina?branch=master)
2
2
 
3
3
  Simple programming language builder inspired by interpreter pattern.
4
+ You can build your own languages with custom operands and operators for any project purposes.
4
5
 
5
6
  ## Installation
6
7
 
data/jaina.gemspec CHANGED
@@ -14,7 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = 'https://github.com/0exp/jaina'
15
15
  spec.summary = 'Simple programming language builder inspired by interpreter pattern.'
16
16
  spec.description = 'Simple programming language builder inspired by interpreter pattern. ' \
17
- 'You can build your own langs for any project purposes.'
17
+ 'You can build your own languages with custom operands and operators ' \
18
+ 'for any project purposes.'
18
19
 
19
20
  spec.bindir = 'bin'
20
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -33,7 +33,7 @@ class Jaina::Parser::AST::Context
33
33
  # @api public
34
34
  # @since 0.1.0
35
35
  def get(key)
36
- thread_safe { get(key) }
36
+ thread_safe { fetch(key) }
37
37
  end
38
38
 
39
39
  # @return [Array<Any>]
@@ -10,8 +10,12 @@ module Jaina::Parser::AST::Evaluator
10
10
  # @api private
11
11
  # @since 0.1.0
12
12
  def evaluate(ast)
13
+ # NOTE: build shared context for a program
13
14
  context = Jaina::Parser::AST::Context.new
14
- # TODO: traverse the abstract syntax tree
15
+
16
+ # NOTE: evaluate the root expression of AST
17
+ # NOTE: root is an atity of type [Jaina::Parser::Expression::Operator::Abstract]
18
+ ast.root.evaluate(context)
15
19
  end
16
20
  end
17
21
  end
@@ -32,4 +32,10 @@ class Jaina::Parser::AST::Tree
32
32
  @ast_oriented_program = ast_oriented_program
33
33
  @expression = expression
34
34
  end
35
+
36
+ # @return [Jaina::Parser::Expression::operator::Abstract]
37
+ #
38
+ # @api private
39
+ # @since 0.1.0
40
+ alias_method :root, :expression
35
41
  end
@@ -3,6 +3,9 @@
3
3
  # @api private
4
4
  # @since 0.1.0
5
5
  class Jaina::Parser::AST
6
+ # @since 0.2.0
7
+ extend Forwardable
8
+
6
9
  require_relative './ast/tree'
7
10
  require_relative './ast/tree_builder'
8
11
  require_relative './ast/evaluator'
@@ -18,15 +21,6 @@ class Jaina::Parser::AST
18
21
  ast_tree = Jaina::Parser::AST::TreeBuilder.build(program)
19
22
  new(program, ast_tree)
20
23
  end
21
-
22
- # @param program [String] Program string in prefix form
23
- # @return [Any]
24
- #
25
- # @api private
26
- # @since 0.1.0
27
- def evaluate(program)
28
- build(program).evaluate
29
- end
30
24
  end
31
25
 
32
26
  # @return [Jaina::Pasrer::AST::Tree]
@@ -41,6 +35,9 @@ class Jaina::Parser::AST
41
35
  # @since 0.1.0
42
36
  attr_reader :program
43
37
 
38
+ # @since 0.2.0
39
+ def_delegator :ast_tree, :root
40
+
44
41
  # @param program [String]
45
42
  # @param ast_tree [Jaina::Parser::AST::Tree]
46
43
  # @return [void]
@@ -13,7 +13,7 @@ class Jaina::Parser::CodeConverter
13
13
  # @api private
14
14
  # @since 0.1.0
15
15
  def to_postfix_form(program)
16
- ToPrefixForm.call(program)
16
+ ToPostfixForm.call(program)
17
17
  end
18
18
 
19
19
  # @param program [String]
@@ -8,5 +8,30 @@ module Jaina::Parser::Expression::Operator
8
8
  associativity_direction :left
9
9
  token 'AND'
10
10
  acts_as_binary_term
11
+
12
+ # @param context [Jaina::Parser::AST::Context]
13
+ # @return [Any]
14
+ #
15
+ # @api private
16
+ # @since 0.2.0
17
+ def evaluate(context)
18
+ left_expression.evaluate(context) && right_expression.evaluate(context)
19
+ end
20
+
21
+ # @return [Jaina::Parser::Expression::Operator::Abstract]
22
+ #
23
+ # @api private
24
+ # @since 0.2.0
25
+ def left_expression
26
+ expressions[0]
27
+ end
28
+
29
+ # @return [Jaina::Parser::Expression::Operator::Abstract]
30
+ #
31
+ # @api private
32
+ # @since 0.2.0
33
+ def right_expression
34
+ expressions[1]
35
+ end
11
36
  end
12
37
  end
@@ -8,5 +8,22 @@ module Jaina::Parser::Expression::Operator
8
8
  associativity_direction :right
9
9
  token 'NOT'
10
10
  acts_as_unary_term
11
+
12
+ # @param context [Jaina::Parser::AST::Context]
13
+ # @return [Any]
14
+ #
15
+ # @api private
16
+ # @since 0.2.0
17
+ def evaluate(contenxt)
18
+ !expression.evaluate(context)
19
+ end
20
+
21
+ # @return [Jaina::Parser::Expression::Operator::Abstract]
22
+ #
23
+ # @api private
24
+ # @since 0.2.0
25
+ def expression
26
+ expressions.first
27
+ end
11
28
  end
12
29
  end
@@ -8,5 +8,30 @@ module Jaina::Parser::Expression::Operator
8
8
  associativity_direction :left
9
9
  token 'OR'
10
10
  acts_as_binary_term
11
+
12
+ # @param context [Jaina::Parser::AST::Context]
13
+ # @return [Any]
14
+ #
15
+ # @api private
16
+ # @since 0.2.0
17
+ def evaluate(context)
18
+ left_expression.evaluate(context) || right_expression.evaluate(context)
19
+ end
20
+
21
+ # @return [Jaina::Parser::Expression::Operator::Abstract]
22
+ #
23
+ # @api private
24
+ # @since 0.2.0
25
+ def left_expression
26
+ expressions.first
27
+ end
28
+
29
+ # @return [Jaina::Parser::Expression::Operator::Abstract]
30
+ #
31
+ # @api private
32
+ # @since 0.2.0
33
+ def right_expression
34
+ expressions.second
35
+ end
11
36
  end
12
37
  end
data/lib/jaina/version.rb CHANGED
@@ -5,5 +5,5 @@ module Jaina
5
5
  #
6
6
  # @api public
7
7
  # @since 0.0.0
8
- VERSION = '0.1.0'
8
+ VERSION = '0.2.0'
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jaina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2019-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -109,7 +109,8 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Simple programming language builder inspired by interpreter pattern.
112
- You can build your own langs for any project purposes.
112
+ You can build your own languages with custom operands and operators for any project
113
+ purposes.
113
114
  email:
114
115
  - iamdaiver@icloud.com
115
116
  executables: []
@@ -120,6 +121,7 @@ files:
120
121
  - ".rspec"
121
122
  - ".rubocop.yml"
122
123
  - ".travis.yml"
124
+ - CHANGELOG.md
123
125
  - Gemfile
124
126
  - README.md
125
127
  - Rakefile