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

Proposal: YAML-like structure syntax #59

Closed
YamiOdymel opened this issue Dec 10, 2016 · 3 comments
Closed

Proposal: YAML-like structure syntax #59

YamiOdymel opened this issue Dec 10, 2016 · 3 comments

Comments

@YamiOdymel
Copy link

YamiOdymel commented Dec 10, 2016

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

@edemaine
Copy link

edemaine commented Dec 10, 2016

I have on several occasions written CS like

arrayOfObjects = [
  name: 'me' 
  email: '[email protected]'
,
  name: 'you'
  email: '[email protected]'
]

which can get a little hard to read, and sometimes it's hard to find the right outdent level to put the comma (e.g. if this is wrapped in a function call). Having optional - syntax for making array items clearer would be nice for these cases, if it's disambiguatable in the parser.

(This is a YAML and TypeScript feature, but there's still a lot of other stuff in YAML not supported here, e.g. | to write literals. So I wouldn't necessarily call this YAML support, but it's still a nice feature.)

@jituanlin
Copy link

Nice features!I support it.

@coffeescriptbot coffeescriptbot changed the title YAML-like structure syntax CS2 Discussion: Features: YAML-like structure syntax Feb 19, 2018
@coffeescriptbot coffeescriptbot changed the title CS2 Discussion: Features: YAML-like structure syntax Proposal: YAML-like structure syntax Feb 19, 2018
@coffeescriptbot
Copy link
Collaborator

Migrated to jashkenas/coffeescript#4952

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants