riml 0.1.8 → 0.1.9
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.
- data/CONTRIBUTING +0 -2
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/bin/riml +7 -9
- data/lib/ast_rewriter.rb +0 -4
- data/lib/class_map.rb +8 -3
- data/lib/compiler.rb +34 -11
- data/lib/constants.rb +6 -1
- data/lib/errors.rb +1 -0
- data/lib/grammar.y +2 -2
- data/lib/included.vim +2 -0
- data/lib/lexer.rb +6 -2
- data/lib/parser.rb +531 -532
- data/lib/repl.rb +50 -12
- data/lib/riml.rb +7 -5
- data/version.rb +2 -2
- metadata +20 -14
data/lib/repl.rb
CHANGED
@@ -1,24 +1,41 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'readline'
|
3
|
+
rescue LoadError => e
|
4
|
+
$stderr.puts e, "Readline is required to run repl."
|
5
|
+
exit 1
|
6
|
+
end
|
2
7
|
require_relative 'riml'
|
3
8
|
|
4
9
|
module Riml
|
5
10
|
class Repl
|
6
11
|
attr_reader :line
|
12
|
+
attr_reader :parser, :compiler
|
13
|
+
private :parser, :compiler
|
14
|
+
|
15
|
+
EXIT_ON = %w(quit exit q e)
|
16
|
+
COMPILE_ON = %w(compile c)
|
17
|
+
RELOAD_ON = %w(reload reload!)
|
7
18
|
|
8
19
|
def initialize(vi_readline = false)
|
9
20
|
@indent_amount = 0
|
10
21
|
@line = nil
|
22
|
+
prepare_new_context
|
11
23
|
Readline.vi_editing_mode if vi_readline
|
24
|
+
trap(:INT) { reset!; puts }
|
12
25
|
end
|
13
26
|
|
14
27
|
def run
|
15
28
|
while @line = Readline.readline(current_indent, true)
|
16
29
|
line.strip!
|
17
30
|
next if line.empty?
|
18
|
-
|
19
|
-
if
|
31
|
+
line_dc = line.downcase
|
32
|
+
exit_repl if EXIT_ON.include?(line_dc)
|
33
|
+
if COMPILE_ON.include?(line_dc)
|
20
34
|
next if current_compilation_unit.empty?
|
21
35
|
compile_unit!
|
36
|
+
elsif RELOAD_ON.include?(line_dc)
|
37
|
+
reload!
|
38
|
+
puts "reloaded"
|
22
39
|
else
|
23
40
|
current_compilation_unit << line
|
24
41
|
check_indents
|
@@ -28,28 +45,49 @@ module Riml
|
|
28
45
|
|
29
46
|
private
|
30
47
|
|
48
|
+
def prepare_new_context
|
49
|
+
@compiler = Compiler.new
|
50
|
+
@parser = Parser.new
|
51
|
+
end
|
52
|
+
alias reload! prepare_new_context
|
53
|
+
|
31
54
|
def check_indents
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
55
|
+
lexer = Lexer.new(line)
|
56
|
+
lexer.ignore_indentation_check = true
|
57
|
+
lexer.tokenize
|
58
|
+
@indent_amount += lexer.current_indent
|
59
|
+
rescue => e
|
60
|
+
print_error(e)
|
61
|
+
reset!
|
37
62
|
end
|
38
63
|
|
39
64
|
def current_indent
|
40
|
-
|
65
|
+
return '' if @indent_amount <= 0
|
66
|
+
' ' * @indent_amount
|
41
67
|
end
|
42
68
|
|
43
69
|
def compile_unit!
|
44
|
-
|
45
|
-
|
46
|
-
|
70
|
+
puts Riml.compile(current_compilation_unit.join("\n"), parser, compiler), "\n"
|
71
|
+
rescue => e
|
72
|
+
raise unless e.kind_of?(RimlError)
|
73
|
+
print_error(e)
|
74
|
+
ensure
|
75
|
+
reset!
|
47
76
|
end
|
48
77
|
|
49
78
|
def current_compilation_unit
|
50
79
|
@current_compilation_unit ||= []
|
51
80
|
end
|
52
81
|
|
82
|
+
def reset!
|
83
|
+
@indent_amount = 0
|
84
|
+
current_compilation_unit.clear
|
85
|
+
end
|
86
|
+
|
87
|
+
def print_error(e)
|
88
|
+
puts "#{e.class}: #{e}"
|
89
|
+
end
|
90
|
+
|
53
91
|
def exit_repl
|
54
92
|
exit
|
55
93
|
end
|
data/lib/riml.rb
CHANGED
@@ -28,14 +28,15 @@ module Riml
|
|
28
28
|
source = input.read
|
29
29
|
nodes = parser.parse(source)
|
30
30
|
else
|
31
|
-
raise ArgumentError, "input must be nodes, tokens or
|
31
|
+
raise ArgumentError, "input must be nodes, tokens, code or file, is #{input.class}"
|
32
32
|
end
|
33
|
+
compiler.parser = parser
|
33
34
|
output = compiler.compile(nodes)
|
34
35
|
return output unless input.is_a?(File)
|
35
36
|
write_file(output, input.path)
|
36
37
|
ensure
|
37
38
|
input.close if input.is_a?(File)
|
38
|
-
process_compile_queue!(
|
39
|
+
process_compile_queue!(compiler)
|
39
40
|
end
|
40
41
|
|
41
42
|
# expects `file_names` to be readable files
|
@@ -79,15 +80,16 @@ module Riml
|
|
79
80
|
# and we process this queue after each source we compile. We pass the same
|
80
81
|
# parser instance to share Class state, as this state belongs to the
|
81
82
|
# AST_Rewriter's `ClassMap`.
|
82
|
-
def self.process_compile_queue!(
|
83
|
+
def self.process_compile_queue!(compiler)
|
83
84
|
return true if compiler.compile_queue.empty?
|
84
85
|
|
85
86
|
file_name = compiler.compile_queue.shift
|
86
|
-
compile(File.open(File.join(Riml.source_path, file_name)), parser)
|
87
|
-
process_compile_queue!(
|
87
|
+
compile(File.open(File.join(Riml.source_path, file_name)), compiler.parser)
|
88
|
+
process_compile_queue!(compiler)
|
88
89
|
end
|
89
90
|
|
90
91
|
FILE_HEADER = File.read(File.expand_path("../header.vim", __FILE__)) % VERSION.join('.')
|
92
|
+
INCLUDE_COMMENT_FMT = File.read(File.expand_path("../included.vim", __FILE__))
|
91
93
|
|
92
94
|
def self.write_file(output, fname)
|
93
95
|
file_basename = File.basename(fname)
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: racc
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
description: ! " Riml is a superset of VimL that includes some nice features:\n classes,
|
26
31
|
string interpolation, heredocs, default case-sensitive string\n comparison and
|
27
32
|
other things most programmers take for granted.\n"
|
@@ -35,19 +40,20 @@ files:
|
|
35
40
|
- LICENSE
|
36
41
|
- version.rb
|
37
42
|
- lib/parser.rb
|
38
|
-
- lib/class_map.rb
|
39
|
-
- lib/errors.rb
|
40
|
-
- lib/repl.rb
|
41
43
|
- lib/walker.rb
|
44
|
+
- lib/class_map.rb
|
45
|
+
- lib/included.vim
|
46
|
+
- lib/constants.rb
|
47
|
+
- lib/lexer.rb
|
48
|
+
- lib/grammar.y
|
49
|
+
- lib/compiler.rb
|
50
|
+
- lib/environment.rb
|
42
51
|
- lib/header.vim
|
43
|
-
- lib/
|
52
|
+
- lib/repl.rb
|
44
53
|
- lib/riml.rb
|
45
|
-
- lib/compiler.rb
|
46
54
|
- lib/nodes.rb
|
47
|
-
- lib/
|
48
|
-
- lib/
|
49
|
-
- lib/lexer.rb
|
50
|
-
- lib/constants.rb
|
55
|
+
- lib/errors.rb
|
56
|
+
- lib/ast_rewriter.rb
|
51
57
|
- Rakefile
|
52
58
|
- CONTRIBUTING
|
53
59
|
- Gemfile
|
@@ -74,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
80
|
version: '0'
|
75
81
|
requirements: []
|
76
82
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.8.
|
83
|
+
rubygems_version: 1.8.25
|
78
84
|
signing_key:
|
79
85
|
specification_version: 3
|
80
86
|
summary: Relaxed VimL (Vimscript)
|