jashkenas / jashkenas/coffeescript

Proposal: YAML-like structure syntax

Open
#4,952 30 comments 12 reactions 0 assignees View on GitHub
enhancement
Dominant language
CoffeeScript
Stars
16.6k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

_From @YamiOdymel on [2016-12-10 10:16](https://github.com/coffeescript6/discuss/issues/59)_

I still don't see why can't we use YAML-like syntax after read three of the issue which mentioned below, and I also feel that `{`, `}` and `[`, `]` are the most un-CoffeeScript syntaxes (Not _indent_ enough).

So instead of having (*CoffeeScript*)
```coffeescript
kids = sister:
name : 'Ida'
age : 9
parents: [
{
name : 'Caris'
relation: 'xxx'
}
{
name : 'Mike'
relation: 'xxx'
}
]
```

can we have RAML-like syntax like this?

```coffeescript
kids = sister:
name : 'Ida'
age : 9
parents:
- name : 'Caris'
relation: 'xxx'
- name : 'Mike'
relation: 'xxx'

```

and both compile to

```javascript
var kids =
{
sister:
{
name : "Ida",
age : 9,
parents:
[
{ name: 'Caris', relation: 'xxx' },
{ name: 'Mike' , relation: 'xxx' }
]
}
};
```

---

# More Examples

## Types

CoffeeScript

```coffeescript
types = [
-1
'2'
0.3
->
alert 'foo, bar'
helloFunc
]
```

YAML-like (_the CoffeeScript one might be better than this_)

```coffeescript
types =
- -1
- "2"
- 0.3
- ->
alert "foo, bar"
- helloFunc
```

JavaScript

```javascript
var types =
[
-1,
"2",
0.3,
function()
{
alert("foo, bar")
},
helloFunc
]
```

# Large structure

CoffeeScript

```coffeescript
objs = [ {
username: 'YamiOdymel'
nickname: 'yamiodymel'
avatar :
small: 'http://www.example.com/example.png-small'
medium: 'http://www.example.com/example.png-medium'
large: 'http://www.example.com/example.png-large'
hobbies:
most: [
'tech'
'sport'
'eco'
]
medium: [
'animals'
'music'
]
lowest: [ 'science' ]
} ]
```

YAML-like

```coffeescript
objs =
- username: 'YamiOdymel'
nickname: 'yamiodymel'
avatar:
small : 'http://www.example.com/example.png-small'
medium: 'http://www.example.com/example.png-medium'
large : 'http://www.example.com/example.png-large'
hobbies:
most:
- 'tech'
- 'sport'
- 'eco'
medium:
- 'animals'
- 'music'
lowest:
- 'science'
```

JavaScript

```javascript
objs =
[
{
username: 'YamiOdymel',
nickname: 'yamiodymel',
avatar:
{
small: 'http://www.example.com/example.png-small',
medium: 'http://www.example.com/example.png-medium',
large: 'http://www.example.com/example.png-large'
},
hobbies:
{
most : ['tech' , 'sport', 'eco'],
medium: ['animals', 'music'],
lowest: ['science']
}
}
]
```

---

# Other ideas

From [Terser array syntax](https://github.com/jashkenas/coffeescript/issues/2259)

```coffeescript
array = []
{}
key: value
bla: da
{}
key: value2
bla: doom
```

```coffeescript
foo :[]
'hooray'
'no closing character'
```

---

[Better support for YAML-like syntax](https://github.com/jashkenas/coffeescript/issues/645)
[Enhancement: possible solution to the Array-Literal-Without-Brackets problem](https://github.com/jashkenas/coffeescript/issues/3426)
[Terser array syntax](https://github.com/jashkenas/coffeescript/issues/2259)

Contributor guide

Open the contributing guide

Research direction

No source files, tests, or entry points are named. Start by reviewing the linked prior syntax discussions and comparing the proposed YAML-like examples with current parser behavior; completion would require an agreed syntax and defined compiler and test scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.