jejune 1.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 +15 -0
- data/.gemtest +0 -0
- data/History.txt +12 -0
- data/Manifest.txt +39 -0
- data/README.txt +55 -0
- data/Rakefile +75 -0
- data/bin/jjs +173 -0
- data/lib/jejune.rb +78 -0
- data/lib/jejune/boot.rb +107 -0
- data/lib/jejune/constants.rb +105 -0
- data/lib/jejune/data-extension.rb +144 -0
- data/lib/jejune/dependency-scanner.rb +69 -0
- data/lib/jejune/ejjs.rb +178 -0
- data/lib/jejune/errors.rb +53 -0
- data/lib/jejune/grammar.rb +32 -0
- data/lib/jejune/grammar/JavaScript.g +668 -0
- data/lib/jejune/grammar/Jejune.g +1029 -0
- data/lib/jejune/grammar/Jejune.tokens +241 -0
- data/lib/jejune/grammar/lexer.rb +6504 -0
- data/lib/jejune/grammar/parser.rb +17378 -0
- data/lib/jejune/grammar/rakefile +29 -0
- data/lib/jejune/grammar/tree.rb +6737 -0
- data/lib/jejune/input.rb +124 -0
- data/lib/jejune/jstring.rb +163 -0
- data/lib/jejune/lo-fi-lexer.rb +633 -0
- data/lib/jejune/macro.rb +78 -0
- data/lib/jejune/main.rb +289 -0
- data/lib/jejune/manager.rb +333 -0
- data/lib/jejune/node-test.rb +71 -0
- data/lib/jejune/parameters.rb +83 -0
- data/lib/jejune/rewrite-debug.rb +61 -0
- data/lib/jejune/rewrite.rb +125 -0
- data/lib/jejune/scanner.rb +201 -0
- data/lib/jejune/translator.rb +710 -0
- data/lib/jejune/tree-walker.rb +81 -0
- data/lib/jejune/utils.rb +81 -0
- data/lib/jejune/version.rb +38 -0
- data/spec/samples.txt +51 -0
- data/spec/translation.rb +69 -0
- data/spec/utils.rb +63 -0
- data/tools/env.fish +2 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2ZhMTYwNmJhYzYxOTE5ODkzYjM2Mzk3MjQ5M2ViYjMyNjQxYmRiOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTk0M2M1NzI3MWNmMDRlNmEwY2VhZWQ3ZGY5MzRkMmM1MzE1YTYwYQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzNiOWEyMjNlMjdhMDkxNDgzY2IwYmYyOWUzMDM5OGI5YzhkMzY0YjZhNjAx
|
10
|
+
OGFiODk1ZjU4MmIyZDA3ZWZhMzI4OTMwZjk0YzQ0ZDI1ZDRkY2QxY2VlMDc2
|
11
|
+
YjNlMGNiOWQzODE3MWI1MGZkNmY2MjcwOTE4MjNhY2E5ODJiMjI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWQzNThmYWVlNGI0Yzg4MzMzODlkNjFkM2Y0MzFlZDg1Y2ZiY2FiZDc4YzM1
|
14
|
+
NTA0NGRmNmM5NzliNDkxYWVkN2YxOWNmODM1MjViZjBkMmZiOGE4MDY4YTVj
|
15
|
+
MDhhYWNhMDc3ZTAwZjU1M2VhNzkyOGQ4ZDlkMTAyN2IzZDZhM2Y=
|
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
lib/jejune.rb
|
2
|
+
lib/jejune/ejjs.rb
|
3
|
+
lib/jejune/rewrite-debug.rb
|
4
|
+
lib/jejune/errors.rb
|
5
|
+
lib/jejune/node-test.rb
|
6
|
+
lib/jejune/tree-walker.rb
|
7
|
+
lib/jejune/main.rb
|
8
|
+
lib/jejune/jstring.rb
|
9
|
+
lib/jejune/grammar.rb
|
10
|
+
lib/jejune/translator.rb
|
11
|
+
lib/jejune/version.rb
|
12
|
+
lib/jejune/dependency-scanner.rb
|
13
|
+
lib/jejune/grammar/Jejune.g
|
14
|
+
lib/jejune/grammar/rakefile
|
15
|
+
lib/jejune/grammar/tree.rb
|
16
|
+
lib/jejune/grammar/lexer.rb
|
17
|
+
lib/jejune/grammar/Jejune.tokens
|
18
|
+
lib/jejune/grammar/parser.rb
|
19
|
+
lib/jejune/grammar/JavaScript.g
|
20
|
+
lib/jejune/lo-fi-lexer.rb
|
21
|
+
lib/jejune/manager.rb
|
22
|
+
lib/jejune/scanner.rb
|
23
|
+
lib/jejune/utils.rb
|
24
|
+
lib/jejune/input.rb
|
25
|
+
lib/jejune/macro.rb
|
26
|
+
lib/jejune/boot.rb
|
27
|
+
lib/jejune/constants.rb
|
28
|
+
lib/jejune/rewrite.rb
|
29
|
+
lib/jejune/data-extension.rb
|
30
|
+
lib/jejune/parameters.rb
|
31
|
+
History.txt
|
32
|
+
Manifest.txt
|
33
|
+
Rakefile
|
34
|
+
README.txt
|
35
|
+
bin/jjs
|
36
|
+
spec/samples.txt
|
37
|
+
spec/translation.rb
|
38
|
+
spec/utils.rb
|
39
|
+
tools/env.fish
|
data/README.txt
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= jejune
|
2
|
+
|
3
|
+
* http://www.jjscript.com
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Make JavaScript look and feel like Ruby -- fancy JavaScript preprocessor. More info to come later.
|
8
|
+
|
9
|
+
== SYNOPSIS:
|
10
|
+
|
11
|
+
~> jjs -e '[1,2,3].map { | number | number * 2 }'
|
12
|
+
# [1,2,3].map(function(number){ return( number * 2 ); })
|
13
|
+
|
14
|
+
== REQUIREMENTS:
|
15
|
+
|
16
|
+
* ruby 1.8+
|
17
|
+
* antlr3 (antlr4ruby) 1.9
|
18
|
+
|
19
|
+
== INSTALL:
|
20
|
+
|
21
|
+
sudo gem install jejune
|
22
|
+
|
23
|
+
== DEVELOPERS:
|
24
|
+
|
25
|
+
After checking out the source, run:
|
26
|
+
|
27
|
+
$ rake newb
|
28
|
+
|
29
|
+
This task will install any missing dependencies, run the tests/specs,
|
30
|
+
and generate the RDoc.
|
31
|
+
|
32
|
+
== LICENSE:
|
33
|
+
|
34
|
+
(The MIT License)
|
35
|
+
|
36
|
+
Copyright (c) 2010-2013 Kyle Yetter
|
37
|
+
|
38
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
39
|
+
a copy of this software and associated documentation files (the
|
40
|
+
'Software'), to deal in the Software without restriction, including
|
41
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
42
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
43
|
+
permit persons to whom the Software is furnished to do so, subject to
|
44
|
+
the following conditions:
|
45
|
+
|
46
|
+
The above copyright notice and this permission notice shall be
|
47
|
+
included in all copies or substantial portions of the Software.
|
48
|
+
|
49
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
50
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
51
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
52
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
53
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
54
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
55
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
#
|
4
|
+
|
5
|
+
require "rubygems"
|
6
|
+
require "hoe"
|
7
|
+
|
8
|
+
begin
|
9
|
+
require './lib/jejune.rb'
|
10
|
+
rescue
|
11
|
+
warn( $! )
|
12
|
+
end
|
13
|
+
|
14
|
+
GRAMMAR_DIR = "lib/jejune/grammar"
|
15
|
+
RENAME = YAML.load( <<-END )
|
16
|
+
JejuneParser.rb: parser.rb
|
17
|
+
JejuneLexer.rb: lexer.rb
|
18
|
+
END
|
19
|
+
TIDY_SCRIPT = "scripts/pretty-antlr-tokens"
|
20
|
+
|
21
|
+
|
22
|
+
parser_lib = File.join( GRAMMAR_DIR, 'parser.rb' )
|
23
|
+
grammars = %w( Jejune.g ).map { | i | File.join( GRAMMAR_DIR, i ) }
|
24
|
+
|
25
|
+
file( parser_lib => grammars ) do
|
26
|
+
require 'antlr3/task'
|
27
|
+
cd GRAMMAR_DIR do
|
28
|
+
tasks = ANTLR3::CompileTask.define( 'Jejune.g' )
|
29
|
+
tasks.compile!
|
30
|
+
for src, dest in RENAME
|
31
|
+
mv( src, dest )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
desc( "Generate the grammar recognition libraries from the ANTLR grammars" )
|
37
|
+
task( :grammar => parser_lib )
|
38
|
+
|
39
|
+
namespace :grammar do
|
40
|
+
desc "reformat the token listings in the grammar files"
|
41
|
+
task :tidy do
|
42
|
+
for grammar in grammars
|
43
|
+
temp = File.basename( grammar ) + '.tmp'
|
44
|
+
cmd = "ruby #{ TIDY_SCRIPT } #{ grammar } > #{ temp }"
|
45
|
+
cp( grammar, grammar + '.backup' )
|
46
|
+
|
47
|
+
sh( cmd ) do | ok, stat |
|
48
|
+
if ok
|
49
|
+
mv( temp, grammar )
|
50
|
+
else
|
51
|
+
test( ?f, temp ) and rm( temp )
|
52
|
+
fail( "command `#{ cmd }' failed with exit status #{ stat.exitstatus }" )
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Hoe.plugin :compiler
|
60
|
+
# Hoe.plugin :gem_prelude_sucks
|
61
|
+
# Hoe.plugin :inline
|
62
|
+
# Hoe.plugin :minitest
|
63
|
+
# Hoe.plugin :racc
|
64
|
+
# Hoe.plugin :rcov
|
65
|
+
# Hoe.plugin :rubyforge
|
66
|
+
|
67
|
+
Hoe.spec "jejune" do
|
68
|
+
developer( "Kyle Yetter", "kyle@ohboyohboyohboy.org")
|
69
|
+
license "MIT" # this should match the license in the README
|
70
|
+
self.version = Jejune::VERSION
|
71
|
+
|
72
|
+
extra_deps <<
|
73
|
+
%w( antlr3 ~>\ 1.8 ) <<
|
74
|
+
%W( sass ~>\ 3.2 )
|
75
|
+
end
|
data/bin/jjs
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
=begin LICENSE
|
5
|
+
|
6
|
+
[The "BSD licence"]
|
7
|
+
Copyright (c) 2010-2013 Kyle Yetter
|
8
|
+
All rights reserved.
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
|
14
|
+
1. Redistributions of source code must retain the above copyright
|
15
|
+
notice, this list of conditions and the following disclaimer.
|
16
|
+
2. Redistributions in binary form must reproduce the above copyright
|
17
|
+
notice, this list of conditions and the following disclaimer in the
|
18
|
+
documentation and/or other materials provided with the distribution.
|
19
|
+
3. The name of the author may not be used to endorse or promote products
|
20
|
+
derived from this software without specific prior written permission.
|
21
|
+
|
22
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
23
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
24
|
+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
25
|
+
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
26
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
27
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
28
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
29
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
30
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
31
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
|
33
|
+
=end
|
34
|
+
|
35
|
+
$0 = 'jjs'
|
36
|
+
|
37
|
+
begin
|
38
|
+
require 'jejune'
|
39
|
+
rescue LoadError
|
40
|
+
project_top = File.expand_path( "../..", __FILE__ )
|
41
|
+
lib = File.join( project_top, 'lib' )
|
42
|
+
$LOAD_PATH.unshift( lib )
|
43
|
+
require 'jejune'
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
require 'optparse'
|
48
|
+
require 'yaml'
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
input = nil
|
53
|
+
output = $stdout
|
54
|
+
load_path = []
|
55
|
+
|
56
|
+
if ENV.has_key?( "JEJUNE_LIB" )
|
57
|
+
load_path.concat( ENV[ "JEJUNE_LIB" ].split( File::PATH_SEPARATOR ) )
|
58
|
+
end
|
59
|
+
|
60
|
+
case ARGV.first
|
61
|
+
when /^(?:tree|ast)$/i then
|
62
|
+
args = ARGV[ 1 .. -1 ].map { | i | i == '-e' ? '-i' : i }
|
63
|
+
Jejune::Parser.main( args )
|
64
|
+
exit
|
65
|
+
when /^(?:lex(?:er)?|token(?:s|ize)?)$/i then
|
66
|
+
args = ARGV[ 1 .. -1 ].map { | i | i == '-e' ? '-i' : i }
|
67
|
+
Jejune::Lexer.main( args )
|
68
|
+
exit
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
manager = Jejune::Manager.new
|
73
|
+
dependency_scan = false
|
74
|
+
|
75
|
+
|
76
|
+
OptionParser.new do | o |
|
77
|
+
o.on( '--input=TEXT', '-e TEXT', "inline input text" ) do | text |
|
78
|
+
manager.set_root_source( text << "\n", :file => '-e' )
|
79
|
+
end
|
80
|
+
|
81
|
+
o.on( '--output=FILE', '-o FILE', "set the output file", "(STDOUT by default)" ) do | path |
|
82
|
+
output = path
|
83
|
+
end
|
84
|
+
|
85
|
+
o.on( '--require FILE', '-r FILE', "require a file before processing" ) do | file |
|
86
|
+
manager.require!( file ).to_s
|
87
|
+
end
|
88
|
+
|
89
|
+
o.on( '--tree', "parse the input and display the resulting parse tree" ) do
|
90
|
+
Jejune::Parser.main( ARGV )
|
91
|
+
exit
|
92
|
+
end
|
93
|
+
|
94
|
+
o.on( '-I DIR', "add DIR to the load path" ) do | dir |
|
95
|
+
manager.add_to_path( dir )
|
96
|
+
end
|
97
|
+
|
98
|
+
o.on( '--depends', "scan and output file dependencies without translating" ) do
|
99
|
+
dependency_scan = true
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
o.on( '--tokens', "tokenize the input and display each token" ) do
|
104
|
+
Jejune::Lexer.main( ARGV )
|
105
|
+
exit
|
106
|
+
end
|
107
|
+
#
|
108
|
+
o.on( '--version', '-v', "print the current version of this program" ) do
|
109
|
+
puts( Jejune.version )
|
110
|
+
exit( 0 )
|
111
|
+
end
|
112
|
+
|
113
|
+
o.on( '--verbose', '-V', "additional information printed during compilation" ) do
|
114
|
+
manager.verbose = true
|
115
|
+
end
|
116
|
+
|
117
|
+
Jejune::Constants::BROWSERS.each do | name |
|
118
|
+
o.on( "--#{ name }", "specify the target browser as #{ name }" ) do
|
119
|
+
manager.browser = name
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
end.parse!( ARGV )
|
124
|
+
|
125
|
+
if dependency_scan
|
126
|
+
require 'jejune/dependency-scanner'
|
127
|
+
scanner = Jejune::DependencyScanner.new( manager )
|
128
|
+
for source_file in ARGV
|
129
|
+
scanner.scan source_file
|
130
|
+
end
|
131
|
+
|
132
|
+
puts YAML.dump( scanner.dependencies )
|
133
|
+
|
134
|
+
exit 0
|
135
|
+
end
|
136
|
+
|
137
|
+
manager.root_input or manager.set_root_file( ARGF )
|
138
|
+
|
139
|
+
begin
|
140
|
+
result = manager.translate
|
141
|
+
|
142
|
+
#if file = manager.root_input and file.source_name and test( ?f, file.source_name )
|
143
|
+
# manager.commit_dependencies( file.source_name, file.dependencies )
|
144
|
+
#end
|
145
|
+
#
|
146
|
+
#open( '.depends', 'w' ) do | f |
|
147
|
+
# f.write( YAML.dump( manager.dependency_map ) )
|
148
|
+
#end
|
149
|
+
#rescue => error
|
150
|
+
# if jtrace = error.jejune_trace and not jtrace.empty?
|
151
|
+
# puts( "[ #{ error.class } ] #{ error }" )
|
152
|
+
#
|
153
|
+
# puts( "RUBY BACKTRACE:" )
|
154
|
+
# for trace in error.backtrace
|
155
|
+
# puts( " - #{ trace }" )
|
156
|
+
# end
|
157
|
+
#
|
158
|
+
# puts( "JEJUNE SOURCE TRACE:" )
|
159
|
+
# for trace in jtrace
|
160
|
+
# puts( " - #{ trace }" )
|
161
|
+
# end
|
162
|
+
# end
|
163
|
+
# exit( 1 )
|
164
|
+
end
|
165
|
+
|
166
|
+
case output
|
167
|
+
when String
|
168
|
+
open( output, 'w' ) { | f | f.write( result ) }
|
169
|
+
when IO
|
170
|
+
output.write( result )
|
171
|
+
else
|
172
|
+
raise( "BUG: output = %p -- should be an IO or String" % output )
|
173
|
+
end
|
data/lib/jejune.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'yaml'
|
5
|
+
require 'json'
|
6
|
+
require 'delegate'
|
7
|
+
require 'shellwords'
|
8
|
+
require 'open3'
|
9
|
+
|
10
|
+
module Jejune
|
11
|
+
begin
|
12
|
+
require 'digest/md5'
|
13
|
+
MD5 = Digest::MD5
|
14
|
+
rescue LoadError
|
15
|
+
require 'md5'
|
16
|
+
MD5 = ::MD5
|
17
|
+
end
|
18
|
+
|
19
|
+
autoload :EJJS, 'jejune/ejjs'
|
20
|
+
|
21
|
+
#
|
22
|
+
# Returns the version string for the library.
|
23
|
+
#
|
24
|
+
def self.version
|
25
|
+
VERSION
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Returns the library path for the module. If any arguments are given,
|
30
|
+
# they will be joined to the end of the libray path using
|
31
|
+
# <tt>File.join</tt>.
|
32
|
+
#
|
33
|
+
def self.library_path( *args )
|
34
|
+
directory = File.dirname( __FILE__ )
|
35
|
+
File.expand_path( ::File.join( directory, *args ) )
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Returns the lpath for the module. If any arguments are given,
|
40
|
+
# they will be joined to the end of the path using
|
41
|
+
# <tt>File.join</tt>.
|
42
|
+
#
|
43
|
+
def self.project_path( *args )
|
44
|
+
library_path( '..', *args )
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.translate( *args )
|
48
|
+
JJSSource.new( *args ).translate
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.translate_file( *args )
|
52
|
+
JJSFile.new( *args ).translate
|
53
|
+
end
|
54
|
+
|
55
|
+
end # module Jejune
|
56
|
+
|
57
|
+
$LOAD_PATH.include?( Jejune.library_path ) or
|
58
|
+
$LOAD_PATH.unshift( Jejune.library_path )
|
59
|
+
|
60
|
+
|
61
|
+
require 'jejune/version'
|
62
|
+
require 'jejune/grammar'
|
63
|
+
require 'jejune/constants'
|
64
|
+
require 'jejune/errors'
|
65
|
+
require 'jejune/utils'
|
66
|
+
require 'jejune/scanner'
|
67
|
+
require 'jejune/rewrite'
|
68
|
+
require 'jejune/jstring'
|
69
|
+
require 'jejune/data-extension'
|
70
|
+
require 'jejune/manager'
|
71
|
+
require 'jejune/input'
|
72
|
+
require 'jejune/node-test'
|
73
|
+
require 'jejune/tree-walker'
|
74
|
+
require 'jejune/parameters'
|
75
|
+
require 'jejune/macro'
|
76
|
+
require 'jejune/translator'
|
77
|
+
require 'jejune/boot'
|
78
|
+
require 'jejune/dependency-scanner'
|