redcar-mirah 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +7 -0
- data/features/fixtures/test.mirah +2 -0
- data/features/syntax_check_mirah.feature +46 -0
- data/lib/mirah.rb +43 -0
- data/lib/mirah/my_error_handler.rb +22 -0
- data/lib/mirah/repl_mirror.rb +50 -0
- data/lib/mirah/syntax_checker.rb +38 -0
- data/plugin.rb +8 -0
- data/spec/mirah/repl_mirror_spec.rb +188 -0
- data/spec/spec_helper.rb +5 -0
- data/vendor/mirah-parser.jar +0 -0
- metadata +60 -0
data/README
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
Feature: Syntax Checking for Mirah
|
2
|
+
As a user
|
3
|
+
I want to get annotations on syntax errors and warnings in Mirah files
|
4
|
+
|
5
|
+
Background:
|
6
|
+
When I have opened "plugins/mirah/features/fixtures/test.mirah"
|
7
|
+
|
8
|
+
Scenario: A syntax-clean Mirah file has no syntax error annotations
|
9
|
+
When I replace the contents with "def foo\n bar\nend"
|
10
|
+
And I save the tab
|
11
|
+
And I wait 2 seconds
|
12
|
+
Then the tab should not have annotations
|
13
|
+
|
14
|
+
Scenario: A syntax-error in a Mirah file should cause syntax error annotations
|
15
|
+
When I replace the contents with "def foo\n => bar\nend"
|
16
|
+
And I save the tab
|
17
|
+
And I wait 2 seconds
|
18
|
+
Then the tab should have annotations
|
19
|
+
And the tab should have an annotation on line 2
|
20
|
+
|
21
|
+
Scenario: A syntax-warning in a Mirah file should cause syntax warning annotations
|
22
|
+
When I replace the contents with "def foo\n end"
|
23
|
+
And I save the tab
|
24
|
+
And I wait 2 seconds
|
25
|
+
Then the tab should have annotations
|
26
|
+
And the tab should have an annotation on line 2
|
27
|
+
|
28
|
+
Scenario: Fixing a syntax-error in a Mirah file should cause syntax error annotations to vanish
|
29
|
+
When I replace the contents with "def foo\n => bar\nend"
|
30
|
+
And I save the tab
|
31
|
+
And I wait 2 seconds
|
32
|
+
Then the tab should have annotations
|
33
|
+
When I replace the contents with "def foo\n bar\nend"
|
34
|
+
And I save the tab
|
35
|
+
And I wait 2 seconds
|
36
|
+
Then the tab should not have annotations
|
37
|
+
|
38
|
+
Scenario: Fixing a syntax-warning in a Mirah file should cause syntax error annotations to vanish
|
39
|
+
When I replace the contents with "def foo\n end"
|
40
|
+
And I save the tab
|
41
|
+
And I wait 2 seconds
|
42
|
+
Then the tab should have annotations
|
43
|
+
When I replace the contents with "def foo\nend"
|
44
|
+
And I save the tab
|
45
|
+
And I wait 2 seconds
|
46
|
+
Then the tab should not have annotations
|
data/lib/mirah.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
require 'java'
|
3
|
+
require 'mirah/syntax_checker'
|
4
|
+
require 'mirah/repl_mirror'
|
5
|
+
|
6
|
+
module Redcar
|
7
|
+
class Mirah
|
8
|
+
|
9
|
+
def self.menus
|
10
|
+
Menu::Builder.build do
|
11
|
+
sub_menu "Plugins" do
|
12
|
+
sub_menu "REPL" do
|
13
|
+
item "Open Mirah REPL", OpenMirahREPL
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.load_dependencies
|
20
|
+
unless @loaded
|
21
|
+
require File.join(File.dirname(__FILE__),'..','vendor','mirah-parser')
|
22
|
+
import 'mirah.impl.MirahParser'
|
23
|
+
import 'jmeta.ErrorHandler'
|
24
|
+
require 'mirah/my_error_handler'
|
25
|
+
@loaded = true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.storage
|
30
|
+
@storage ||= begin
|
31
|
+
storage = Plugin::Storage.new('mirah')
|
32
|
+
storage.set_default('check_for_warnings', true)
|
33
|
+
storage
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class OpenMirahREPL < Redcar::REPL::OpenREPL
|
38
|
+
def execute
|
39
|
+
open_repl(ReplMirror.new)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class Mirah
|
4
|
+
class MyErrorHandler
|
5
|
+
include ErrorHandler
|
6
|
+
|
7
|
+
def problem(m)
|
8
|
+
(@problems||=[]) << m
|
9
|
+
end
|
10
|
+
|
11
|
+
def problems
|
12
|
+
@problems || []
|
13
|
+
end
|
14
|
+
|
15
|
+
def warning(messages, positions)
|
16
|
+
messages.length.times { |i|
|
17
|
+
problem "Warning: #{messages[i]} #{positions[i]}"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class Mirah
|
4
|
+
class ReplMirror < Redcar::REPL::ReplMirror
|
5
|
+
|
6
|
+
def title
|
7
|
+
"Mirah REPL"
|
8
|
+
end
|
9
|
+
|
10
|
+
def grammar_name
|
11
|
+
"Ruby REPL"
|
12
|
+
end
|
13
|
+
|
14
|
+
def prompt
|
15
|
+
">>"
|
16
|
+
end
|
17
|
+
|
18
|
+
def format_error(e)
|
19
|
+
backtrace = e.backtrace.reject{|l|
|
20
|
+
l =~ /(repl_mirror|redcar)/
|
21
|
+
}
|
22
|
+
backtrace.unshift("(repl):1")
|
23
|
+
"#{e.class}: #{e.message}\n #{backtrace.join("\n ")}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def evaluator
|
27
|
+
@evaluator ||= ReplMirror::Evaluator.new
|
28
|
+
end
|
29
|
+
|
30
|
+
class Evaluator
|
31
|
+
attr_reader :output
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
Mirah.load_dependencies
|
35
|
+
@binding = binding
|
36
|
+
@impl = Java::MirahImpl::Mirah.new
|
37
|
+
@output = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def inspect
|
41
|
+
"main"
|
42
|
+
end
|
43
|
+
|
44
|
+
def execute(command)
|
45
|
+
@impl.instance_eval(command).inspect
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class Mirah
|
4
|
+
class SyntaxChecker < Redcar::SyntaxCheck::Checker
|
5
|
+
supported_grammars "Mirah"
|
6
|
+
|
7
|
+
def check(*args)
|
8
|
+
Mirah.load_dependencies
|
9
|
+
check_warnings = Mirah.storage['check_for_warnings']
|
10
|
+
path = manifest_path(doc)
|
11
|
+
|
12
|
+
parser = MirahParser.new
|
13
|
+
parser.filename = path
|
14
|
+
|
15
|
+
handler = MyErrorHandler.new
|
16
|
+
parser.errorHandler = handler
|
17
|
+
|
18
|
+
begin
|
19
|
+
parser.parse(IO.read(path))
|
20
|
+
rescue
|
21
|
+
m = $!.message
|
22
|
+
error = m.split(" (").first
|
23
|
+
if info = m.match(/line: ([0-9]+), char: ([0-9]+)\)/)
|
24
|
+
SyntaxCheck::Error.new(doc, info[1].to_i-1, error).annotate
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
if check_warnings
|
29
|
+
handler.problems.each do |problem|
|
30
|
+
if info = problem.match(/line: ([0-9]+), char: ([0-9]+)\)/)
|
31
|
+
SyntaxCheck::Warning.new(doc, info[1].to_i-1, problem.split(" (").first).annotate
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/plugin.rb
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
class Redcar::Mirah
|
4
|
+
describe ReplMirror do
|
5
|
+
before do
|
6
|
+
@mirror = ReplMirror.new
|
7
|
+
@changed_event = false
|
8
|
+
@mirror.add_listener(:change) { @changed_event = true }
|
9
|
+
end
|
10
|
+
|
11
|
+
def commit_test_text1
|
12
|
+
text = <<-MIRAH
|
13
|
+
# Mirah REPL
|
14
|
+
# type 'help' for help
|
15
|
+
|
16
|
+
>> $internal_repl_test = 707
|
17
|
+
MIRAH
|
18
|
+
@mirror.commit(text.chomp)
|
19
|
+
end
|
20
|
+
|
21
|
+
def result_test_text1
|
22
|
+
(<<-MIRAH).chomp
|
23
|
+
# Mirah REPL
|
24
|
+
# type 'help' for help
|
25
|
+
|
26
|
+
>> $internal_repl_test = 707
|
27
|
+
=> 707
|
28
|
+
>>
|
29
|
+
MIRAH
|
30
|
+
end
|
31
|
+
|
32
|
+
def commit_test_text2
|
33
|
+
text = <<-MIRAH
|
34
|
+
# Mirah REPL
|
35
|
+
# type 'help' for help
|
36
|
+
|
37
|
+
>> $internal_repl_test = 707
|
38
|
+
=> 707
|
39
|
+
>> $internal_repl_test = 909
|
40
|
+
MIRAH
|
41
|
+
@mirror.commit(text.chomp)
|
42
|
+
text.chomp
|
43
|
+
end
|
44
|
+
|
45
|
+
def result_test_text2
|
46
|
+
(<<-MIRAH).chomp
|
47
|
+
# Mirah REPL
|
48
|
+
# type 'help' for help
|
49
|
+
|
50
|
+
>> $internal_repl_test = 707
|
51
|
+
=> 707
|
52
|
+
>> $internal_repl_test = 909
|
53
|
+
=> 909
|
54
|
+
>>
|
55
|
+
MIRAH
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def commit_no_input
|
60
|
+
text = <<-MIRAH
|
61
|
+
# Mirah REPL
|
62
|
+
# type 'help' for help
|
63
|
+
|
64
|
+
>>
|
65
|
+
MIRAH
|
66
|
+
@mirror.commit(text)
|
67
|
+
end
|
68
|
+
|
69
|
+
def prompt
|
70
|
+
"# Mirah REPL\n\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "with no history" do
|
74
|
+
it "should exist" do
|
75
|
+
@mirror.should be_exist
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should have a message and a prompt" do
|
79
|
+
@mirror.read.should == (<<-MIRAH).chomp
|
80
|
+
# Mirah REPL
|
81
|
+
# type 'help' for help
|
82
|
+
|
83
|
+
>>
|
84
|
+
MIRAH
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should have a title" do
|
88
|
+
@mirror.title.should == "Mirah REPL"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should not be changed" do
|
92
|
+
@mirror.should_not be_changed
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "when executing" do
|
96
|
+
it "should execute committed text" do
|
97
|
+
commit_test_text1
|
98
|
+
$internal_repl_test.should == 707
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should allow committing nothing as the first command" do
|
102
|
+
commit_no_input
|
103
|
+
@mirror.read.should == "# Mirah REPL\n# type 'help' for help\n\n>> \n=> nil\n>> "
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should allow committing nothing as an xth command" do
|
107
|
+
committed = commit_test_text2
|
108
|
+
@mirror.commit committed + "\n>> "
|
109
|
+
@mirror.read.should == "# Mirah REPL\n# type 'help' for help\n\n>> $internal_repl_test = 909\n=> 909\n>> \n=> nil\n>> "
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should emit changed event when text is executed" do
|
113
|
+
commit_test_text1
|
114
|
+
@changed_event.should be_true
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should now have the command and the result at the end" do
|
118
|
+
commit_test_text1
|
119
|
+
@mirror.read.should == result_test_text1
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should display errors" do
|
123
|
+
@mirror.commit(prompt + ">> nil.foo")
|
124
|
+
text = <<-MIRAH
|
125
|
+
# Mirah REPL
|
126
|
+
# type 'help' for help
|
127
|
+
|
128
|
+
>> nil.foo
|
129
|
+
x> NoMethodError: undefined method `foo' for nil:NilClass
|
130
|
+
(repl):1
|
131
|
+
MIRAH
|
132
|
+
@mirror.read.include?(text).should be_true
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "with a history" do
|
138
|
+
before do
|
139
|
+
commit_test_text1
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should not have changed" do
|
143
|
+
@mirror.changed?.should be_false
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should display the history and prompt correctly" do
|
147
|
+
@mirror.read.should == result_test_text1
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "when executing" do
|
151
|
+
it "should execute committed text" do
|
152
|
+
commit_test_text2
|
153
|
+
$internal_repl_test.should == 909
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should show the correct history" do
|
157
|
+
commit_test_text2
|
158
|
+
@mirror.read.should == result_test_text2
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should allow the history to be cleared" do
|
162
|
+
@mirror.clear_history
|
163
|
+
@mirror.read.should == ">> "
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# somehow ...
|
170
|
+
# describe "when executing" do
|
171
|
+
# it "should persist local variables" do
|
172
|
+
# sent = prompt + ">> a = 13"
|
173
|
+
# @mirror.commit(sent)
|
174
|
+
# @mirror.commit(sent + "\n>> a")
|
175
|
+
# @mirror.read.should == (<<-MIRAH).chomp
|
176
|
+
# # Mirah REPL
|
177
|
+
# # type 'help' for help
|
178
|
+
#
|
179
|
+
# >> a = 13
|
180
|
+
# => 13
|
181
|
+
# >> a
|
182
|
+
# => 13
|
183
|
+
# >>
|
184
|
+
# MIRAH
|
185
|
+
# end
|
186
|
+
# end
|
187
|
+
end
|
188
|
+
end
|
data/spec/spec_helper.rb
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redcar-mirah
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michal Hantl
|
9
|
+
- Daniel Lucraft
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-09-10 00:00:00.000000000 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
description: ''
|
17
|
+
email:
|
18
|
+
- michal.hantl@gmail.com
|
19
|
+
- dan@fluentradical.com
|
20
|
+
executables: []
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- lib/mirah/my_error_handler.rb
|
25
|
+
- lib/mirah/repl_mirror.rb
|
26
|
+
- lib/mirah/syntax_checker.rb
|
27
|
+
- lib/mirah.rb
|
28
|
+
- features/fixtures/test.mirah
|
29
|
+
- features/syntax_check_mirah.feature
|
30
|
+
- spec/mirah/repl_mirror_spec.rb
|
31
|
+
- spec/spec_helper.rb
|
32
|
+
- vendor/mirah-parser.jar
|
33
|
+
- plugin.rb
|
34
|
+
- README
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/redcar/redcar-mirah
|
37
|
+
licenses: []
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.6.2
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Redcar extensions for Mirah development
|
60
|
+
test_files: []
|