Skip to content
This repository was archived by the owner on Feb 19, 2018. It is now read-only.
This repository was archived by the owner on Feb 19, 2018. It is now read-only.

Proposal: YAML-like structure syntax #59

@YamiOdymel

Description

@YamiOdymel

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)

kids = sister:
  name   : 'Ida'
  age    : 9
  parents: [
    {
      name    : 'Caris'
      relation: 'xxx'
    }
    {
      name    : 'Mike'
      relation: 'xxx'
    }
  ]

can we have RAML-like syntax like this?

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

and both compile to

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

More Examples

Types

CoffeeScript

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

YAML-like (the CoffeeScript one might be better than this)

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

JavaScript

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

Large structure

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

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

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

array = []
  {}
    key: value
    bla: da
  {}
    key: value2
    bla: doom
foo :[]
  'hooray'
  'no closing character'

Better support for YAML-like syntax
Enhancement: possible solution to the Array-Literal-Without-Brackets problem
Terser array syntax

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions