modl 0.3.19 → 0.3.20

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: 0e391e57bad47d661e08c986b5a5b660fc10312e8c6a196b00318fbfe57ec621
4
- data.tar.gz: df205763034d607acf635c6d2b2ce37c3b48bdf39626c17d9eead2f99f351a77
3
+ metadata.gz: '00617859c13359189d14d838eb6701f4a755f3933631e7771c664751e1779651'
4
+ data.tar.gz: 46967560c08f4eb541553bc184e0688040e91f5e3513da6709d316dae74b7f4a
5
5
  SHA512:
6
- metadata.gz: 7208bfae428e5f0de6a54f0727f525f2db44a11c2022dc493e5696a5cfaff50b3a45722f2a657ee93f242eae670e273071a3e137dd70859777810120c1751bc1
7
- data.tar.gz: ac22712bed4d0d4dd9ac46b129136f1617d381367ddbe6dc0c47173ecc0ef22bc110b08fbdccfa515e818834ab7ebf70d13c19bc241f4b946d897013e2f28dd2
6
+ metadata.gz: cb09f90f72233e3de2b672aca0c1d3ef04f56ced05440a6a37bd31eb029bf6e23b46e4e880b859dbce4d5ba1a162b8d3841edb5c04d7ed7fa7b67edb06db4ab2
7
+ data.tar.gz: 2740782db327af3741d4627fccce8d4af0875830d007171df7f9b705fab0faecd8fe3ccdb820d601a7079f78f9a838ab295b0acbc7f64f322b1eb6a2c97b4cb5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.3.20
2
+ ===
3
+ - Support escaping unicode escape sequences so they are not replaced by unicode characters.
4
+
1
5
  0.3.19
2
6
  ===
3
7
  - Fix bug with `*assign` when there is only 1 item in the array.
@@ -3014,12 +3014,12 @@
3014
3014
  },
3015
3015
  {
3016
3016
  "id": "316",
3017
- "input": "We\\\\u2019re=We\\\\u2019re;You~u2019re=We~u2019re",
3017
+ "input": "We\\u2019re=We\\u2019re;You~u2019re=We~u2019re",
3018
3018
  "expected_output": "{\n \"We’re\": \"We’re\",\n \"You’re\": \"We’re\"\n}",
3019
3019
  "tested_features": [
3020
3020
  "unicode"
3021
3021
  ],
3022
- "minimised_modl": "We\\\\u2019re=We\\\\u2019re;You~u2019re=We~u2019re"
3022
+ "minimised_modl": "We\\u2019re=We\\u2019re;You~u2019re=We~u2019re"
3023
3023
  },
3024
3024
  {
3025
3025
  "id": "317",
@@ -3056,5 +3056,35 @@
3056
3056
  "class"
3057
3057
  ],
3058
3058
  "minimised_modl": "*class(*id=m;*name=message;*superclass=map;*assign=[[direction;date_time;message]];method=sms);[m=out:2018-03-22 15\\:25:Hi;m=in:2018-03-22 15\\:26:Hello, how are you?;m=out:2018-03-22 15\\:25:Hi, good thanks;m=out:2018-03-22 15\\:26:How about you?;m=in:2018-03-22 1\\:26:Yes, fine thanks. What are you up to?;m=out:2018-03-22 15\\:25:Just testing out MODL;m=in:2018-03-22 15\\:26:Cool!]"
3059
+ },
3060
+ {
3061
+ "id": "321",
3062
+ "input": "test=\\~u2019",
3063
+ "expected_output": "{\n \"test\": \"~u2019\"\n}",
3064
+ "tested_features": [
3065
+ "unicode",
3066
+ "escapes"
3067
+ ],
3068
+ "minimised_modl": "test=\\~u2019"
3069
+ },
3070
+ {
3071
+ "id": "322",
3072
+ "input": "test=\\\\u2019",
3073
+ "expected_output": "{\n \"test\": \"\\\\u2019\"\n}",
3074
+ "tested_features": [
3075
+ "unicode",
3076
+ "escapes"
3077
+ ],
3078
+ "minimised_modl": "test=\\\\u2019"
3079
+ },
3080
+ {
3081
+ "id": "323",
3082
+ "input": "test=\\\\~u2019\\\\u2019~u2019\\\\u2019",
3083
+ "expected_output": "{\n \"test\": \"~u2019\\\\u2019\u2019\\\\u2019\"\n}",
3084
+ "tested_features": [
3085
+ "unicode",
3086
+ "escapes"
3087
+ ],
3088
+ "minimised_modl": "test=\\\\~u2019\\\\u2019~u2019\\\\u2019"
3059
3089
  }
3060
3090
  ]
@@ -54,7 +54,7 @@ module MODL
54
54
  while i < condition.values.length
55
55
  item = condition.values[i]
56
56
  if item.primitive.constant
57
- value2 = Substitutions.process(item.text)
57
+ value2 = Substitutions.process UnicodeEscapes.process(item.text)
58
58
  else
59
59
  value2, success = value(global, item.text)
60
60
  end
@@ -105,12 +105,12 @@ module MODL
105
105
  if ikey.to_s == key
106
106
  index_val = global.index[ikey]
107
107
  value1 = index_val.respond_to?(:text) ? index_val.text : nil
108
- value1 = Substitutions.process(value1)
108
+ value1 = Substitutions.process UnicodeEscapes.process(value1)
109
109
  else
