schizm 0.0.6 → 0.0.7

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/schizm/match.rb +42 -18
  3. data/lib/schizm/parse.rb +38 -35
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2123141f335e7349ec095d5b078acc21f09ed75
4
- data.tar.gz: 7751549bb232c6cd6d9d4e63e5a3fd5d3a659574
3
+ metadata.gz: 0e2929e0a7f68d25c528e1d9b9d0701a22d58994
4
+ data.tar.gz: 623845d2684c673a9ccb76d8f81f354ea984e0a2
5
5
  SHA512:
6
- metadata.gz: a5c82e3b896e625eaf65d54dbef821c192f9bbd742beeb1f2a4d0e73e42a258caf9766ca7c96efb2d3db7dd4f13948c0e85c289a20f8f89c948fb04bd2f79d5c
7
- data.tar.gz: a2919358945784a928cc2d48201e23013ae5ce72983a2bf4e644c055dd1d4381db3877707f84c959dae8ae4bfff209766ef82f55ca7759680d927bddc38afff4
6
+ metadata.gz: 0f7659693638560c2aef258fa915cc76c261c5627c6fc4e26792a8e19e732943e6158b3da6d71d1c85f44a7f0d838e99b240f1cad8076e447093d66841d85190
7
+ data.tar.gz: ec67ab6941bb54b8294f6a2e2d4f75ec4f489b32c3a452e3892e45c377fac6b651c085db5869e834259362637e9ad74a7641c820981a2fd0754e66606d0e8cea
@@ -1,18 +1,18 @@
1
1
  # Copyright (c) 2017 M. Grady Saunders
2
- #
2
+ #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions
5
5
  # are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above
8
8
  # copyright notice, this list of conditions and the following
9
9
  # disclaimer.
10
- #
10
+ #
11
11
  # 2. Redistributions in binary form must reproduce the above
12
12
  # copyright notice, this list of conditions and the following
13
13
  # disclaimer in the documentation and/or other materials
14
14
  # provided with the distribution.
15
- #
15
+ #
16
16
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
17
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
18
  # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -33,12 +33,6 @@ module Schizm
33
33
  # Source path, extension put in match group 1.
34
34
  SOURCE_PATH = /^.*\.(c|cc|cpp|cxx|inl|tcc)$/
35
35
 
36
- # Single quotes.
37
- QUOTE1_STRING = /'((?:[^\\']*(?:\\.)*)*)'/u
38
-
39
- # Double quotes.
40
- QUOTE2_STRING = /"((?:[^\\"]*(?:\\.)*)*)"/u
41
-
42
36
  # Space sequence.
43
37
  SPACE = /\p{Space}+/u
44
38
 
@@ -99,7 +93,7 @@ module Schizm
99
93
  # HTML entity.
