bitclust-core 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e32c5dfdf60ae79984fb44940fa5125727de9823b97d57f4476ff17381f71fe
4
- data.tar.gz: c6e37cad779f2876ae2ad907b7e0d04ad21a2cfd622c68089edcb2995788a723
3
+ metadata.gz: b69f11fbdf0bc331f213ef6d9d854c39d96920492d182277101106d1ed0de062
4
+ data.tar.gz: 53858c49735d3b7207292a5d704c015209226f4a39a7763ccd031919e34225c9
5
5
  SHA512:
6
- metadata.gz: 5fdb5e20b6d1469f314e2abb08e5082169a340e49679f22e5d89195d595b66791e2e2adad946946c56c487fa7491aaacc4b75eeae5394621858011e9f46eaded
7
- data.tar.gz: 86042f89cc75d2cca54cef4c6622bcadd05987bb9a3ff0ef7bd2a7a7ec3f3320f41b40ca2c10c9c7e2984684c8afcf1eaa5ef29dff19c1a120077bf84556bd45
6
+ metadata.gz: 04b3303a69a3ee1610ed17c5124f81280cf68355973b1726f3a474e8a22c096329ed82dc687237e3d6c6b19a13e0d6ddcda33f457cb81d7e4ebb22929ba76c1b
7
+ data.tar.gz: 42c05365d2c6985e3fe147942c70672463a77e31e46cbc407c3044c3a73e72a36cbcfa0f68ba5bce5a89d516ad1edd4865e79f009cae1113f583450f1f79d99c
@@ -14,8 +14,14 @@
14
14
  <% headline_init %>
15
15
  <%= headline("#{entry.type_label} #{entry.label}") %>
16
16
  <dl class="methodlist">
17
- <% @entries.sort.each do |ent| %>
17
+ <%
18
+ headline_push
19
+ @entries.sort.each do |ent|
20
+ %>
18
21
  <%= compile_method(ent) %>
19
- <% end %>
22
+ <%
23
+ end
24
+ headline_pop
25
+ %>
20
26
  </dl>
21
27
 
@@ -15,7 +15,13 @@
15
15
  <% headline_init %>
16
16
  <%= headline("#{entry.type_label} #{entry.label}") %>
17
17
  <dl class="methodlist">
18
- <% @entries.sort.each do |ent| %>
18
+ <%
19
+ headline_push
20
+ @entries.sort.each do |ent|
21
+ %>
19
22
  <%= compile_method(ent) %>
20
- <% end %>
23
+ <%
24
+ end
25
+ headline_pop
26
+ %>
21
27
  </dl>
@@ -15,8 +15,14 @@
15
15
  <% headline_init %>
16
16
  <%= headline("#{entry.type_label} #{entry.label}") %>
17
17
  <dl class="methodlist">
18
- <% @entries.sort.each do |ent| %>
18
+ <%
19
+ headline_push
20
+ @entries.sort.each do |ent|
21
+ %>
19
22
  <%= compile_method(ent) %>
20
- <% end %>
23
+ <%
24
+ end
25
+ headline_pop
26
+ %>
21
27
  </dl>
22
28
 
@@ -17,8 +17,9 @@ class LineInput
17
17
  new(StringIO.new(s))
18
18
  end
19
19
 
20
- def initialize(f)
20
+ def initialize(f, entry = nil)
21
21
  @input = f
22
+ @entry = entry
22
23
  @buf = []
23
24
  @lineno = 0
24
25
  @eof_p = false
@@ -36,6 +37,14 @@ class LineInput
36
37
  @input.path
37
38
  end
38
39
 
40
+ def name
41
+ if @entry
42
+ @entry.inspect
43
+ else
44
+ "-"
45
+ end
46
+ end
47
+
39
48
  def lineno
40
49
  @lineno
41
50
  end
@@ -45,7 +45,7 @@ module BitClust
45
45
  def compile_function(f, opt = nil)
46
46
  @opt = opt
47
47
  @type = :function