110
110
  pair = global.pair(key)
111
- return Substitutions.process(k) unless pair
111
+ return Substitutions.process UnicodeEscapes.process(k) unless pair
112
112
 
113
- value1 = Substitutions.process(pair.text)
113
+ value1 = Substitutions.process UnicodeEscapes.process(pair.text)
114
114
  end
115
115
  success = true
116
116
  end
@@ -25,6 +25,7 @@
25
25
  require 'modl/parser/MODLParserBaseListener'
26
26
  require 'modl/parser/global_parse_context'
27
27
  require 'modl/parser/ref_processor'
28
+ require 'modl/parser/unicode_escapes'
28
29
  require 'modl/parser/substitutions'
29
30
  require 'modl/parser/file_importer'
30
31
  require 'antlr4/runtime/parse_cancellation_exception'
@@ -287,7 +288,7 @@ module MODL
287
288
  return if @type == 'allow'
288
289
  return if @type == 'expect'
289
290
 
290
- formatted_key = Substitutions.process @key
291
+ formatted_key = Substitutions.process UnicodeEscapes.process @key
291
292
  {formatted_key => @text}
292
293
  end
293
294
 
@@ -667,14 +668,14 @@ module MODL
667
668
  if user_method
668
669
  return user_method.run(@string.string)
669
670
  end
670
- return StandardMethods.run_method(key, Substitutions.process(@string.string))
671
+ StandardMethods.run_method(key, Substitutions.process(UnicodeEscapes.process(@string.string)))
671
672
  end
672
673
  end
673
674
 
674
675
  def extract_hash
675
676
  result, _ignore = RefProcessor.deref(@text, @global) unless @constant
676
677
  result = @text if @constant
677
- Substitutions.process result
678
+ Substitutions.process UnicodeEscapes.process result
678
679
  end
679
680
 
680
681
  def evaluate
@@ -743,7 +744,7 @@ module MODL
743
744
  end
744
745
 
745
746
  def extract_hash
746
- @string = Substitutions.process @string
747
+ @string = Substitutions.process UnicodeEscapes.process @string
747
748
  end
748
749
  end
749
750
 
@@ -90,19 +90,7 @@ module MODL
90
90
  break unless new_str && new_str != prev
91
91
  end
92
92
  end
93
- convert_unicode new_str
94
- end
95
-
96
- def self.convert_unicode(s)
97
- uni_str_idx = s.index('\u')
98
- uni_str_idx = s.index('~u') if uni_str_idx.nil?
99
- return s if uni_str_idx.nil?
100
-
101
- value = s.slice(uni_str_idx + 2, 4).to_i(16)
102
- uni_str = s.slice(uni_str_idx, 6)
103
- uni_val = value.chr(Encoding::UTF_8)
104
- result = s.sub(uni_str, uni_val)
105
- return convert_unicode result
93
+ new_str
106
94
  end
107
95
  end
108
96
  end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The MIT License (MIT)
4
+ #
5
+ # Copyright (c) 2019 NUM Technology Ltd
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ # THE SOFTWARE.
24
+
25
+ module MODL
26
+ module Parser
27
+ # Escape-sequence replacements for MODL files.
28
+ class UnicodeEscapes
29
+
30
+ # Replace all unicode escape sequences in the supplied string and return the new value.
31
+ def self.process(str)
32
+ return str unless str.is_a? String
33
+
34
+ start = 0
35
+ result = str
36
+ loop do
37
+
38
+ backslash_u = result.index('\u', start)
39
+ tilde_u = result.index('~u', start)
40
+
41
+ break if tilde_u.nil? && backslash_u.nil?
42
+
43
+ if tilde_u.nil?
44
+ uni_str_idx = backslash_u
45
+ elsif backslash_u.nil?
46
+ uni_str_idx = tilde_u
47
+ else
48
+ uni_str_idx = [backslash_u, tilde_u].min
49
+ end
50
+
51
+ break if uni_str_idx + 6 > result.length
52
+
53
+ start = uni_str_idx + 1
54
+
55
+ next if uni_str_idx > 0 && result[uni_str_idx - 1] == '~'
56
+ next if uni_str_idx > 0 && result[uni_str_idx - 1] == '\\'
57
+
58
+ value = result.slice(uni_str_idx + 2, 4).to_i(16)
59
+ uni_val = value.chr(Encoding::UTF_8)
60
+ left = result.slice(0, uni_str_idx)
61
+ right = result.slice(uni_str_idx + 6, result.length)
62
+ result = left + uni_val + right unless right.nil?
63
+ result = left + uni_val if right.nil?
64
+ end
65
+ result
66
+ end
67
+ end
68
+ end
69
+ end
@@ -24,6 +24,6 @@
24
24
 
25
25
  module MODL
26
26
  module Parser
27
- VERSION = "0.3.19"
27
+ VERSION = "0.3.20"
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.19
4
+ version: 0.3.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Walmsley
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-11 00:00:00.000000000 Z
11
+ date: 2019-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -131,6 +131,7 @@ files:
131
131
  - lib/modl/parser/substitutions.rb
132
132
  - lib/modl/parser/sutil.rb
133
133
  - lib/modl/parser/throwing_error_listener.rb
134
+ - lib/modl/parser/unicode_escapes.rb
134
135
  - lib/modl/parser/version.rb
135
136
  - modl.gemspec
136
137
  homepage: https://github.com/MODLanguage/ruby-interpreter