nydp 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lisp/boot.nydp +16 -7
- data/lib/lisp/tests/boot-tests.nydp +5 -0
- data/lib/lisp/tests/parser-tests.nydp +19 -1
- data/lib/nydp/builtin/to_string.rb +9 -10
- data/lib/nydp/core.rb +1 -1
- data/lib/nydp/helper.rb +2 -0
- data/lib/nydp/parser.rb +3 -2
- data/lib/nydp/string_atom.rb +1 -0
- data/lib/nydp/tokeniser.rb +18 -4
- data/lib/nydp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5371b4420aa7a746eccbe2b573c4272d7dfba14
|
4
|
+
data.tar.gz: a3984911b5b429111b2d05edfb0dbe8e7255f09b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f34a901a9f99c8225bbe8b4301d7399e6cde7b54f10d8d46d22763309271ab8baaea9829de021ab0d35eaaf949a45ff805795b29ad6ea5d44595f4f4fea4ff5
|
7
|
+
data.tar.gz: 00f4189ec6bbeeb721b3431a59bb6bc819f239eaecd499f49ba38b49f42d29ffc8609b3cd370eb976a6897cccc4442c97b94457eed6cede53cf72db09fe85f54
|
data/lib/lisp/boot.nydp
CHANGED
@@ -235,6 +235,9 @@
|
|
235
235
|
(flatten (zip (map (fn (_) txt) (cdr joinables))
|
236
236
|
(map to-string (cdr joinables)))))))
|
237
237
|
|
238
|
+
(def string-pieces pieces
|
239
|
+
(joinstr "" pieces))
|
240
|
+
|
238
241
|
(let uniq-counter 0
|
239
242
|
(def uniq (prefix)
|
240
243
|
(sym (joinstr "-"
|
@@ -274,18 +277,19 @@
|
|
274
277
|
(iso (car x) (car y))
|
275
278
|
(iso (cdr x) (cdr y)))))
|
276
279
|
|
277
|
-
(def isa
|
278
|
-
(def sym?
|
279
|
-
(
|
280
|
-
(
|
280
|
+
(def isa (type obj) (eq? (type-of obj) type))
|
281
|
+
(def sym? (arg) (isa 'symbol arg))
|
282
|
+
(def string? (arg) (isa 'string arg))
|
283
|
+
(mac just (arg) arg)
|
284
|
+
(def quotify (arg) `(quote ,arg))
|
281
285
|
|
282
286
|
(def caris (obj things)
|
283
287
|
(and (isa 'pair things)
|
284
288
|
(eq? (car things) obj)))
|
285
289
|
|
286
290
|
(def len (xs)
|
287
|
-
(if (pair? xs)
|
288
|
-
(
|
291
|
+
(if (pair? xs) (+ 1 (len (cdr xs)))
|
292
|
+
(string? xs) (string-length xs)
|
289
293
|
0))
|
290
294
|
|
291
295
|
(def build-keyword-args (pairs)
|
@@ -316,6 +320,9 @@
|
|
316
320
|
(build-hash-getters (cdr names) `(hash-get ,acc ',(car names)))
|
317
321
|
acc))
|
318
322
|
|
323
|
+
(def build-hash-lookup-from (root names)
|
324
|
+
(build-hash-getters (cons root names) nil))
|
325
|
+
|
319
326
|
(mac hash-lookup (names)
|
320
327
|
(build-hash-getters names nil))
|
321
328
|
|
@@ -345,9 +352,11 @@
|
|
345
352
|
,@(map (fn (m) `(hash-set ,hash ,(brace-list-hash-key (car m)) ,(cadr m))) mappings)
|
346
353
|
,hash))))
|
347
354
|
|
355
|
+
(mac brace-list-mono (arg) arg)
|
356
|
+
|
348
357
|
(mac brace-list args
|
349
358
|
(if (no (cdr args))
|
350
|
-
(car args)
|
359
|
+
`(brace-list-mono ,(car args))
|
351
360
|
(brace-list-build-hash args)))
|
352
361
|
|
353
362
|
(mac on-err (handler . body)
|
@@ -53,6 +53,11 @@
|
|
53
53
|
(list "hello world" (hash-get hsh "hello world") "yesterday" (hash-get hsh "yesterday"))))
|
54
54
|
("hello world" 10 "yesterday" 11)))
|
55
55
|
|
56
|
+
(suite "strings"
|
57
|
+
("length"
|
58
|
+
(len "foo-bar")
|
59
|
+
7))
|
60
|
+
|
56
61
|
(suite "list management"
|
57
62
|
("'pair breaks a list into pairs"
|
58
63
|
(pairs '(1 a 2 b 3 c))
|
@@ -52,4 +52,22 @@
|
|
52
52
|
|
53
53
|
("parses a plain string with interpolations"
|
54
54
|
(parse-in-string (joinstr "" (list "hello, " '~ "(world), take me to your " '~ "dealer please")))
|
55
|
-
(string-pieces "hello, " (world) ", take me to your " dealer " please"))
|
55
|
+
(string-pieces "hello, " (world) ", take me to your " dealer " please"))
|
56
|
+
|
57
|
+
("ignores standalone interpolation symbol"
|
58
|
+
(parse-in-string (joinstr "" (list "hello " '~ " world")))
|
59
|
+
"hello \~ world")
|
60
|
+
|
61
|
+
("ignores backslash-escaped interpolation symbol"
|
62
|
+
(len "hello \~world")
|
63
|
+
12)
|
64
|
+
|
65
|
+
("ignores escaped interpolation symbol"
|
66
|
+
(parse-in-string (joinstr "" (list "hello " '~ '~ "world")))
|
67
|
+
"hello \~world")
|
68
|
+
|
69
|
+
("really ignores standalone interpolation symbol"
|
70
|
+
(len (parse-in-string (joinstr "" (list "hello " '~ " world"))))
|
71
|
+
13)
|
72
|
+
|
73
|
+
)))
|
@@ -11,16 +11,15 @@ class Nydp::Builtin::ToString
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
class Nydp::Builtin::
|
15
|
-
def to_string first, rest
|
16
|
-
if Nydp.NIL.is? rest
|
17
|
-
first.to_s
|
18
|
-
else
|
19
|
-
"#{first.to_s}#{to_string rest.car, rest.cdr}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
14
|
+
class Nydp::Builtin::StringLength
|
23
15
|
def invoke vm, args
|
24
|
-
|
16
|
+
arg = args.car
|
17
|
+
val = case arg
|
18
|
+
when Nydp::StringAtom
|
19
|
+
arg.length
|
20
|
+
else
|
21
|
+
0
|
22
|
+
end
|
23
|
+
vm.push_arg val
|
25
24
|
end
|
26
25
|
end
|
data/lib/nydp/core.rb
CHANGED
@@ -53,7 +53,7 @@ module Nydp
|
|
53
53
|
Symbol.mk("parse-in-string", ns).assign(Nydp::Builtin::ParseInString.new(ns))
|
54
54
|
Symbol.mk("random-string" , ns).assign(Nydp::Builtin::RandomString.new)
|
55
55
|
Symbol.mk("to-string" , ns).assign(Nydp::Builtin::ToString.new)
|
56
|
-
Symbol.mk("string-
|
56
|
+
Symbol.mk("string-length" , ns).assign(Nydp::Builtin::StringLength.new)
|
57
57
|
Symbol.mk("string-replace" , ns).assign(Nydp::Builtin::StringReplace.new)
|
58
58
|
Symbol.mk("string-split" , ns).assign(Nydp::Builtin::StringSplit.new )
|
59
59
|
Symbol.mk("thread-locals" , ns).assign(Nydp::Builtin::ThreadLocals.new)
|
data/lib/nydp/helper.rb
CHANGED
data/lib/nydp/parser.rb
CHANGED
@@ -113,14 +113,15 @@ module Nydp
|
|
113
113
|
end
|
114
114
|
|
115
115
|
INTERPOLATION_SIGN = /~/
|
116
|
+
INTERPOLATION_ESCAPES = { /~\s/ => true, /~~/ => "~" }
|
116
117
|
|
117
118
|
def string token_stream, open_delimiter, close_delimiter
|
118
119
|
fragments = [sym(:"string-pieces")]
|
119
|
-
string_token = token_stream.next_string_fragment(open_delimiter, close_delimiter, INTERPOLATION_SIGN)
|
120
|
+
string_token = token_stream.next_string_fragment(open_delimiter, close_delimiter, INTERPOLATION_SIGN, INTERPOLATION_ESCAPES)
|
120
121
|
fragments << Nydp::StringAtom.new(string_token.string, string_token)
|
121
122
|
while !(string_token.is_a? StringFragmentCloseToken)
|
122
123
|
fragments << expression(token_stream)
|
123
|
-
string_token = token_stream.next_string_fragment('', close_delimiter, INTERPOLATION_SIGN)
|
124
|
+
string_token = token_stream.next_string_fragment('', close_delimiter, INTERPOLATION_SIGN, INTERPOLATION_ESCAPES)
|
124
125
|
fragments << Nydp::StringAtom.new(string_token.string, string_token)
|
125
126
|
end
|
126
127
|
|
data/lib/nydp/string_atom.rb
CHANGED
data/lib/nydp/tokeniser.rb
CHANGED
@@ -25,7 +25,7 @@ module Nydp
|
|
25
25
|
scanner.scan(delim)
|
26
26
|
end
|
27
27
|
|
28
|
-
def next_string_fragment open_delimiter, close_delimiter, interpolation_sign
|
28
|
+
def next_string_fragment open_delimiter, close_delimiter, interpolation_sign, interpolation_escapes={ }
|
29
29
|
s = @scanner
|
30
30
|
rep = "#{open_delimiter}"
|
31
31
|
string = ""
|
@@ -42,9 +42,23 @@ module Nydp
|
|
42
42
|
elsif closer = close_delimiter?(s, close_delimiter)
|
43
43
|
rep << closer
|
44
44
|
return StringFragmentCloseToken.new(string, rep)
|
45
|
-
elsif interpolation_sign
|
46
|
-
|
47
|
-
|
45
|
+
elsif interpolation_sign
|
46
|
+
escaped = false
|
47
|
+
interpolation_escapes.each do |esc, repl|
|
48
|
+
if !escaped && (escape = s.scan esc)
|
49
|
+
string << ((repl == true) ? escape : repl)
|
50
|
+
rep << escape
|
51
|
+
escaped = true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
if !escaped && (start_interpolation = s.scan(interpolation_sign))
|
55
|
+
rep << start_interpolation
|
56
|
+
return StringFragmentToken.new(string, rep)
|
57
|
+
else
|
58
|
+
ch = s.getch
|
59
|
+
string << ch
|
60
|
+
rep << ch
|
61
|
+
end
|
48
62
|
else
|
49
63
|
ch = s.getch
|
50
64
|
string << ch
|
data/lib/nydp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nydp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Conan Dalton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|