48
- setup(f.source) {
48
+ setup(f.source, f) {
49
49
  entry
50
50
  }
51
51
  ensure
@@ -57,7 +57,7 @@ module BitClust
57
57
  @opt = opt
58
58
  @type = :method
59
59
  @method = m
60
- setup(m.source) {
60
+ setup(m.source, m) {
61
61
  entry
62
62
  }
63
63
  ensure
@@ -66,8 +66,8 @@ module BitClust
66
66
 
67
67
  private
68
68
 
69
- def setup(src)
70
- @f = LineInput.new(StringIO.new(src))
69
+ def setup(src, entry = nil)
70
+ @f = LineInput.new(StringIO.new(src), entry)
71
71
  @out = StringIO.new
72
72
  yield
73
73
  @out.string
@@ -275,7 +275,13 @@ module BitClust
275
275
  src << line
276
276
  end
277
277
  if lang == "ruby"
278
- string BitClust::SyntaxHighlighter.new(src).highlight
278
+ begin
279
+ filename = (caption&.size || 0) > 2 ? caption : @f.name
280
+ string BitClust::SyntaxHighlighter.new(src, filename).highlight
281
+ rescue BitClust::SyntaxHighlighter::Error => ex
282
+ $stderr.puts ex.message
283
+ exit(false)
284
+ end
279
285
  else
280
286
  string src
281
287
  end
@@ -5,6 +5,25 @@ module BitClust
5
5
  class SyntaxHighlighter < Ripper::Filter
6
6
  include BitClust::HTMLUtils
7
7
 
8
+ class Error < StandardError
9
+ def initialize(name, lineno, column, error_message)
10
+ @name = name
11
+ @lineno = lineno
12
+ @column = column
13
+ @error_message = error_message
14
+ end
15
+
16
+ def message
17
+ "#{@name}:#{@lineno}:#{@column} #{@error_message} (#{self.class})"
18
+ end
19
+ end
20
+
21
+ class ParseError < Error
22
+ end
23
+
24
+ class CompileError < Error
25
+ end
26
+
8
27
  COLORS = {
9
28
  CHAR: "sc", # ?a
10
29
  __end__: "k", # __END__
@@ -97,10 +116,16 @@ module BitClust
97
116
 
98
117
  BUILTINS_B = %w[chomp chop exit gsub sub]
99
118
 
100
- def initialize(*args)
119
+ def initialize(src, filename = "-", lineno = 1)
101
120
  super
102
121
  @stack = []
103
122
  @name_buffer = []
123
+ @__lexer.define_singleton_method(:on_parse_error) do |message|
124
+ raise ParseError.new(filename, self.lineno, self.column, message)
125
+ end
126
+ @__lexer.define_singleton_method(:compile_error) do |message|
127
+ raise CompileError.new(filename, self.lineno, self.column, message)
128
+ end
104
129
  end
105
130
 
106
131
  def on_default(event, token, data)
@@ -1,3 +1,3 @@
1
1
  module BitClust
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'bitclust/syntax_highlighter'
2
+
3
+ class TestSyntaxHighlighter < Test::Unit::TestCase
4
+ def highlight(src, filename = "-")
5
+ BitClust::SyntaxHighlighter.new(src, filename).highlight
6
+ end
7
+
8
+ sub_test_case "syntax error" do
9
+ test "single line" do
10
+ src = "...\n"
11
+ assert_raise(BitClust::SyntaxHighlighter::ParseError.new("-", 1, 3, "syntax error, unexpected ...")) do
12
+ highlight(src)
13
+ end
14
+ end
15
+
16
+ test "multiple line" do
17
+ src = "a = 1\n...\n"
18
+ assert_raise(BitClust::SyntaxHighlighter::ParseError.new("-", 2, 3, "syntax error, unexpected ..., expecting end-of-input")) do
19
+ highlight(src)
20
+ end
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitclust-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/rurema
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-13 00:00:00.000000000 Z
11
+ date: 2018-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
@@ -191,7 +191,6 @@ files:
191
191
  - lib/bitclust/subcommands/preproc_command.rb
192
192
  - lib/bitclust/subcommands/property_command.rb
193
193
  - lib/bitclust/subcommands/query_command.rb
194
- - lib/bitclust/subcommands/review_command.rb
195
194
  - lib/bitclust/subcommands/server_command.rb
196
195
  - lib/bitclust/subcommands/setup_command.rb
197
196
  - lib/bitclust/subcommands/statichtml_command.rb
@@ -214,6 +213,7 @@ files:
214
213
  - test/test_rrdparser.rb
215
214
  - test/test_runner.rb
216
215
  - test/test_simplesearcher.rb
216
+ - test/test_syntax_highlighter.rb
217
217
  - theme/default/images/external.png
218
218
  - theme/default/rurema.png
219
219
  - theme/default/style.css
@@ -241,23 +241,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
241
  version: '0'
242
242
  requirements: []
243
243
  rubyforge_project: ''
244
- rubygems_version: 2.7.3
244
+ rubygems_version: 2.7.4
245
245
  signing_key:
246
246
  specification_version: 4
247
247
  summary: BitClust is a rurema document processor.
248
248
  test_files:
249
- - test/test_simplesearcher.rb
250
- - test/test_refsdatabase.rb
251
- - test/test_runner.rb
252
249
  - test/test_methoddatabase.rb
253
- - test/test_nameutils.rb
254
- - test/run_test.rb
255
- - test/test_rrdparser.rb
250
+ - test/test_functiondatabase.rb
251
+ - test/test_refsdatabase.rb
256
252
  - test/test_bitclust.rb
257
253
  - test/test_methodsignature.rb
258
- - test/test_entry.rb
259
254
  - test/test_functionreferenceparser.rb
260
- - test/test_rdcompiler.rb
255
+ - test/test_simplesearcher.rb
261
256
  - test/test_preprocessor.rb
262
- - test/test_functiondatabase.rb
257
+ - test/test_runner.rb
263
258
  - test/test_libraryentry.rb
259
+ - test/test_nameutils.rb
260
+ - test/test_entry.rb
261
+ - test/run_test.rb
262
+ - test/test_rdcompiler.rb
263
+ - test/test_rrdparser.rb
264
+ - test/test_syntax_highlighter.rb
@@ -1,9 +0,0 @@
1
-
2
- module BitClust
3
- module Subcommands
4
- class ReviewCommand < Subcommand
5
- include NameUtils
6
-
7
- end
8
- end
9
- end