Skip to content

Commit 577319d

Browse files
committed
core: Remove support for '-' escaping
Only support '+' escaping now.
1 parent 72507e0 commit 577319d

13 files changed

Lines changed: 93 additions & 126 deletions

File tree

core/src/yamlscript/resolver.clj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,16 @@
247247
(defn resolve-code-sequence [_]
248248
(die "Sequences (block and flow) not allowed in code mode"))
249249

250-
(def esc1 #"^\+\ *[\`\!\@\#\%\&\*\-\{\[\|\:\'\"\,\?\>]")
251-
(def esc2 #"^-[\`\!\@\#\%\&\*\-\{\[\|\:\'\"\,\?]")
250+
(def esc #"^\+\ *[\`\!\@\#\%\&\*\-\{\[\|\:\'\"\,\?\>]")
252251
(defn resolve-code-scalar [node type style]
253252
(if type
254253
(set/rename-keys node {style type})
255254
(let [val (style node)]
256255
(case style
257-
:= (let [node ;; Remove leading escape character from value
258-
(if (or (re-find esc1 val) (re-find esc2 val))
259-
(assoc node := (subs val 1))
260-
node)]
256+
:= (let [ ;; Remove leading escape character from value
257+
node (if (re-find esc val)
258+
(assoc node := (subs val 1))
259+
node)]
261260
(set/rename-keys node {style :expr}))
262261
:$ (set/rename-keys node {style :xstr})
263262
:' (set/rename-keys node {style :str})

core/test/compiler-stack.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,29 +124,29 @@
124124
(a b c)
125125
126126
127-
- name: Dot escaping
127+
- name: Plus escaping
128128
yamlscript: |
129129
--- !yamlscript/v0
130-
map inc: -[2 4 6 8]
130+
map inc: +[2 4 6 8]
131131
parse: |
132132
"+MAP", :! "yamlscript/v0"
133133
"=VAL", := "map inc"
134-
"=VAL", := "-[2 4 6 8]"
134+
"=VAL", := "+[2 4 6 8]"
135135
"-MAP"
136136
compose: |
137137
{:+ "code" :% [
138138
{:= "map inc"}
139-
{:= "-[2 4 6 8]"} ]}
139+
{:= "+[2 4 6 8]"} ]}
140140
print: |
141141
(map inc [2 4 6 8])
142142
143143
144144
- name: YS reader forms
145145
yamlscript: |
146146
--- !yamlscript/v0
147-
prn: -["str" \\c 42 foo true false nil]
148-
prn: -{:a 1 :c 2 :b 3}
149-
prn: -"A longer string"
147+
prn: +["str" \\c 42 foo true false nil]
148+
prn: +{:a 1 :c 2 :b 3}
149+
prn: +"A longer string"
150150
build: |
151151
{:xmap [
152152
{:Sym prn}
@@ -477,7 +477,7 @@
477477
- name: Support default fn arguments
478478
yamlscript: |
479479
!yamlscript/v0
480-
defn foo(a b=42 c="OK"): -[c b a]
480+
defn foo(a b=42 c="OK"): +[c b a]
481481
build: |
482482
{:xmap
483483
[[{:Sym defn} {:Sym foo} nil]
@@ -516,7 +516,7 @@
516516
- name: All args have defaults
517517
yamlscript: |
518518
!yamlscript/v0
519-
defn foo(a=1 b=2 c=3): -[c b a]
519+
defn foo(a=1 b=2 c=3): +[c b a]
520520
print: |
521521
(defn
522522
foo
@@ -1418,7 +1418,7 @@
14181418
!yamlscript/v0:
14191419
- 0
14201420
- 1
1421-
- :: -[2 3 4]
1421+
- :: +[2 3 4]
14221422
- 5
14231423
- 5
14241424
- ::: [6, 7, 8]
@@ -1432,7 +1432,7 @@
14321432
yamlscript: |
14331433
!yamlscript/v0:
14341434
- 1
1435-
- :when x: -[2 3 4]
1435+
- :when x: +[2 3 4]
14361436
- :when y:: [6, 7, 8]
14371437
- 9
14381438
clojure: |
@@ -1442,7 +1442,7 @@
14421442
- name: Single '::' in a data mode sequence
14431443
yamlscript: |
14441444
!yamlscript/v0:
1445-
- :when x: -[2 3 4]
1445+
- :when x: +[2 3 4]
14461446
clojure: |
14471447
(concat (when x [2 3 4]))
14481448
@@ -1451,7 +1451,7 @@
14511451
yamlscript: |
14521452
!yamlscript/v0:
14531453
a: 1
1454-
:when x: -{'b' 2}
1454+
:when x: +{'b' 2}
14551455
:when y:: {c: 3}
14561456
d: 4
14571457
clojure: |

core/test/compiler.yaml

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@
644644
- name: Single quoted string
645645
yamlscript: |
646646
!yamlscript/v0
647-
say: -"123" + ' let''s go'
647+
say: +"123" + ' let''s go'
648648
say: '123 let''s go'
649649
clojure: |
650650
(say (add+ "123" " let's go"))
@@ -683,7 +683,7 @@
683683
- name: Floating point numbers
684684
yamlscript: |
685685
!yamlscript/v0
686-
=>: -[ -0.00 0.1 -1.2e3 2.3e-4 ]
686+
=>: +[ -0.00 0.1 -1.2e3 2.3e-4 ]
687687
clojure: |
688688
[-0.0 0.1 -1200.0 2.3E-4]
689689
@@ -732,8 +732,8 @@
732732
yamlscript: |
733733
!yamlscript/v0
734734
defn foo():
735-
-[a b c] =: -[1 2 3]
736-
-{:d d :e e} =: -{:d 4 :e 5}
735+
+[a b c] =: +[1 2 3]
736+
+{:d d :e e} =: +{:d 4 :e 5}
737737
=>: a + b + c
738738
clojure: |
739739
(defn
@@ -745,7 +745,7 @@
745745
- name: Destructuring def
746746
yamlscript: |
747747
!yamlscript/v0
748-
-[a b c] =: -[1 2 3]
748+
+[a b c] =: +[1 2 3]
749749
clojure: |
750750
(+def [a b c] [1 2 3])
751751
@@ -833,7 +833,7 @@
833833
- name: Dot groupings in vectors
834834
yamlscript: |
835835
!yamlscript/v0
836-
=>: -[a.3.b(x.y), c.4.d]
836+
=>: +[a.3.b(x.y), c.4.d]
837837
clojure: |
838838
[(b (get+ a 3) (get+ x 'y)) (get+ (get+ c 4) 'd)]
839839
@@ -871,47 +871,15 @@
871871
{"bar" 44}
872872
873873
874-
- name: Plus minus escaping of YAML syntax
874+
- name: Plus escaping of YAML syntax
875875
yamlscript: |
876876
!yamlscript/v0
877-
=>: -'foo' * 3
878-
=>: -"foo" * 3
877+
=>: +'foo' * 3
878+
=>: +"foo" * 3
879879
=>: +[foo] + [bar]
880880
=>: +
881881
{foo 1} + {bar 2}
882-
foo: -|| bar
883-
clojure: |
884-
(mul+ "foo" 3)
885-
(mul+ "foo" 3)
886-
(add+ [foo] [bar])
887-
(add+ {foo 1} {bar 2})
888-
(foo || bar)
889-
890-
891-
- name: Plus escaping of YAML syntax
892-
yamlscript: |
893-
!yamlscript/v0
894-
=>: -'foo' * 3
895-
=>: -"foo" * 3
896-
=>: -[foo] + [bar]
897-
=>: -{foo 1} + {bar 2}
898-
foo: +|| bar
899-
clojure: |
900-
(mul+ "foo" 3)
901-
(mul+ "foo" 3)
902-
(add+ [foo] [bar])
903-
(add+ {foo 1} {bar 2})
904-
(foo || bar)
905-
906-
907-
- name: Plus escaping of YAML syntax
908-
yamlscript: |
909-
!yamlscript/v0
910-
=>: -'foo' * 3
911-
=>: -"foo" * 3
912-
=>: -[foo] + [bar]
913-
=>: -{foo 1} + {bar 2}
914-
foo: +|| bar
882+
foo: + || bar
915883
clojure: |
916884
(mul+ "foo" 3)
917885
(mul+ "foo" 3)
@@ -1184,7 +1152,7 @@
11841152
yamlscript: |
11851153
!yamlscript/v0
11861154
=>: "$1 $foo $2"
1187-
=>: -"$1$foo$2"
1155+
=>: +"$1$foo$2"
11881156
clojure: |
11891157
(str "$1 " foo " $2")
11901158
(str "$1" foo "$2")
@@ -1212,8 +1180,8 @@
12121180
- name: Escape pound and colon in ysexpr strings
12131181
yamlscript: |
12141182
!yamlscript/v0
1215-
say: -'foo \# bar :\ baz'
1216-
say: -"foo \# bar :\ baz"
1183+
say: +'foo \# bar :\ baz'
1184+
say: +"foo \# bar :\ baz"
12171185
clojure: |
12181186
(say "foo # bar : baz")
12191187
(say "foo # bar : baz")
@@ -1415,7 +1383,7 @@
14151383
- name: Seq destruct without []
14161384
yamlscript: |
14171385
!yamlscript/v0
1418-
a b c =: -[1 2 3]
1386+
a b c =: +[1 2 3]
14191387
clojure: |
14201388
(+def [a b c] [1 2 3])
14211389
@@ -1428,8 +1396,8 @@
14281396
=>: a.b.:c:d
14291397
=>: a.5:b
14301398
=>: a(5):b
1431-
=>: -{}:a
1432-
=>: -[]:a
1399+
=>: +{}:a
1400+
=>: +[]:a
14331401
=>: a:b?
14341402
=>: a:b!
14351403
=>: a:b+
@@ -1545,7 +1513,7 @@
15451513
- name: Merge key in data mode
15461514
yamlscript: |
15471515
!yamlscript/v0/data
1548-
<<:: -[{:a 1 :b 2}]
1516+
<<:: +[{:a 1 :b 2}]
15491517
:a: 3
15501518
clojure: |
15511519
(+merge {:-<< [{:a 1, :b 2}], :a 3})
@@ -1566,7 +1534,7 @@
15661534
- name: Tag method call with data mode switch to code mode
15671535
yamlscript: |
15681536
!yamlscript/v0:
1569-
foo: !:merge: -[{:a 1 :b 2} {:a 3}]
1537+
foo: !:merge: +[{:a 1 :b 2} {:a 3}]
15701538
clojure: |
15711539
{"foo" (merge [{:a 1, :b 2} {:a 3}])}
15721540

core/test/runtime.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
=>: "foo"
1111
=>: true
1212
=>: false
13-
=>: -[1 2 3]
14-
=>: -{:a 1 :b 2}
13+
=>: +[1 2 3]
14+
=>: +{:a 1 :b 2}
1515
eval: |
1616
[1 2.3 "foo" true false [1 2 3] {:a 1, :b 2}]
1717
@@ -21,8 +21,8 @@
2121
vector:
2222
=>: 1 + 2
2323
=>: 1 + 2 + 3
24-
=>: -"foo" + "bar"
25-
=>: -[1 2] + [3 4]
24+
=>: +"foo" + "bar"
25+
=>: +[1 2] + [3 4]
2626
eval: |
2727
[3 6 "foobar" (1 2 3 4)]
2828

core/test/transformer.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,6 @@
210210
yamlscript: |
211211
!yamlscript/v0
212212
defn foo():
213-
-[x *y] =: z
213+
+[x *y] =: z
214214
clojure: |
215215
(defn foo [] (let [[x & y] z]))

sample/rosetta-code/hello-world.ys

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ say: 'Hello, world!'
77
=>: say('Hello, world!')
88

99
say:
10-
-'Hello, ' +: 'world!'
10+
+'Hello, ' +: 'world!'
1111

12-
say: -'Hello, ' + 'world!'
12+
say: +'Hello, ' + 'world!'
1313

14-
say: -'Hello,' 'world!'
14+
say: +'Hello,' 'world!'
1515

1616
say 'Hello,': 'world!'
1717

ys/test/cli-usage.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ys::taptest: :all
44

55
VERSION =: '0.2.4'
66

7-
ROOT =: -"$DIR/../.."
7+
ROOT =: +"$DIR/../.."
88

99
HELP =: |
1010

ys/test/dot.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ test::
1313
want: null
1414
- code: nil.foo
1515
want: null
16-
- code: -{}.$NIL
16+
- code: +{}.$NIL
1717
want: null
18-
- code: -[].$NIL
18+
- code: +[].$NIL
1919
want: null
2020
- code: true.foo
2121
want: null
22-
- code: -"foo".foo
22+
- code: +"foo".foo
2323
want: null
2424

2525
- code: (1 .. 20).partition(3 5)

ys/test/operators.t

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ test::
5555
want: AB
5656
- code: (\\A + 2) + 3
5757
want:: \\F
58-
- code: -{:a 1} + {:b 2} + {:c 3}
59-
want:: -{:a 1 :b 2 :c 3}
60-
- code: -'J' + 5
58+
- code: +{:a 1} + {:b 2} + {:c 3}
59+
want:: +{:a 1 :b 2 :c 3}
60+
- code: +'J' + 5
6161
want: J5
62-
- code: -'J' + \\5
62+
- code: +'J' + \\5
6363
want: J5
64-
- code: -'12' + \\3 + 4
64+
- code: +'12' + \\3 + 4
6565
want: "1234"
6666
- code: \{:a :b} + \{:b :c :d}
6767
want:: \{:a :b :c :d}
6868
- name: add+ with hash-maps and array-maps
69-
code: -{:a 1} + {:b 2} + {:c 1 :d 1 :e 1 :f 1 :g 1 :h 1 :i 1 :j 1 :k 1 :l 1}
70-
want:: -{:a 1 :b 2 :c 1 :d 1 :e 1 :f 1 :g 1 :h 1 :i 1 :j 1 :k 1 :l 1}
69+
code: +{:a 1} + {:b 2} + {:c 1 :d 1 :e 1 :f 1 :g 1 :h 1 :i 1 :j 1 :k 1 :l 1}
70+
want:: +{:a 1 :b 2 :c 1 :d 1 :e 1 :f 1 :g 1 :h 1 :i 1 :j 1 :k 1 :l 1}
7171

7272
- note: 'sub+ tests'
7373

@@ -80,7 +80,7 @@ test::
8080
- code: \\A - []
8181
what: error
8282
want: "Can't sub(\\A [])"
83-
- code: -'foobarbazbar' - 'bar'
83+
- code: +'foobarbazbar' - 'bar'
8484
want: foobaz
8585
- code: nil - 2
8686
what: error
@@ -104,7 +104,7 @@ test::
104104
- code: nil.++
105105
what: error
106106
want: "Can't convert a nil value to a number"
107-
- code: -"B".++
107+
- code: +"B".++
108108
what: error
109109
want: 'Can''t inc+("B")'
110110

0 commit comments

Comments
 (0)