modl 0.3.25 → 0.3.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -140
  3. data/Gemfile +4 -2
  4. data/LICENSE.txt +1 -1
  5. data/README.md +19 -11
  6. data/Rakefile +5 -3
  7. data/lib/modl/interpreter.rb +38 -0
  8. data/lib/modl/model/model.rb +264 -0
  9. data/lib/modl/parser/parser.rb +272 -59
  10. data/lib/modl/tokeniser/context.rb +113 -0
  11. data/lib/modl/tokeniser/tokeniser.rb +28 -0
  12. data/lib/modl/util/functions.rb +74 -0
  13. data/lib/modl/util/unicode.rb +44 -0
  14. data/lib/modl/version.rb +5 -0
  15. data/lib/modl.rb +7 -32
  16. data/modl.gemspec +8 -11
  17. metadata +16 -75
  18. data/.DS_Store +0 -0
  19. data/.idea/vcs.xml +0 -6
  20. data/.rspec +0 -3
  21. data/.rubocop.yml +0 -5
  22. data/.travis.yml +0 -7
  23. data/bin/console +0 -14
  24. data/bin/setup +0 -8
  25. data/lib/modl/parser/MODLLexer.interp +0 -132
  26. data/lib/modl/parser/MODLLexer.rb +0 -324
  27. data/lib/modl/parser/MODLLexer.tokens +0 -40
  28. data/lib/modl/parser/MODLParser.interp +0 -93
  29. data/lib/modl/parser/MODLParser.rb +0 -2492
  30. data/lib/modl/parser/MODLParser.tokens +0 -40
  31. data/lib/modl/parser/MODLParserBaseListener.rb +0 -164
  32. data/lib/modl/parser/MODLParserBaseVisitor.rb +0 -107
  33. data/lib/modl/parser/MODLParserListener.rb +0 -151
  34. data/lib/modl/parser/MODLParserVisitor.rb +0 -56
  35. data/lib/modl/parser/class_processor.rb +0 -411
  36. data/lib/modl/parser/evaluator.rb +0 -125
  37. data/lib/modl/parser/file_importer.rb +0 -101
  38. data/lib/modl/parser/global_parse_context.rb +0 -318
  39. data/lib/modl/parser/instruction_processor.rb +0 -84
  40. data/lib/modl/parser/interpreter.rb +0 -75
  41. data/lib/modl/parser/modl_class.rb +0 -138
  42. data/lib/modl/parser/modl_index.rb +0 -54
  43. data/lib/modl/parser/modl_keylist.rb +0 -81
  44. data/lib/modl/parser/modl_method.rb +0 -172
  45. data/lib/modl/parser/object_cache.rb +0 -88
  46. data/lib/modl/parser/orphan_handler.rb +0 -98
  47. data/lib/modl/parser/parsed.rb +0 -1470
  48. data/lib/modl/parser/ref_processor.rb +0 -258
  49. data/lib/modl/parser/substitutions.rb +0 -101
  50. data/lib/modl/parser/sutil.rb +0 -108
  51. data/lib/modl/parser/throwing_error_listener.rb +0 -44
  52. data/lib/modl/parser/unicode_escape_replacer.rb +0 -148
  53. data/lib/modl/parser/unicode_escapes.rb +0 -112
  54. data/lib/modl/parser/version.rb +0 -29
@@ -1,112 +0,0 @@
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, len) = try_parse(result, uni_str_idx + 2)
59
- uni_val = value.chr(Encoding::UTF_8)
60
- left = result.slice(0, uni_str_idx)
61
- right = result.slice(uni_str_idx + (2 + len), 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
-
68
- def self.enough_digits?(str, idx, n)
69
- i = 0
70
- chars = str.chars
71
- while i < n && (idx + i) < str.length
72
- c = chars[idx + i]
73
- unless (('0'..'9').include? c) || (('a'..'f').include? c) || (('A'..'F').include? c)
74
- return false
75
- end
76
- i += 1
77
- end
78
- (i == n) ? true : false
79
- end
80
-
81
- # unicode can be 4 to 6 characters
82
- def self.try_parse(str, idx)
83
- if enough_digits?(str, idx, 6)
84
- value = str.slice(idx, 6).to_i(16)
85
- if valid_range? value
86
- return [value, 6]
87
- end
88
- end
89
- if enough_digits?(str, idx, 5)
90
- value = str.slice(idx, 5).to_i(16)
91
- if valid_range? value
92
- return [value, 5]
93
- end
94
- end
95
- if enough_digits?(str, idx, 4)
96
- value = str.slice(idx, 4).to_i(16)
97
- if valid_range? value
98
- return [value, 4]
99
- end
100
- if valid_range? value
101
- return [value, 4]
102
- end
103
- end
104
- [0, 4]
105
- end
106
-
107
- def self.valid_range?(value)
108
- return ((0x100000..0x10ffff).include? value) || ((0x10000..0xfffff).include? value) || ((0..0xd7ff).include? value) || ((0xe000..0xffff).include? value) ? true : false
109
- end
110
- end
111
- end
112
- end
@@ -1,29 +0,0 @@
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
- VERSION = "0.3.25"
28
- end
29
- end