100
94
  HTML_ENTITY = /&(?:\w+|\#\d+|\#x\h+);/
101
95
 
102
- # HTML special characters.
96
+ # HTML special characters.
103
97
  HTML_ESCAPE = /[\p{^ASCII}&<>]/u
104
98
 
105
99
  # Character escape, put in match group 1.
@@ -108,12 +102,12 @@ module Schizm
108
102
  # Link definition, content put in match group 1, params put in match group 2.
109
103
  LINK_DEF = /^\[(#{DELIM_BRACKS})\]:[ ]*(.*)[ ]*\n/u
110
104
 
111
- # Link reference, content put in match group 1, params put in match group 2.
112
- LINK_REF_BRACKS = /\[(#{DELIM_BRACKS})\]\[(#{DELIM_BRACKS})\]/um
113
-
114
105
  # Link reference, content put in match group 1, params put in match group 2.
115
106
  LINK_REF_PARENS = /\[(#{DELIM_BRACKS})\]\((#{DELIM_PARENS})\)/um
116
107
 
108
+ # Link reference, content put in match group 1, params put in match group 2.
109
+ LINK_REF_BRACKS = /\[(#{DELIM_BRACKS})\](?:\[(#{DELIM_BRACKS})\])?/um
110
+
117
111
  # Image definition, entry put in match group 1, params put in match group 2.
118
112
  IMAGE_DEF = /^!\[(#{DELIM_BRACKS})\]:[ ]*(.*)[ ]*\n/u
119
113
 
@@ -121,7 +115,7 @@ module Schizm
121
115
  IMAGE_REF_PARENS = /!\[(#{DELIM_BRACKS})\]\((#{DELIM_PARENS})\)/u
122
116
 
123
117
  # Image reference, alt put in match group 1, params put in match group 2.
124
- IMAGE_REF_BRACKS = /!\[(#{DELIM_BRACKS})\]\[(#{DELIM_BRACKS})\]/u
118
+ IMAGE_REF_BRACKS = /!\[(#{DELIM_BRACKS})\](?:\[(#{DELIM_BRACKS})\])?/u
125
119
 
126
120
  # Center math, content put in match group 1.
127
121
  CENTER_MATH = /[$][$]((?:[^\\$]*(?:\\.)*)*)[$][$]/um
@@ -250,6 +244,38 @@ module Schizm
250
244
  [/\|==>/u, 10503] # Right double arrow from bar.
251
245
  ]
252
246
 
247
+ CPP_INT_DIGITS_02 = /0[Bb][0-1]+/
248
+
249
+ CPP_INT_DIGITS_16 = /0[Xx][0-9A-Fa-f]+/
250
+
251
+ CPP_INT_DIGITS_10 = /[1-9][0-9]*|0(?![0-9])/
252
+
253
+ CPP_INT_DIGITS_08 = /0[0-7]+/
254
+
255
+ CPP_INT_DIGITS = Regexp.union [
256
+ CPP_INT_DIGITS_02,
257
+ CPP_INT_DIGITS_16,
258
+ CPP_INT_DIGITS_10,
259
+ CPP_INT_DIGITS_08
260
+ ]
261
+
262
+ CPP_INT = /#{CPP_INT_DIGITS}(?:[Uu][Ll]{0,2}|[Ll]{1,2}|_[0-9A-Za-z_]+)?/
263
+
264
+ CPP_FLT_DIGITS_10 = /(?:\.[0-9]+|[0-9]+\.[0-9]*|[0-9]+(?=[Ee]))(?:[Ee][+-]?[0-9]+)?/
265
+
266
+ CPP_FLT_DIGITS_16 = /(?:0[Xx]1\.[0-9A-Fa-f]+[Pp][+-][0-9]+)/
267
+
268
+ CPP_FLT_DIGITS = Regexp.union [
269
+ CPP_FLT_DIGITS_10,
270
+ CPP_FLT_DIGITS_16
271
+ ]
272
+
273
+ CPP_FLT = /#{CPP_FLT_DIGITS}(?:[Ii]?[FfLl]|_[A-Za-z0-9_]+)?/
274
+
275
+ CPP_NUMBER = /[+-]?(?:#{CPP_FLT}|#{CPP_INT})/
276
+
277
+ CPP_STRING = /(?:u8?|[ULR])?(["'])((?:[^\\\1]*(?:\\.)*)*)\1/u
278
+
253
279
  # Syntax highlighting.
254
280
  HIGHLIGHT_CPP = [
255
281
  ["hi-comment", /\/\/.*$/u],
@@ -260,9 +286,7 @@ module Schizm
260
286
  ["hi-type-spec", /(?:constexpr|const|volatile|static|mutable|thread_local|register|extern|inline|noexcept)\b/u],
261
287
  ["hi-flow", /(?:new|delete|do|while|for|if|else|try|throw|catch|switch|case|default|break|continue|goto|return)\b/u],
262
288
  ["hi-op", /(?:(?:and|or|xor|not)(?:_eq)?|bitand|bitor|compl|(?:(?:const|dynamic|static|reinterpret)_cast))\b/u],
263
- ["hi-value", /(?:true|false|this|nullptr|NULL)\b/u],
264
- ["hi-value", /'[^'\\]*(?:\\.[^'\\]*)*'/u], # Single quote
265
- ["hi-value", /"[^"\\]*(?:\\.[^"\\]*)*"/u], # Double quote
289
+ ["hi-value", /(?:true|false|this|nullptr|NULL|#{CPP_NUMBER}|#{CPP_STRING})\b/u],
266
290
  ["hi-other", /(?:alignas|alignof|sizeof|decltype|template|typename|typedef|using|concept|requires|operator)\b/u],
267
291
  ["hi-other", /(?:namespace|class|struct|enum|public|protected|private|friend|final|virtual|override)\b/u],
268
292
  ["hi-ident", /[a-zA-Z]\w*/u],
@@ -141,30 +141,33 @@ module Parse
141
141
  when sscan.skip(HTML_ESCAPE) then sscan[0].codepoints[0]
142
142
  when sscan.skip(CHAR_ESCAPE) then sscan[0].codepoints[0]
143
143
  when sscan.skip(LINK_REF_PARENS)
144
- shown = String.new(sscan[1]).unescape("]")
145
- param = String.new(sscan[2]).unescape(")")
144
+ text = String.new(sscan[1]).unescape("]")
145
+ info = String.new(sscan[2]).unescape(")")
146
+ sscan2 = StringScanner.new(info)
146
147
  attrs = Hash.new
147
- sscan2 = StringScanner.new(param)
148
+ attrs["target"] = "_blank"
148
149
  until sscan2.eos?
149
150
  case
150
- when sscan2.skip(QUOTE1_STRING) then attrs["title"] = String.new(sscan2[1]).unescape("'")
151
- when sscan2.skip(QUOTE2_STRING) then attrs["title"] = String.new(sscan2[1]).unescape("\"").gsub(/"/u, "'")
151
+ when sscan2.skip(/'((?:[^\\']*(?:\\.)*)*)'/u) then attrs["title"] = sscan2[1]
152
+ when sscan2.skip(/"((?:[^\\"]*(?:\\.)*)*)"/u) then attrs["title"] = sscan2[1]
152
153
  when sscan2.skip(/\p{Graph}+/u) then attrs["href"] = sscan2[0]
153
154
  when sscan2.skip(/\p{Space}+/u) then nil
154
155
  end
155
156
  end
156
157
  Markup.new("a")
157
- .add_attrs("target" => "_blank")
158
158
  .add_attrs(attrs)
159
- .add_elems(line_elems(where, shown))
159
+ .add_elems(line_elems(where, text))
160
160
  when sscan.skip(LINK_REF_BRACKS)
161
- shown = String.new(sscan[1]).unescape("]")
162
- param = String.new(sscan[2]).unescape("]")
161
+ text =
162
+ name = String.new(sscan[1]).unescape("]")
163
+ name = String.new(sscan[2]).unescape("]") if sscan[2]
164
+ attrs = Hash.new
165
+ attrs["target"] = "_blank"
166
+ attrs["title"] = HashAttr.new @@links[where][name], "title"
167
+ attrs["href"] = HashAttr.new @@links[where][name], "href"
163
168
  Markup.new("a")
164
- .add_attrs("target" => "_blank")
165
- .add_attrs("title" => HashAttr.new(@@links[where][param], "title"))
166
- .add_attrs("href" => HashAttr.new(@@links[where][param], "href"))
167
- .add_elems(line_elems(where, shown))
169
+ .add_attrs(attrs)
170
+ .add_elems(line_elems(where, text))
168
171
  when sscan.skip(CENTER_MATH)
169
172
  Markup.new("script")
170
173
  .add_attrs(CENTER_MATH_ATTRS)
@@ -221,7 +224,6 @@ module Parse
221
224
  when sscan.skip(HEADING_ATX)
222
225
  type = String.new sscan[1]
223
226
  text = String.new sscan[2]
224
- slug = text.slugify
225
227
  Markup.new(
226
228
  case type.size
227
229
  when 1 then "h1"
@@ -243,33 +245,34 @@ module Parse
243
245
  .add_attrs("class" => "title")
244
246
  .add_elems(line_elems(where, text))
245
247
  when sscan.skip(LINK_DEF)
246
- entry = String.new(sscan[1]).unescape("]")
248
+ name = String.new(sscan[1]).unescape("]")
247
249
  sscan2 = StringScanner.new(sscan[2])
248
250
  until sscan2.eos?
249
251
  case
250
- when sscan2.skip(QUOTE1_STRING) then @@links[where][entry]["title"] = String.new(sscan2[1]).unescape("'")
251
- when sscan2.skip(QUOTE2_STRING) then @@links[where][entry]["title"] = String.new(sscan2[1]).unescape("\"").gsub(/"/u, "'")
252
- when sscan2.skip(/\p{Graph}+/u) then @@links[where][entry]["href"] = sscan2[0]
252
+ when sscan2.skip(/'((?:[^\\']*(?:\\.)*)*)'/u) then @@links[where][name]["title"] = sscan2[1]
253
+ when sscan2.skip(/"((?:[^\\"]*(?:\\.)*)*)"/u) then @@links[where][name]["title"] = sscan2[1]
254
+ when sscan2.skip(/\p{Graph}+/u) then @@links[where][name]["href"] = sscan2[0]
253
255
  when sscan2.skip(/\p{Space}+/u) then nil
254
256
  end
255
257
  end
256
258
  nil
257
259
  when sscan.skip(IMAGE_DEF)
258
- entry = String.new(sscan[1]).unescape("]")
260
+ name = String.new(sscan[1]).unescape("]")
259
261
  sscan2 = StringScanner.new(sscan[2])
260
262
  until sscan2.eos?
261
263
  case
262
- when sscan2.skip(/w=(\d+)/u) then @@images[where][entry]["width"] = sscan2[1]
263
- when sscan2.skip(/h=(\d+)/u) then @@images[where][entry]["height"] = sscan2[1]
264
- when sscan2.skip(/\p{Graph}+/u) then @@images[where][entry]["src"] = sscan2[0]
264
+ when sscan2.skip(/w=(\d+)/u) then @@images[where][name]["width"] = sscan2[1]
265
+ when sscan2.skip(/h=(\d+)/u) then @@images[where][name]["height"] = sscan2[1]
266
+ when sscan2.skip(/\p{Graph}+/u) then @@images[where][name]["src"] = sscan2[0]
265
267
  when sscan2.skip(/\p{Space}+/u) then nil
266
268
  end
267
269
  end
268
270
  when sscan.skip(/^[ ]{0,3}#{IMAGE_REF_PARENS}$/u)
269
- alt = String.new(sscan[1]).unescape("]")
270
- param = String.new(sscan[2]).unescape(")")
271
- sscan2 = StringScanner.new(param)
271
+ text = String.new(sscan[1]).unescape("]")
272
+ info = String.new(sscan[2]).unescape(")")
273
+ sscan2 = StringScanner.new(info)
272
274
  attrs = Hash.new
275
+ attrs["alt"] = text
273
276
  until sscan2.eos?
274
277
  case
275
278
  when sscan2.skip(/w=(\d+)/u) then attrs["width"] = sscan2[1]
@@ -278,17 +281,17 @@ module Parse
278
281
  when sscan2.skip(/\p{Space}+/u) then nil
279
282
  end
280
283
  end
281
- Markup.new("img")
282
- .add_attrs("alt" => alt)
283
- .add_attrs(attrs)
284
+ Markup.new("img").add_attrs(attrs)
284
285
  when sscan.skip(/^[ ]{0,3}#{IMAGE_REF_BRACKS}$/u)
285
- alt = String.new(sscan[1]).unescape("]")
286
- entry = String.new(sscan[2]).unescape("]")
287
- Markup.new("img")
288
- .add_attrs("alt" => alt)
289
- .add_attrs("src" => HashAttr.new(@@images[where][entry], "src"))
290
- .add_attrs("width" => HashAttr.new(@@images[where][entry], "width"))
291
- .add_attrs("height" => HashAttr.new(@@images[where][entry], "height"))
286
+ text =
287
+ name = String.new(sscan[1]).unescape("]")
288
+ name = String.new(sscan[2]).unescape("]") if sscan[2]
289
+ attrs = Hash.new
290
+ attrs["alt"] = text
291
+ attrs["src"] = HashAttr.new @@images[where][name], "src"
292
+ attrs["width"] = HashAttr.new @@images[where][name], "width"
293
+ attrs["height"] = HashAttr.new @@images[where][name], "height"
294
+ Markup.new("img").add_attrs(attrs)
292
295
  when sscan.skip(/^#{CHUNK_LABEL}/u)
293
296
  div = nil
294
297
  chunk = Chunk.hash[where][String.new(sscan[1]).unescape("]")]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schizm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - M. Grady Saunders
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-23 00:00:00.000000000 Z
11
+ date: 2017-12-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: mgradysaunders@gmail.com