dzintars 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84d1bee3c2aefa2ac0c30b0cfc3d26d7df4bf176
4
+ data.tar.gz: 4e0bfe5864d831586fef8cd39bb2d6b1f6632d8a
5
+ SHA512:
6
+ metadata.gz: 0608656044beb216e9d2f3ae3c9e6d3cd4fe015acddaf5c9fc6e6fdf3d1e9c1246e2518215841133446dbafdc12ed93fa3333071d5e7473726ddb58f17db41fc
7
+ data.tar.gz: 4a390e19e67e9617908df911f112a261c912d09a1ddd52422d3165853186053289ccc676bc05e5b371bb7b06eedb2b47061d0a6b55b7027901fbedc54db3fa23
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rvmrc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dzintars.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Raimonds Simanovskis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Dzintars
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dzintars'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dzintars
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "dzintars/kompilators"
4
+
5
+ if faila_nosaukums = ARGV[0]
6
+ kompilators = Dzintars::Kompilators.new
7
+ dzintara_kods = File.read faila_nosaukums
8
+ ruby_kods = kompilators.uz_ruby dzintara_kods
9
+ eval ruby_kods
10
+
11
+ else
12
+ puts <<-EOS
13
+ Nav norādīts fails. Pareiza sintakse ir:
14
+
15
+ dzintars fails.dz
16
+ EOS
17
+
18
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dzintars/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dzintars"
8
+ spec.version = Dzintars::VERSION
9
+ spec.authors = ["Raimonds Simanovskis"]
10
+ spec.email = ["raimonds.simanovskis@gmail.com"]
11
+ spec.description = %q{Programmēšanas valoda Dzintars}
12
+ spec.summary = %q{Programmēšanas valoda Dzintars ir Ruby ar latviešu sintaksi.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "ruby2ruby"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,5 @@
1
+ ja 1 > 0
2
+ izdrukāt_virkni "Sveika pasaule!"
3
+ citādi
4
+ izdrukāt_virkni "Kaut kas ir sabojājies"
5
+ beigas
@@ -0,0 +1,5 @@
1
+ require "dzintars/version"
2
+
3
+ module Dzintars
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1 @@
1
+ require "dzintars/core_ext/kernel"
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module Kernel
4
+ alias_method :izdrukāt_virkni, :puts
5
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ require 'ruby2ruby'
4
+ require 'ruby_parser'
5
+ require 'dzintars/ruby_parser_patches'
6
+
7
+ module Dzintars
8
+
9
+ class Kompilators
10
+
11
+ def initialize
12
+
13
+ end
14
+
15
+ SĀKUMA_KODS = "# encoding: utf-8\nrequire \"dzintars/core_ext\"\n"
16
+
17
+ def uz_ruby(kods)
18
+ ruby2ruby = Ruby2Ruby.new
19
+ parser = RubyParser.new
20
+ sexp = parser.process("# encoding: utf-8\n#{kods}")
21
+
22
+ ruby_kods = ruby2ruby.process(sexp)
23
+
24
+ "#{SĀKUMA_KODS}#{ruby_kods}"
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
@@ -0,0 +1,113 @@
1
+ class RubyLexer
2
+ ##
3
+ # Parse a number from the input stream.
4
+ #
5
+ # @param c The first character of the number.
6
+ # @return A int constant wich represents a token.
7
+
8
+ def parse_number
9
+ self.lex_state = :expr_end
10
+
11
+ case
12
+ when src.scan(/[+-]?0[xXbBdD]\b/) then
13
+ rb_compile_error "Invalid numeric format"
14
+ # when src.scan(/[+-]?(?:(?:[1-9][\d_]*|0)(?!\.\d)\b|0[Dd][0-9_]+)/) then
15
+ when src.scan(/[+-]?(?:(?:[1-9][\d_]*|0)(?!\,\d)\b|0[Dd][0-9_]+)/) then
16
+ int_with_base(10)
17
+ when src.scan(/[+-]?0x[a-f0-9_]+/i) then
18
+ int_with_base(16)
19
+ when src.scan(/[+-]?0[Bb][01_]+/) then
20
+ int_with_base(2)
21
+ when src.scan(/[+-]?0[Oo]?[0-7_]*[89]/) then
22
+ rb_compile_error "Illegal octal digit."
23
+ when src.scan(/[+-]?0[Oo]?[0-7_]+|0[Oo]/) then
24
+ int_with_base(8)
25
+ when src.scan(/[+-]?[\d_]+_(e|\.)/) then
26
+ rb_compile_error "Trailing '_' in number."
27
+ # when src.scan(/[+-]?[\d_]+\.[\d_]+(e[+-]?[\d_]+)?\b|[+-]?[\d_]+e[+-]?[\d_]+\b/i) then
28
+ when src.scan(/[+-]?[\d_]+\,[\d_]+(e[+-]?[\d_]+)?\b|[+-]?[\d_]+e[+-]?[\d_]+\b/i) then
29
+ number = src.matched.sub(',', '.')
30
+ if number =~ /__/ then
31
+ rb_compile_error "Invalid numeric format"
32
+ end
33
+ self.yacc_value = number.to_f
34
+ :tFLOAT
35
+ when src.scan(/[+-]?[0-9_]+(?![e])/) then
36
+ int_with_base(10)
37
+ else
38
+ rb_compile_error "Bad number format"
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ module RubyParserStuff
45
+ class Keyword
46
+ wordlist = [
47
+ ["beigas", [:kEND, :kEND ], :expr_end ],
48
+ ["citādi", [:kELSE, :kELSE ], :expr_beg ],
49
+ ["case", [:kCASE, :kCASE ], :expr_beg ],
50
+ ["ensure", [:kENSURE, :kENSURE ], :expr_beg ],
51
+ ["module", [:kMODULE, :kMODULE ], :expr_beg ],
52
+ ["elsif", [:kELSIF, :kELSIF ], :expr_beg ],
53
+ ["def", [:kDEF, :kDEF ], :expr_fname ],
54
+ ["rescue", [:kRESCUE, :kRESCUE_MOD ], :expr_mid ],
55
+ ["not", [:kNOT, :kNOT ], :expr_beg ],
56
+ ["tad", [:kTHEN, :kTHEN ], :expr_beg ],
57
+ ["yield", [:kYIELD, :kYIELD ], :expr_arg ],
58
+ ["for", [:kFOR, :kFOR ], :expr_beg ],
59
+ ["self", [:kSELF, :kSELF ], :expr_end ],
60
+ ["false", [:kFALSE, :kFALSE ], :expr_end ],
61
+ ["retry", [:kRETRY, :kRETRY ], :expr_end ],
62
+ ["return", [:kRETURN, :kRETURN ], :expr_mid ],
63
+ ["patiess", [:kTRUE, :kTRUE ], :expr_end ],
64
+ ["ja", [:kIF, :kIF_MOD ], :expr_beg ],
65
+ ["defined?", [:kDEFINED, :kDEFINED ], :expr_arg ],
66
+ ["super", [:kSUPER, :kSUPER ], :expr_arg ],
67
+ ["undef", [:kUNDEF, :kUNDEF ], :expr_fname ],
68
+ ["break", [:kBREAK, :kBREAK ], :expr_mid ],
69
+ ["in", [:kIN, :kIN ], :expr_beg ],
70
+ ["do", [:kDO, :kDO ], :expr_beg ],
71
+ ["nil", [:kNIL, :kNIL ], :expr_end ],
72
+ ["until", [:kUNTIL, :kUNTIL_MOD ], :expr_beg ],
73
+ ["unless", [:kUNLESS, :kUNLESS_MOD ], :expr_beg ],
74
+ ["or", [:kOR, :kOR ], :expr_beg ],
75
+ ["next", [:kNEXT, :kNEXT ], :expr_mid ],
76
+ ["when", [:kWHEN, :kWHEN ], :expr_beg ],
77
+ ["redo", [:kREDO, :kREDO ], :expr_end ],
78
+ ["and", [:kAND, :kAND ], :expr_beg ],
79
+ ["begin", [:kBEGIN, :kBEGIN ], :expr_beg ],
80
+ ["__LINE__", [:k__LINE__, :k__LINE__ ], :expr_end ],
81
+ ["class", [:kCLASS, :kCLASS ], :expr_class ],
82
+ ["__FILE__", [:k__FILE__, :k__FILE__ ], :expr_end ],
83
+ ["END", [:klEND, :klEND ], :expr_end ],
84
+ ["BEGIN", [:klBEGIN, :klBEGIN ], :expr_end ],
85
+ ["while", [:kWHILE, :kWHILE_MOD ], :expr_beg ],
86
+ ["alias", [:kALIAS, :kALIAS ], :expr_fname ],
87
+ ["__ENCODING__", [:k__ENCODING__, :k__ENCODING__], :expr_end],
88
+ ].map { |args| KWtable.new(*args) }
89
+
90
+ # :startdoc:
91
+
92
+ original_verbosity = $VERBOSE
93
+ $VERBOSE = nil
94
+
95
+ WORDLIST18 = Hash[*wordlist.map { |o| [o.name, o] }.flatten]
96
+ WORDLIST19 = Hash[*wordlist.map { |o| [o.name, o] }.flatten]
97
+
98
+ $VERBOSE = original_verbosity
99
+
100
+ WORDLIST18.delete "__ENCODING__"
101
+
102
+ %w[and case elsif for ja in module or unless until when while].each do |k|
103
+ WORDLIST19[k] = WORDLIST19[k].dup
104
+ WORDLIST19[k].state = :expr_value
105
+ end
106
+ %w[not].each do |k|
107
+ WORDLIST19[k] = WORDLIST19[k].dup
108
+ WORDLIST19[k].state = :expr_arg
109
+ end
110
+
111
+ end
112
+ end
113
+
@@ -0,0 +1,3 @@
1
+ module Dzintars
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe "Kompilators" do
5
+ let(:sākuma_kods) do
6
+ "# encoding: utf-8\nrequire \"dzintars/core_ext\"\n"
7
+ end
8
+
9
+ let(:kompilators) do
10
+ Dzintars::Kompilators.new
11
+ end
12
+
13
+ tas "nokompilē tukšu Dzintara programmu" do
14
+ kompilators.uz_ruby("").should == sākuma_kods + ""
15
+ end
16
+
17
+ describe "skaitļi" do
18
+
19
+ tas "nokompilē veselu skaitli" do
20
+ kompilators.uz_ruby("1").should == sākuma_kods + "1"
21
+ end
22
+
23
+ tas "nokompilē daļskaitli" do
24
+ kompilators.uz_ruby("1,2").should == sākuma_kods + "1.2"
25
+ end
26
+
27
+ tas "nokompilē daļskaitli" do
28
+ kompilators.uz_ruby("1,2").should == sākuma_kods + "1.2"
29
+ end
30
+
31
+ tas "nokompilē sarakstu ar daļskaitli un veselu skaitli" do
32
+ kompilators.uz_ruby("[1,2, 3]").should == sākuma_kods + "[1.2, 3]"
33
+ end
34
+
35
+ end
36
+
37
+ describe "atslēgvārdi" do
38
+ tas "aizvieto ja / tad / citādi / beigas" do
39
+ kompilators.uz_ruby("ja 1 tad\n2\ncitādi\n3\nbeigas").should ==
40
+ sākuma_kods + "1 ? (2) : (3)"
41
+ end
42
+ end
43
+
44
+ describe "Kernel metodes" do
45
+ tas "izveido puts iesauku izdrukāt_virkni" do
46
+ kompilators.uz_ruby("izdrukāt_virkni 'abc'").should ==
47
+ sākuma_kods + "izdrukāt_virkni(\"abc\")"
48
+ end
49
+ end
50
+
51
+
52
+ end
@@ -0,0 +1,28 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
18
+
19
+ # TODO: kā pareizi izveidot describe aliasu?
20
+ # RSpec::Core::DSL.module_eval do
21
+ # alias_method :apraksta, :describe
22
+ # end
23
+
24
+ class << RSpec::Core::ExampleGroup
25
+ define_example_method :tas
26
+ end
27
+
28
+ require "dzintars/kompilators"
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dzintars
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Raimonds Simanovskis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby2ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Programmēšanas valoda Dzintars
70
+ email:
71
+ - raimonds.simanovskis@gmail.com
72
+ executables:
73
+ - dzintars
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/dzintars
84
+ - dzintars.gemspec
85
+ - examples/sveika_pasaule.dz
86
+ - lib/dzintars.rb
87
+ - lib/dzintars/core_ext.rb
88
+ - lib/dzintars/core_ext/kernel.rb
89
+ - lib/dzintars/kompilators.rb
90
+ - lib/dzintars/ruby_parser_patches.rb
91
+ - lib/dzintars/version.rb
92
+ - spec/dzintars/kompilators_spec.rb
93
+ - spec/spec_helper.rb
94
+ homepage: ''
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Programmēšanas valoda Dzintars ir Ruby ar latviešu sintaksi.
118
+ test_files:
119
+ - spec/dzintars/kompilators_spec.rb
120
+ - spec/spec_helper.rb