wexpr 0.1.2 → 0.1.6
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/bin/wexprTool +1 -1
- data/lib/wexpr/exception.rb +3 -0
- data/lib/wexpr/expression.rb +99 -107
- data/lib/wexpr/version.rb +1 -1
- data/lib/wexpr.rb +10 -6
- data/wexpr.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d69b8945baa9211cb2b896fdf425c0dc403e06a55599d0ebf917fa49e47c3e7
|
4
|
+
data.tar.gz: 9409bd300351110d65e637de80509d3402eeecbb4896c6349ebf8660b5f1338c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc3f65916ce7267cc67cbd0461163f7e6fde51f6a7bfc02a5b249776fefebef0a74e83a3871e09ab6c912a3c77523e549b15d440ab7626df7c2438e7c59eb106
|
7
|
+
data.tar.gz: 035c0f7df69a0b73241f8e839885bca8a392d1b5ddf6c6d079a3f1af297124e4e4153b5029bba4e0797a4ff496076c24e74e1285e64ac0765e742b57c155b5a7
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
wexpr (0.1.
|
4
|
+
wexpr (0.1.5)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
minitest (5.11.3)
|
10
|
-
rake (
|
10
|
+
rake (12.3.3)
|
11
11
|
|
12
12
|
PLATFORMS
|
13
13
|
ruby
|
@@ -15,7 +15,7 @@ PLATFORMS
|
|
15
15
|
DEPENDENCIES
|
16
16
|
bundler (~> 1.16)
|
17
17
|
minitest (~> 5.0)
|
18
|
-
rake (~>
|
18
|
+
rake (~> 12.3)
|
19
19
|
wexpr!
|
20
20
|
|
21
21
|
BUNDLED WITH
|
data/bin/wexprTool
CHANGED
data/lib/wexpr/exception.rb
CHANGED
data/lib/wexpr/expression.rb
CHANGED
@@ -170,8 +170,15 @@ module Wexpr
|
|
170
170
|
end
|
171
171
|
|
172
172
|
else
|
173
|
-
#
|
174
|
-
|
173
|
+
# see if we support to_wexpr
|
174
|
+
# if so, decode it with :returnAsExpression
|
175
|
+
if variable.class.method_defined?(:to_wexpr) && variable.method(:to_wexpr).owner != Object
|
176
|
+
# use that method
|
177
|
+
return variable.to_wexpr([:returnAsExpression])
|
178
|
+
else
|
179
|
+
# might be a number or something else, to_s it
|
180
|
+
return Expression.create_value(variable.to_s)
|
181
|
+
end
|
175
182
|
end
|
176
183
|
end
|
177
184
|
|
@@ -199,7 +206,7 @@ module Wexpr
|
|
199
206
|
|
200
207
|
# then init
|
201
208
|
if @type == :value
|
202
|
-
@value = ""
|
209
|
+
@value = "".freeze
|
203
210
|
elsif @type == :binarydata
|
204
211
|
@binarydata = ""
|
205
212
|
elsif @type == :array
|
@@ -343,7 +350,7 @@ module Wexpr
|
|
343
350
|
return
|
344
351
|
end
|
345
352
|
|
346
|
-
@value = str
|
353
|
+
@value = str.dup.freeze
|
347
354
|
end
|
348
355
|
|
349
356
|
# --- Binary Data
|
@@ -539,19 +546,13 @@ module Wexpr
|
|
539
546
|
end
|
540
547
|
|
541
548
|
def self.s_is_not_bareword_safe(c)
|
542
|
-
return (c
|
543
|
-
or c == '#' \
|
544
|
-
or c == '@' \
|
545
|
-
or c == '(' or c == ')' \
|
546
|
-
or c == '[' or c == ']' \
|
547
|
-
or c == '^' \
|
548
|
-
or c == '<' or c == '>' \
|
549
|
-
or c == '"' \
|
550
|
-
or c == ';' \
|
551
|
-
or self.s_is_whitespace(c) \
|
552
|
-
)
|
549
|
+
return /^(\*|\#|\@|\(|\)|\[|\]|\^|<|>|"|;|\s)$/.match? c
|
553
550
|
end
|
554
551
|
|
552
|
+
def self.s_index_of_first_non_bareword(s, startIndex)
|
553
|
+
return s.index(/(\*|\#|\@|\(|\)|\[|\]|\^|<|>|"|;|\s)/, startIndex)
|
554
|
+
end
|
555
|
+
|
555
556
|
def self.s_is_escape_valid(c)
|
556
557
|
return (c == '"' || c == 'r' || c == 'n' || c == 't' || c == "\\")
|
557
558
|
end
|
@@ -640,11 +641,6 @@ module Wexpr
|
|
640
641
|
|
641
642
|
# will copy out the value of the string to a new buffer, will parse out quotes as needed
|
642
643
|
def self.s_create_value_of_string(str, parserState)
|
643
|
-
# two pass:
|
644
|
-
# first pass, get the length of the size
|
645
|
-
# second pass, store the buffer
|
646
|
-
|
647
|
-
bufferLength = 0
|
648
644
|
isQuotedString = false
|
649
645
|
isEscaped = false
|
650
646
|
pos = 0 # position we're parsing at
|
@@ -654,91 +650,75 @@ module Wexpr
|
|
654
650
|
pos += 1
|
655
651
|
end
|
656
652
|
|
657
|
-
|
658
|
-
c = str[pos]
|
659
|
-
|
660
|
-
if isQuotedString
|
661
|
-
if isEscaped
|
662
|
-
# we're in an escape. Is it valid?
|
663
|
-
if self.s_is_escape_valid(c)
|
664
|
-
bufferLength += 1 # counts
|
665
|
-
isEscaped = false # escape ended
|
666
|
-
else
|
667
|
-
raise InvalidStringEscapeError.new(parserState.line, parserState.column, "Invalid escape found in the string")
|
668
|
-
end
|
669
|
-
else
|
670
|
-
if c == '"'
|
671
|
-
# end quote, part of us
|
672
|
-
pos += 1
|
673
|
-
break
|
674
|
-
elsif c == "\\"
|
675
|
-
# we're escaping
|
676
|
-
isEscaped = true
|
677
|
-
else
|
678
|
-
# otherwise it's a character
|
679
|
-
bufferLength += 1
|
680
|
-
end
|
681
|
-
end
|
682
|
-
else
|
683
|
-
# have we ended the word?
|
684
|
-
if self.s_is_not_bareword_safe(c)
|
685
|
-
# ended - not part of us
|
686
|
-
break
|
687
|
-
end
|
688
|
-
|
689
|
-
# otherwise, its a character
|
690
|
-
bufferLength += 1
|
691
|
-
end
|
692
|
-
|
693
|
-
pos += 1
|
694
|
-
end
|
695
|
-
|
696
|
-
if bufferLength == 0 and !isQuotedString # cannot have an empty barewords string
|
697
|
-
raise EmptyStringError.new(parserState.line, parserState.column, "Was told to parse an empty string")
|
698
|
-
end
|
699
|
-
|
700
|
-
endVal = pos
|
701
|
-
|
702
|
-
# we now know our buffer size and the string has been checked
|
703
|
-
# ... not that we needed this in ruby
|
653
|
+
# parse out and write the string
|
704
654
|
buffer = ""
|
705
655
|
writePos = 0
|
706
656
|
pos = 0
|
707
657
|
if isQuotedString
|
708
658
|
pos = 1
|
709
|
-
|
710
|
-
|
711
|
-
while writePos < bufferLength
|
712
|
-
c = str[pos]
|
713
|
-
|
714
|
-
if isQuotedString
|
659
|
+
while pos < str.size
|
715
660
|
if isEscaped
|
661
|
+
c = str[pos]
|
716
662
|
escapedValue = self.s_value_for_escape(c)
|
717
663
|
buffer[writePos] = escapedValue
|
718
664
|
writePos += 1
|
719
665
|
isEscaped = false
|
720
666
|
else
|
721
|
-
|
667
|
+
# move forward to the next escape or end of string
|
668
|
+
ni = str.index(/["\\]/, pos)
|
669
|
+
if ni == nil
|
670
|
+
# uhhhh no possible end to string - missing a quote?
|
671
|
+
raise StringMissingQuoteError.new(parserState.line, parserState.column, "String was quoted, but couldnt find an ending quote")
|
672
|
+
end
|
673
|
+
|
674
|
+
# otherwise, copy up to the pos
|
675
|
+
if ni != 0
|
676
|
+
sub = str[pos..ni-1]
|
677
|
+
buffer += sub
|
678
|
+
pos += sub.size
|
679
|
+
writePos += sub.size
|
680
|
+
end
|
681
|
+
|
682
|
+
# Now we're on top of a special character
|
683
|
+
c = str[pos]
|
684
|
+
if c == '"'
|
685
|
+
# end quote, part of us and we're done
|
686
|
+
pos += 1
|
687
|
+
break
|
688
|
+
elsif c == "\\"
|
722
689
|
# we're escaping
|
723
690
|
isEscaped = true
|
724
691
|
else
|
725
|
-
|
726
|
-
buffer[writePos] = c
|
727
|
-
writePos += 1
|
692
|
+
raise StandardError.new("INTERNAL ERROR: reached a special character, but not an expected special character??? (was: #{c} at #{pos})")
|
728
693
|
end
|
729
694
|
end
|
730
695
|
|
696
|
+
# next character
|
697
|
+
pos += 1
|
698
|
+
end
|
699
|
+
else # !isQuotedString
|
700
|
+
|
701
|
+
# figure out where we would end the word
|
702
|
+
sub = str[pos..-1]
|
703
|
+
i = self.s_index_of_first_non_bareword(sub, pos)
|
704
|
+
if i == nil
|
705
|
+
# entire rest is fine
|
706
|
+
buffer += sub
|
707
|
+
pos += sub.size
|
708
|
+
writePos += sub.size
|
731
709
|
else
|
732
|
-
#
|
733
|
-
buffer[
|
734
|
-
|
710
|
+
# up to i is fine
|
711
|
+
buffer += sub[0..i-1]
|
712
|
+
pos += i
|
713
|
+
writePos += i
|
735
714
|
end
|
736
|
-
|
737
|
-
# next character
|
738
|
-
pos += 1
|
739
715
|
end
|
740
|
-
|
741
|
-
|
716
|
+
|
717
|
+
if writePos == 0 and !isQuotedString # cannot have an empty barewords string
|
718
|
+
raise EmptyStringError.new(parserState.line, parserState.column, "Was told to parse an empty string")
|
719
|
+
end
|
720
|
+
|
721
|
+
return buffer, pos
|
742
722
|
end
|
743
723
|
|
744
724
|
# returns information about a string
|
@@ -943,7 +923,7 @@ module Wexpr
|
|
943
923
|
# will load into self, setting up everything. Assumes we're empty/null to start.
|
944
924
|
def p_parse_from_string(str, parseFlags, parserState)
|
945
925
|
if str.size == 0
|
946
|
-
raise EmptyStringError(parserState.line, parserState.column, "Was told to parse an empty string")
|
926
|
+
raise EmptyStringError.new(parserState.line, parserState.column, "Was told to parse an empty string")
|
947
927
|
end
|
948
928
|
|
949
929
|
# now we parse
|
@@ -1022,7 +1002,7 @@ module Wexpr
|
|
1022
1002
|
str = keyExpression.p_parse_from_string(str, parseFlags, parserState)
|
1023
1003
|
|
1024
1004
|
if keyExpression.type != :value
|
1025
|
-
raise MapKeyMustBeAValueError.new(prevLine, prevColumn, "Map keys must be a value")
|
1005
|
+
raise MapKeyMustBeAValueError.new(prevLine, prevColumn, "Map keys must be a value: was #{keyExpression.type}")
|
1026
1006
|
end
|
1027
1007
|
|
1028
1008
|
valueExpression = Expression.create_invalid()
|
@@ -1157,7 +1137,7 @@ module Wexpr
|
|
1157
1137
|
@type = :null
|
1158
1138
|
else
|
1159
1139
|
@type = :value
|
1160
|
-
@value = val
|
1140
|
+
@value = val.dup.freeze
|
1161
1141
|
end
|
1162
1142
|
|
1163
1143
|
parserState.move_forward_based_on_string(str[0..endPos-1])
|
@@ -1169,6 +1149,34 @@ module Wexpr
|
|
1169
1149
|
return ""
|
1170
1150
|
end
|
1171
1151
|
|
1152
|
+
##
|
1153
|
+
# Will write the string escaped, and with quotes
|
1154
|
+
# around it if needed.
|
1155
|
+
#
|
1156
|
+
def self.s_write_string_escaped(v, props)
|
1157
|
+
buf = ''
|
1158
|
+
|
1159
|
+
if not props[:isbarewordsafe]
|
1160
|
+
buf += '"'
|
1161
|
+
end
|
1162
|
+
|
1163
|
+
# do per character so we can escape as needed
|
1164
|
+
for c in v.chars
|
1165
|
+
if Expression.s_requires_escape(c)
|
1166
|
+
buf += "\\"
|
1167
|
+
buf += Expression.s_escape_for_value(c)
|
1168
|
+
else
|
1169
|
+
buf += c
|
1170
|
+
end
|
1171
|
+
end
|
1172
|
+
|
1173
|
+
if not props[:isbarewordsafe]
|
1174
|
+
buf += '"'
|
1175
|
+
end
|
1176
|
+
|
1177
|
+
return buf
|
1178
|
+
end
|
1179
|
+
|
1172
1180
|
# NOTE THESE BUFFERS ARE ACTUALLY MUTABLE
|
1173
1181
|
#
|
1174
1182
|
# Human Readable notes:
|
@@ -1191,23 +1199,7 @@ module Wexpr
|
|
1191
1199
|
v = self.value
|
1192
1200
|
props = Expression.s_wexpr_value_string_properties(v)
|
1193
1201
|
|
1194
|
-
|
1195
|
-
newBuf += '"'
|
1196
|
-
end
|
1197
|
-
|
1198
|
-
# do per character so we can escape as needed
|
1199
|
-
for c in v.chars
|
1200
|
-
if Expression.s_requires_escape(c)
|
1201
|
-
newBuf += "\\"
|
1202
|
-
newBuf += Expression.s_escape_for_value(c)
|
1203
|
-
else
|
1204
|
-
newBuf += c
|
1205
|
-
end
|
1206
|
-
end
|
1207
|
-
|
1208
|
-
if not props[:isbarewordsafe]
|
1209
|
-
newBuf += '"'
|
1210
|
-
end
|
1202
|
+
newBuf += Expression.s_write_string_escaped(v, props)
|
1211
1203
|
|
1212
1204
|
return newBuf
|
1213
1205
|
|
@@ -1301,7 +1293,7 @@ module Wexpr
|
|
1301
1293
|
# if human readable, indent the line, output the key, space, object, newline
|
1302
1294
|
if writeHumanReadable
|
1303
1295
|
newBuf += Expression.s_indent(indent+1)
|
1304
|
-
newBuf += key
|
1296
|
+
newBuf += Expression.s_write_string_escaped(key, Expression.s_wexpr_value_string_properties(key))
|
1305
1297
|
newBuf += " "
|
1306
1298
|
|
1307
1299
|
# add the value
|
@@ -1317,7 +1309,7 @@ module Wexpr
|
|
1317
1309
|
end
|
1318
1310
|
|
1319
1311
|
# now key, space, value
|
1320
|
-
newBuf += key
|
1312
|
+
newBuf += Expression.s_write_string_escaped(key, Expression.s_wexpr_value_string_properties(key))
|
1321
1313
|
newBuf += " "
|
1322
1314
|
|
1323
1315
|
newBuf = value.p_append_string_representation_to_buffer(flags, indent, newBuf)
|
data/lib/wexpr/version.rb
CHANGED
data/lib/wexpr.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require_relative 'wexpr/exception'
|
2
|
+
require_relative 'wexpr/expression'
|
3
|
+
require_relative 'wexpr/object_ext'
|
4
|
+
require_relative 'wexpr/uvlq64'
|
5
|
+
require_relative 'wexpr/version'
|
6
6
|
|
7
7
|
#
|
8
8
|
# Ruby-Wexpr library
|
@@ -21,12 +21,16 @@ module Wexpr
|
|
21
21
|
|
22
22
|
#
|
23
23
|
# Emit a hash as the equivilant wexpr string, human readable or not.
|
24
|
-
# See possible writeflags in Expression.
|
24
|
+
# See possible writeflags in Expression. We also support :returnAsExpression which will return the expression, and not the string (for internal use).
|
25
25
|
#
|
26
26
|
def self.dump(variable, writeFlags=[])
|
27
27
|
# first step, go through the variable and create the equivilant wexpr expressions
|
28
28
|
expr = Expression::create_from_ruby(variable)
|
29
29
|
|
30
|
+
if writeFlags.include? :returnAsExpression
|
31
|
+
return expr
|
32
|
+
end
|
33
|
+
|
30
34
|
# then have it write out the string
|
31
35
|
return expr.create_string_representation(0, writeFlags)
|
32
36
|
end
|
data/wexpr.gemspec
CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.require_paths = ["lib"]
|
35
35
|
|
36
36
|
spec.add_development_dependency "bundler", "~> 1.16"
|
37
|
-
spec.add_development_dependency "rake", "~>
|
37
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
38
38
|
spec.add_development_dependency "minitest", "~> 5.0"
|
39
39
|
|
40
40
|
spec.required_ruby_version = '>= 2.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wexpr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenneth Perry (thothonegan)
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '12.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '12.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.7.3
|
102
|
+
rubygems_version: 2.7.6.3
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: Wexpr parser and emitter for ruby
|