Skip to content

RFC: Anchors, References, Extend #51

@f3l1x

Description

@f3l1x

Prologue

I'd like to propose a new NEON features. I named them anchors, references, extend. It basically came from YAML (https://en.wikipedia.org/wiki/YAML#Syntax, https://blog.daemonl.com/2016/02/yaml.html).

When you are using NEON in nette-like applications, you are probably using it for service definitions. I consider current syntax as complete and don't miss anything.

However, when you are using NEON as standalone tool for some kind of definition schema, I found myself to miss some features like extending and referencing. I have 1000+ rows in one NEON file and DRY principle comes very handy in here.

Anchors & References

YAML

foo: &anchor
 K1: "One"
 K2: "Two"

bar: *anchor

Result

{
    "foo": {
        "K1": "One",
        "K2": "Two"
    },
    "bar": {
        "K1": "One",
        "K2": "Two"
    }
}

NEON

# A
foo: &anchor
bar: *anchor

# B
foo: &(anchor)
bar: $(anchor)

# C
foo: =$(anchor)
bar: $(anchor)

& and * has no special meaning in NEON, am I right?

Extending

YAML

foo: &anchor
  K1: "One"
  K2: "Two"

bar:
  <<: *anchor
  K2: "I Changed"
  K3: "Three"

Result

{
    "foo": {
        "K1": "One",
        "K2": "Two"
    },
    "bar": {
        "K1": "One",
        "K2": "I Changed",
        "K3": "Three"
    }
}

NEON

# A
foo: # depends on anchor 
bar: <<$anchor

# B
foo: # depends on anchor
bar: ...$anchor

It's an idea of adding extra features to NEON. Maybe someone think the same way. Thanks for a feedback.


List of resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions