uga_uga 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e475b295a76d004debe5c9f8b5f1ce5bb44b0af
4
+ data.tar.gz: eccdc212ac1896218ad9491fee0b8754694c5703
5
+ SHA512:
6
+ metadata.gz: 00f18ca1b2ada9fefcdae9a6a860ea46fd1cd14678ffaa1142c4ed0a07f114571a138d2ee54c9e2bbe48180c80c7caa917803c74add98c18585be4e2fdad35d7
7
+ data.tar.gz: 348bd55a6fcce453c15e138fdfb0b97895c8b6fc3ef6da858787430675664d4ba2085c0566fbc6e5984ad7061d8f43ee625e74bdbff3cdff061936bd7ddb0532
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ node_modules/
19
+ bin/bower
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+
2
+ Copyright (c) 2015 da99
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+
2
+ # Uga\_Uga
3
+
4
+ Don't use this.
5
+ Use [Treetop](https://github.com/nathansobo/treetop) or [OMeta](https://github.com/alexwarth/ometa-js).
6
+
7
+ ## Installation
8
+
9
+ gem 'uga_uga'
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ require "uga_uga"
15
+
16
+ code = <<-EOF
17
+ bobby {
18
+ howie { :funny }
19
+ mandel { "comedian" }
20
+ }
21
+ EOF
22
+
23
+ results = []
24
+
25
+ Uga_Uga.uga code do |name, blok|
26
+
27
+ case name
28
+
29
+ when "bobby"
30
+ results << "bobby was called"
31
+ blok
32
+
33
+ when "howie"
34
+ results << "howie was called"
35
+ blok
36
+
37
+ when "mandel"
38
+ results << "mandel was called"
39
+ blok
40
+
41
+ when ":funny", '"comedian"'
42
+
43
+ else
44
+ fail ArgumentError, "Command not found: #{name.inspect}"
45
+ end
46
+
47
+ end
48
+
49
+ puts results.inspect
50
+
51
+ ```
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/uga_uga ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env bash
2
+ # -*- bash -*-
3
+ #
4
+ #
5
+ set -u -e -o pipefail
6
+
7
+ action="$1"
8
+ shift
9
+
10
+ case "$action" in
11
+
12
+ "help")
13
+ echo " ====================================================="
14
+ echo ""
15
+ echo " $ uga_uga watch"
16
+ echo ""
17
+ echo " $ uga_uga test"
18
+ echo " $ uga_uga test name"
19
+ echo ""
20
+ echo " ====================================================="
21
+ echo ""
22
+ exit 0
23
+ ;; # === start
24
+
25
+ "watch")
26
+ echo "=== Watching: "
27
+ bin/uga_uga test "$@" || true
28
+
29
+ inotifywait -q --exclude .git/ -e close_write,close -m -r . | while read CHANGE
30
+ do
31
+ dir=$(echo "$CHANGE" | cut -d' ' -f 1)
32
+ op=$(echo "$CHANGE" | cut -d' ' -f 2)
33
+ file=$(echo "$CHANGE" | cut -d' ' -f 3)
34
+ path="${dir}$file"
35
+
36
+ if [[ ( ! "$op" =~ "NOWRITE" ) && ( "$op" =~ "CLOSE" || "$op" =~ "WRITE" ) && ! -z "$file" ]]
37
+ then
38
+ echo ""
39
+ if [[ "$file" == *.js* ]]; then
40
+ echo ""
41
+ echo "=== Runninig jshint on $path: $CHANGE"
42
+ (jshint "$path" && echo "No errors.") || true
43
+ fi
44
+
45
+ if [[ "$path" == *bin/uga_uga* ]]; then
46
+ echo ""
47
+ echo "=== Restarting:"
48
+ exec $path "watch" "$@"
49
+ fi
50
+
51
+ if [[ "$file" == *.rb* || "$path" == *spec* ]]; then
52
+ echo "=== Running tests: $@"
53
+ bin/uga_uga test "$@" || true
54
+ fi
55
+ fi # === if file op
56
+
57
+ done
58
+
59
+ ;; # === watch
60
+
61
+ "test")
62
+ files=""
63
+ if [[ ! -z "$@" ]]; then
64
+ files="$(echo -n specs/*-$1.rb)"
65
+ if [[ -f "$files" ]]; then
66
+ shift
67
+ else
68
+ files=""
69
+ fi
70
+ fi
71
+
72
+ if [[ -z "$files" ]]; then
73
+ files="$(echo -n specs/*.rb | tr ' ' '\n' | sort)"
74
+ fi
75
+
76
+ if [[ -z "$files" ]]; then
77
+ colorize yellow "No tests found." 1>&2
78
+ exit 0
79
+ else
80
+ bundle exec bacon specs/lib/helpers.rb $files "$@"
81
+ fi
82
+ ;; # === test
83
+
84
+ *)
85
+ echo "=== Unknown action: $action" 1>&2
86
+ exit 1
87
+ ;;
88
+
89
+ esac
data/lib/uga_uga.rb ADDED
@@ -0,0 +1,98 @@
1
+
2
+ class Uga_Uga
3
+
4
+ class << self
5
+
6
+ def uga origin
7
+ tokens = blockenize(tokenize(origin))
8
+
9
+ case
10
+ when block_given?
11
+ run(tokens) do |cmd, block|
12
+ yield cmd, block
13
+ end
14
+ else
15
+ tokens
16
+ end
17
+ end
18
+
19
+ def tokenize origin
20
+ origin.split(/(\n)|((?<!\{)\{(?!\{))|((?<!\})\}(?!\}))/)
21
+ end
22
+
23
+ def blockenize raw
24
+ tokens = raw.dup
25
+ final = []
26
+ stack = []
27
+ current = final
28
+ last = nil
29
+ while t = tokens.shift
30
+ case t
31
+ when '{'
32
+ stack << current
33
+ current << (b = [])
34
+ current = b
35
+ when '}'
36
+ current = stack.pop
37
+ when ''
38
+ # ignore
39
+ else
40
+ current << t
41
+ end
42
+ end # === while
43
+ final
44
+ end
45
+
46
+ #
47
+ # This method is used mainly used in
48
+ # tests/specs to remove the "noise"
49
+ # (whitespace, empty lines, etc)
50
+ # during parsing.
51
+ #
52
+ def clean arg
53
+ case arg
54
+
55
+ when String
56
+ str = arg.strip
57
+ return nil if str.empty?
58
+ str
59
+
60
+ when Array
61
+ arg.map { |unknown| clean unknown }.compact
62
+
63
+ else
64
+ arg
65
+
66
+ end
67
+ end
68
+
69
+ def run raw
70
+ arr = raw.dup
71
+ while t = arr.shift
72
+ case
73
+
74
+ when t.is_a?(String) && arr.first.is_a?(Array)
75
+ blok = arr.shift
76
+ results = yield t.strip, blok
77
+ if results == blok
78
+ run results do |arg1, arg2|
79
+ yield arg1, arg2
80
+ end
81
+ end
82
+
83
+ when t.is_a?(String) && (arr.first != arr.is_a?(Array))
84
+ str = t.strip
85
+ if !str.empty?
86
+ yield str, nil
87
+ end
88
+
89
+ else
90
+ fail ArgumentError, "Syntax: #{t.inspect} in #{raw.join.inspect}"
91
+
92
+ end
93
+ end
94
+ end # === def run
95
+
96
+ end # === class self ===
97
+
98
+ end # === class Uga_Uga ===
@@ -0,0 +1,137 @@
1
+
2
+ describe :uga.inspect do
3
+
4
+ it "runs" do
5
+ o = Uga_Uga.uga(<<-EOF)
6
+ p {
7
+ "my paragraph"
8
+ }
9
+ EOF
10
+
11
+ Uga_Uga.clean(o).should == [
12
+ 'p', ['"my paragraph"']
13
+ ]
14
+ end
15
+
16
+ it "runs code from README.md" do
17
+ file = File.expand_path(File.dirname(__FILE__) + '/../README.md')
18
+ contents = File.read( file )
19
+ code = (contents[/```ruby([^`]+)```/] && $1).gsub('puts ','')
20
+
21
+ result = eval(code, nil, file, contents.split("\n").index('```ruby') + 1)
22
+ result.should.match /bobby/
23
+ end # === it
24
+
25
+ it "parses lines without blocks" do
26
+ code = <<-EOF
27
+ a :href => addr
28
+ a :href addr
29
+ p { }
30
+ EOF
31
+
32
+ Uga_Uga.clean(Uga_Uga.uga code).
33
+ should == [ "a :href => addr",
34
+ "a :href addr",
35
+ "p", []
36
+ ]
37
+ end
38
+
39
+ it "parses inner blocks" do
40
+ code = <<-EOF
41
+ p {
42
+ span {
43
+ inner { "my" }
44
+ }
45
+ }
46
+ EOF
47
+
48
+ Uga_Uga.clean(Uga_Uga.uga code).
49
+ should == [
50
+ "p", [
51
+ "span", [
52
+ "inner", ['"my"']
53
+ ]
54
+ ]
55
+ ]
56
+ end
57
+
58
+ it "yields the inner block" do
59
+ result = []
60
+ code = <<-EOF
61
+ p {
62
+ span {
63
+ 1 {
64
+ 2 {
65
+ 3 { "my text" }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ EOF
71
+
72
+ Uga_Uga.uga(code) do |cmd, code|
73
+ if cmd['"']
74
+ result << cmd
75
+ else
76
+ result << cmd.to_sym
77
+ end
78
+ code
79
+ end
80
+
81
+ result.should == [:p, :span, :'1', :'2', :'3', '"my text"']
82
+ end # === it
83
+
84
+ it "passes all text before a block start: cmd, cmd {" do
85
+ result = []
86
+ code = %^
87
+ cmd, cmd {
88
+ inner, inner {
89
+ }
90
+ }
91
+ ^
92
+ Uga_Uga.uga(code) do |cmd, code|
93
+ result << cmd
94
+ code
95
+ end
96
+ result.should == ["cmd, cmd", "inner, inner"]
97
+ end # === it
98
+
99
+ it "yields lines without a block" do
100
+ code = "
101
+ br /
102
+ br /
103
+ p { }
104
+ "
105
+ result = []
106
+ Uga_Uga.uga(code) do |cmd, code|
107
+ result << cmd
108
+ code
109
+ end
110
+
111
+ result.should == ['br /', 'br /', 'p']
112
+ end # === it
113
+
114
+ it "passes block w/original whitespace" do
115
+ blok = "
116
+ a
117
+ a a
118
+ a
119
+ "
120
+ code = "
121
+ p {#{blok}}
122
+ "
123
+ result = nil
124
+ Uga_Uga.uga(code) { |cmd, code| result = code.join }
125
+ result.should == blok
126
+ end # === it
127
+
128
+ it "does not parse mustaches as blocks: {{ }}" do
129
+ code = "
130
+ p {{ code }}
131
+ "
132
+ result = nil
133
+ Uga_Uga.uga(code) { |cmd, code| result = cmd }
134
+ result.should == code.strip
135
+ end # === it
136
+
137
+ end # === describe :uga
@@ -0,0 +1,5 @@
1
+
2
+ require 'Bacon_Colored'
3
+ require 'uga_uga'
4
+ require 'pry'
5
+ require 'awesome_print'
data/uga_uga.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "uga_uga"
7
+ spec.version = `cat VERSION`
8
+ spec.authors = ["da99"]
9
+ spec.email = ["i-hate-spam-1234567@mailinator.com"]
10
+ spec.summary = %q{A little tool to help you write DSLs.}
11
+ spec.description = %q{
12
+ It takes in a String and gives you back a
13
+ stupid data structure of commands, blocks, and Strings.
14
+ You then do stuff to make that stuff come alive.
15
+ Whatever... I don't have time to tell you exactly
16
+ since you will use Treetop anyway:
17
+ https://github.com/nathansobo/treetop
18
+ }
19
+ spec.homepage = "https://github.com/da99/uga_uga"
20
+ spec.license = "MIT"
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |file|
23
+ file.index('bin/') == 0 && file != "bin/#{File.basename Dir.pwd}"
24
+ }
25
+ spec.executables = spec.files.grep("bin/#{spec.name}") { |f| File.basename(f) }
26
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.required_ruby_version = '>= 2.2.0'
30
+
31
+ spec.add_development_dependency "pry" , "> 0.9"
32
+ spec.add_development_dependency "bundler" , "> 1.5"
33
+ spec.add_development_dependency "bacon" , "> 1.0"
34
+ spec.add_development_dependency "Bacon_Colored" , "> 0.1"
35
+ spec.add_development_dependency "awesome_print" , "> 0.1"
36
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uga_uga
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - da99
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
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.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bacon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: Bacon_Colored
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: awesome_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
83
+ description: "\n It takes in a String and gives you back a\n stupid data structure
84
+ of commands, blocks, and Strings.\n You then do stuff to make that stuff come
85
+ alive.\n Whatever... I don't have time to tell you exactly\n since you will
86
+ use Treetop anyway:\n https://github.com/nathansobo/treetop\n "
87
+ email:
88
+ - i-hate-spam-1234567@mailinator.com
89
+ executables:
90
+ - uga_uga
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".gitignore"
95
+ - Gemfile
96
+ - LICENSE
97
+ - README.md
98
+ - VERSION
99
+ - bin/uga_uga
100
+ - lib/uga_uga.rb
101
+ - specs/0000-it-runs.rb
102
+ - specs/lib/helpers.rb
103
+ - uga_uga.gemspec
104
+ homepage: https://github.com/da99/uga_uga
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 2.2.0
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.5
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: A little tool to help you write DSLs.
128
+ test_files: []