ebnf 2.3.4 → 2.4.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.
data/lib/ebnf/writer.rb CHANGED
@@ -11,42 +11,81 @@ module EBNF
11
11
  LINE_LENGTH = 80
12
12
  LINE_LENGTH_HTML = 200
13
13
 
14
- # ASCII escape names
15
- ASCII_ESCAPE_NAMES = [
16
- "null", #x00
17
- "start of heading", #x01
18
- "start of text", #x02
19
- "end of text", #x03
20
- "end of transmission", #x04
21
- "enquiry", #x05
22
- "acknowledge", #x06
23
- "bell", #x07
24
- "backspace", #x08
25
- "horizontal tab", #x09
26
- "new line", #x0A
27
- "vertical tab", #x0B
28
- "form feed", #x0C
29
- "carriage return", #x0D
30
- "shift out", #x0E
31
- "shift in", #x0F
32
- "data link escape", #x10
33
- "device control 1", #x11
34
- "device control 2", #x12
35
- "device control 3", #x13
36
- "device control 4", #x14
37
- "negative acknowledge", #x15
38
- "synchronous idle", #x16
39
- "end of trans. block", #x17
40
- "cancel", #x18
41
- "end of medium", #x19
42
- "substitute", #x1A
43
- "escape", #x1B
44
- "file separator", #x1C
45
- "group separator", #x1D
46
- "record separator", #x1E
47
- "unit separator", #x1F
48
- "space" #x20
49
- ]
14
+ # UNICODE escape names
15
+ # From https://en.wikipedia.org/wiki/List_of_Unicode_characters
16
+ UNICODE_ESCAPE_NAMES = {
17
+ 0x00 => 'null',
18
+ 0x01 => 'start of heading',
19
+ 0x02 => 'start of text',
20
+ 0x03 => 'end of text',
21
+ 0x04 => 'end of transmission',
22
+ 0x05 => 'enquiry',
23
+ 0x06 => 'acknowledge',
24
+ 0x07 => 'bell',
25
+ 0x08 => 'backspace',
26
+ 0x09 => 'horizontal tab',
27
+ 0x0A => 'new line',
28
+ 0x0B => 'vertical tab',
29
+ 0x0C => 'form feed',
30
+ 0x0D => 'carriage return',
31
+ 0x0E => 'shift out',
32
+ 0x0F => 'shift in',
33
+ 0x10 => 'data link escape',
34
+ 0x11 => 'device control 1',
35
+ 0x12 => 'device control 2',
36
+ 0x13 => 'device control 3',
37
+ 0x14 => 'device control 4',
38
+ 0x15 => 'negative acknowledge',
39
+ 0x16 => 'synchronous idle',
40
+ 0x17 => 'end of trans. block',
41
+ 0x18 => 'cancel',
42
+ 0x19 => 'end of medium',
43
+ 0x1A => 'substitute',
44
+ 0x1B => 'escape',
45
+ 0x1C => 'file separator',
46
+ 0x1D => 'group separator',
47
+ 0x1E => 'record separator',
48
+ 0x1F => 'unit separator',
49
+ 0x20 => 'space',
50
+ 0x22 => 'dquote',
51
+ 0x27 => 'apos',
52
+ 0x2F => 'slash',
53
+ 0x5C => 'backslash',
54
+ 0x60 => 'grave',
55
+ 0x7F => 'delete',
56
+ 0x80 => 'padding character',
57
+ 0x81 => 'high octet preset',
58
+ 0x82 => 'break permitted here',
59
+ 0x83 => 'no break here',
60
+ 0x84 => 'index',
61
+ 0x85 => 'next line',
62
+ 0x86 => 'start of selected area',
63
+ 0x87 => 'end of selected area',
64
+ 0x88 => 'character tabulation set',
65
+ 0x89 => 'character tabulation with justification',
66
+ 0x8A => 'line tabulation set',
67
+ 0x8B => 'partial line forward',
68
+ 0x8C => 'partial line backward',
69
+ 0x8D => 'reverse line feed',
70
+ 0x8E => 'single-shift two',
71
+ 0x8F => 'single-shift three',
72
+ 0x90 => 'device control string',
73
+ 0x91 => 'private use 1',
74
+ 0x92 => 'private use 2',
75
+ 0x93 => 'set transmit state',
76
+ 0x94 => 'cancel character',
77
+ 0x95 => 'message waiting',
78
+ 0x96 => 'start of protected area',
79
+ 0x97 => 'end of protected area',
80
+ 0x98 => 'start of string',
81
+ 0x99 => 'single graphic character introducer',
82
+ 0x9A => 'single character intro introducer',
83
+ 0x9B => 'control sequence introducer',
84
+ 0x9C => 'string terminator',
85
+ 0x9D => 'operating system command',
86
+ 0x9E => 'private message',
87
+ 0x9F => 'application program command',
88
+ }
50
89
 
51
90
  ##
52
91
  # Format rules to a String
@@ -360,27 +399,19 @@ module EBNF
360
399
 
361
400
  def escape_ebnf_hex(u)
362
401
  fmt = case u.ord
363
- when 0x00..0x20 then "#x%02X"
364
402
  when 0x0000..0x00ff then "#x%02X"
365
403
  when 0x0100..0xffff then "#x%04X"
366
404
  else "#x%08X"
367
405
  end
