Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 54 additions & 15 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Keys do not require quotes around them. Unquoted keys can consist of any UTF-8 c
- [Whitespace](#whitespace)
- `.` full stop (period)
- `=` equals
- `[ ]` square brackets
- `{ }` braces
- `'` single quote
- `"` double quote

Optionally, a key can be surrounded by single quotes `'`. This removes all of the above limitations.

Expand Down Expand Up @@ -101,6 +105,8 @@ This results in the following JSON output:
}
```

#### Escaping

The following standard escape characters are supported:

- `\\` backslash
Expand All @@ -113,11 +119,12 @@ The following standard escape characters are supported:
{ foo = "hello\nworld" }
```

You can also include any Unicode character using an `\uXXXX` escape code.
`XXXX` must be replaced with exactly 4 hexadecimal digits.
You can also include any Unicode character using an `\u{XXXX}` escape code.
`XXXX` must be replaced with 1–6 (inclusive) hexadecimal digits.
Alphabetic characters are case-insensitive.

```corn
{ foo = "\u2603" }
{ foo = "\u{0061}" }
```

### Integer
Expand All @@ -138,6 +145,24 @@ Underscores cannot be the first or last characters in a value.
}
```

Four bases are supported:

- Decimal, with no prefix.
- Hexadecimal, using a `0x` prefix.
- Octal, using a `0o` prefix.
- Binary, using a `0b` prefix.

```corn
{
dec = 10
hex = 0x1a
oct = 0o77
bin = 0b101010
}
```

Each base supports the same pos/neg sign and underscore rules.

### Float

Floats are double-precision (64-bit).
Expand Down Expand Up @@ -318,14 +343,16 @@ this is handled as an undeclared input.

Inputs with values of type [string](#object) can be interpolated inside string values.

The input is referenced in the standard manner within the double quotes `""`, and standard input reference rules apply.
The input is referenced using a `${name}` syntax within the double quotes `""`.
The standard input reference syntax `$name` is invalid for interpolation.
Standard input reference rules apply.

```corn
let {
$subject = "world"
} in {
// evaluates as "hello, world"
greeting = "hello, $subject"
greeting = "hello, ${subject}"
}
```

Expand All @@ -334,12 +361,13 @@ the dollar should be prefixed with a backslash `\`.

```corn
{
// evaluates as "hello, $subject"
greeting = "hello, \$subject"
// evaluates as "hello, ${subject}"
greeting = "hello, \${subject}"
}
```

Non-string input types are not supported.
Interpolation of both string and integer types is supported.
Interpolation of other types is invalid.

### Object merging

Expand Down Expand Up @@ -460,7 +488,7 @@ The following characters are valid whitespace:

Any quantity or combination of the above characters is permitted, so long as it abides by the rules described below.

Whitespace is almost entirely optional. It is required in the following places only:
Whitespace abides by fairly standard rules. It is required in the following places only:

- When an integer or float follows another integer or float, whitespace must be included between them:

Expand All @@ -486,7 +514,7 @@ Whitespace is almost entirely optional. It is required in the following places o
}
```

- When a value is followed by a key, whitespace must be included between them.
- When a key follows a value, whitespace must be included between them.

```corn
{
Expand All @@ -497,6 +525,18 @@ Whitespace is almost entirely optional. It is required in the following places o
foo = 4bar = 4
}
```

- When a literal token follows another literal token, whitespace must be included between them.

```corn
{
// valid, tokens are separated by whitespace
foo = [ true false ]

// invalid, tokens are not separated by whitespace
foo = [truefalse]
}
```

Whitespace cannot exist inside key or value tokens, unless part of whitespace inside a string literal:

Expand All @@ -513,7 +553,7 @@ Whitespace cannot exist inside key or value tokens, unless part of whitespace in
}
```

Based on these rules, Corn supports a very compact syntax. The following is entirely valid:
The following "condensed" example is valid:

```corn
{
Expand All @@ -524,10 +564,9 @@ Based on these rules, Corn supports a very compact syntax. The following is enti
five={foo=null bar=null}
six={foo={} bar={}}
seven={foo=[] bar=[]}

eight=["foo""bar"]
nine=[truefalse]
ten=[nullnull]
nine=[true false]
ten=[null null]
eleven=[[][]]
twelve=[{}{}]
}
Expand All @@ -536,7 +575,7 @@ Based on these rules, Corn supports a very compact syntax. The following is enti
And since newlines and indentation are optional too, this can be condensed further into:

```corn
{one={foo="bar" bar="foo"} two={foo=1 bar=2} three={foo=1.0 bar=2.0} four={foo=true bar=false} five={foo=null bar=null} six={foo={} bar={}} seven={foo=[] bar=[]} eight=["foo""bar"] nine=[truefalse] ten=[nullnull] eleven=[[][]] twelve=[{}{}]}
{one={foo="bar" bar="foo"} two={foo=1 bar=2} three={foo=1.0 bar=2.0} four={foo=true bar=false} five={foo=null bar=null} six={foo={} bar={}} seven={foo=[] bar=[]} eight=["foo""bar"] nine=[true false] ten=[null null] eleven=[[][]] twelve=[{}{}]}
```

Writing Corn in the style of the above two examples is not recommended.
Expand Down