Skip to content

Commit 3cf80d7

Browse files
committed
disable empty hash
1 parent efc289e commit 3cf80d7

File tree

5 files changed

+24
-33
lines changed

5 files changed

+24
-33
lines changed

EDGE_CASES.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
In designing any language it's interesting to see what conflicts arise based on combinations you hadn't thought of. Here are some.
22

3+
## Empty Hash
4+
35
foo := {}
46

57
Is this an empty function definition, or is foo returning an empty hash?
6-
It's ambiguous, here's how I decided to define it.
8+
These are more clear:
79

8-
"foo := {}" `matches` "function foo() {\n}",
9-
"foo := return {}" `matches` "function foo() {\n return [];\n}",
10-
"foo := { {} }" `matches` "function foo() {\n return [];\n}"
10+
foo:= return {}
11+
foo:= { {} }
1112

1213
Similarly,
1314

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,16 @@ becomes
203203

204204
```
205205
$a = [
206-
foo => 1,
207-
bar => 2,
208-
baz => "hi"
206+
"foo" => 1,
207+
"bar" => 2,
208+
"baz" => "hi"
209209
]
210210
```
211211

212212
Trailing comma is optional.
213213

214+
Note empty hash `{}` is not allowed, you need to make it like this: `[]`. See EDGE_CASES.md for an explanation of why.
215+
214216
## Dot notation
215217

216218
```

src/Parser.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ saltyParserSingleWithoutNewline = do
9595
parens
9696
<||> hashTable
9797
<||> array
98-
<||> emptyHash
98+
-- <||> emptyHash
9999
<||> (braces Nothing)
100100
<||> function
101101
<||> functionTypeSignature
@@ -138,7 +138,7 @@ validFuncArgTypes :: SaltyParser
138138
validFuncArgTypes = debug "validFuncArgTypes" >> do
139139
hashTable
140140
<||> array
141-
<||> emptyHash
141+
-- <||> emptyHash
142142
<||> operation
143143
<||> partialOperation
144144
<||> saltyString
@@ -196,7 +196,7 @@ validHashValue = debug "validHashValue" >> do
196196
<||> hashLookup
197197
<||> hashTable
198198
<||> array
199-
<||> emptyHash
199+
-- <||> emptyHash
200200
<||> flagName
201201
<||> saltyBool
202202
<||> saltyNull

test.salt

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
$a = 0;
2-
$b = '0';
3-
$c = '1';
4-
$d = '1';
5-
6-
// assert throws a warning if its argument is not true
7-
8-
// These comparisons will always be true, even if the types aren't the same.
9-
assert($a == $b); // equality
10-
assert($c != $a); // inequality
11-
assert($c <> $a); // alternative inequality
12-
assert($a < $c);
13-
assert($c > $b);
14-
assert($a <= $b);
15-
assert($c >= $d);
16-
1+
{ a: 1,
2+
b: 2
3+
}

test/Spec.hs

+8-7
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,16 @@ transpileTests = [
340340
"$foo = 1;\n$bar = 2;" `matches` "$foo = 1;\n$bar = 2;",
341341

342342
-- backticks for php
343-
"'foo' ++ `'bar' . 'baz'`" `matches` "\"foo\" . 'bar' . 'baz';",
343+
"'foo' ++ `'bar' . 'baz'`" `matches` "\"foo\" . 'bar' . 'baz';"
344344

345345
-- empty hash
346-
"{}" `matches` "[];",
347-
"foo = {}" `matches` "$foo = [];",
348-
"a, b, foo = {}" `matches` "$a = [];\n$b = [];\n$foo = [];",
349-
"foo := {}" `matches` "function foo() {\n}",
350-
"foo := return {}" `matches` "function foo() {\n return [];\n}",
351-
"foo := { {} }" `matches` "function foo() {\n return [];\n}"
346+
-- disabling this feature since the syntax becomes ambiguous
347+
-- "{}" `matches` "[];",
348+
-- "foo = {}" `matches` "$foo = [];",
349+
-- "a, b, foo = {}" `matches` "$a = [];\n$b = [];\n$foo = [];",
350+
-- "foo := {}" `matches` "function foo() {\n}",
351+
-- "foo := return {}" `matches` "function foo() {\n return [];\n}",
352+
-- "foo := { {} }" `matches` "function foo() {\n return [];\n}"
352353

353354
-- unsure what to do with this
354355
-- "if 1 == 1 then {}" `matches` ""

0 commit comments

Comments
 (0)