368
406
  char = fmt % u.ord
369
407
  if @options[:html]
370
- char = if u.ord <= 0x20
371
- %(<abbr title="#{ASCII_ESCAPE_NAMES[u.ord]}">#{@coder.encode char}</abbr>)
372
- elsif u.ord == 0x22
373
- %(<abbr title="quot">>&quot;</abbr>)
374
- elsif u.ord < 0x7F
375
- %(<abbr title="ascii '#{@coder.encode u}'">#{@coder.encode char}</abbr>)
376
- elsif u.ord == 0x7F
377
- %(<abbr title="delete">#{@coder.encode char}</abbr>)
378
- elsif u.ord <= 0xFF
379
- %(<abbr title="extended ascii '#{@coder.encode char}'">#{char}</abbr>)
380
- elsif (%w(Control Private-use Surrogate Noncharacter Reserved) - ::Unicode::Types.of(u)).empty?
381
- %(<abbr title="unicode '#{u}'">#{char}</abbr>)
408
+ char = if UNICODE_ESCAPE_NAMES.include?(u.ord)
409
+ %(<abbr title="#{UNICODE_ESCAPE_NAMES[u.ord]}">#{char}</abbr>)
410
+ elsif ([::Unicode::Types.of(u)] - %w(Control Private-use Surrogate Noncharacter Reserved)).empty?
411
+ %(<abbr title="unicode '#{@coder.encode u}'">#{char}</abbr>)
382
412
  else
383
- %(<abbr title="unicode '#{::Unicode::Types.of(u).first}'">#{char}</abbr>)
413
+ uni_esc = "U+%04X" % u.ord
414
+ %(<abbr title="unicode #{uni_esc}">#{char}</abbr>)
384
415
  end
385
416
  %(<code class="grammar-char-escape">#{char}</code>)
386
417
  else
@@ -561,18 +592,13 @@ module EBNF
561
592
  end
562
593
  char = "%x" + (fmt % u.ord).upcase
563
594
  if @options[:html]
564
- if u.ord <= 0x20
565
- char = %(<abbr title="#{ASCII_ESCAPE_NAMES[u.ord]}">#{@coder.encode char}</abbr>)
566
- elsif u.ord == 0x22
567
- %(<abbr title="quot">>&quot;</abbr>)
568
- elsif u.ord < 0x7F
569
- char = %(<abbr title="ascii '#{u}'">#{@coder.encode char}</abbr>)
570
- elsif u.ord == 0x7F
571
- char = %(<abbr title="delete">#{@coder.encode char}</abbr>)
572
- elsif u.ord <= 0xFF
573
- char = %(<abbr title="extended ascii '#{u}'">#{char}</abbr>)
595
+ char = if UNICODE_ESCAPE_NAMES.include?(u.ord)
596
+ %(<abbr title="#{UNICODE_ESCAPE_NAMES[u.ord]}">#{char}</abbr>)
597
+ elsif ([::Unicode::Types.of(u)] - %w(Control Private-use Surrogate Noncharacter Reserved)).empty?
598
+ %(<abbr title="unicode '#{@coder.encode u}'">#{char}</abbr>)
574
599
  else
575
- char = %(<abbr title="unicode '#{u.unicode_normaliz}'">#{char}</abbr>)
600
+ uni_esc = "U+%04X" % u.ord
601
+ %(<abbr title="unicode #{uni_esc}">#{char}</abbr>)
576
602
  end
577
603
  %(<code class="grammar-char-escape">#{char}</code>)
578
604
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebnf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.4
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregg Kellogg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-09 00:00:00.000000000 Z
11
+ date: 2023-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sxp
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: '1.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.2'
26
+ version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: scanf
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.2'
47
+ version: '3.3'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.2'
54
+ version: '3.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: htmlentities
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,48 +100,48 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '3.2'
103
+ version: '3.3'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '3.2'
110
+ version: '3.3'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rdf-turtle
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '3.2'
117
+ version: '3.3'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '3.2'
124
+ version: '3.3'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: nokogiri
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '1.13'
131
+ version: '1.15'
132
132
  - - ">="
133
133
  - !ruby/object:Gem::Version
134
- version: 1.13.4
134
+ version: 1.15.4
135
135
  type: :development
136
136
  prerelease: false
137
137
  version_requirements: !ruby/object:Gem::Requirement
138
138
  requirements:
139
139
  - - "~>"
140
140
  - !ruby/object:Gem::Version
141
- version: '1.13'
141
+ version: '1.15'
142
142
  - - ">="
143
143
  - !ruby/object:Gem::Version
144
- version: 1.13.4
144
+ version: 1.15.4
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: erubis
147
147
  requirement: !ruby/object:Gem::Requirement
@@ -293,14 +293,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
293
293
  requirements:
294
294
  - - ">="
295
295
  - !ruby/object:Gem::Version
296
- version: '2.6'
296
+ version: '3.0'
297
297
  required_rubygems_version: !ruby/object:Gem::Requirement
298
298
  requirements:
299
299
  - - ">="
300
300
  - !ruby/object:Gem::Version
301
301
  version: '0'
302
302
  requirements: []
303
- rubygems_version: 3.4.10
303
+ rubygems_version: 3.2.33
304
304
  signing_key:
305
305
  specification_version: 4
306
306
  summary: EBNF parser and parser generator in Ruby.