Guidance: Nested indexer [] within flow sequence #423
-
Is there any way to easily extend the parsing of flow sequence entries to allow values which contain the indexer [] characters? The requirement is simply to provide a string-type value in yaml, which is parsed in and ultimately passed to https://lodash.com/docs/#get to resolve a value within a particular object.
The second parse
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Short answer: not really, because the latter "required syntax" is not valid YAML. Within flow collections, plain scalars cannot contain They're fine is a block collection though: YAML.parse(`
args:
- $variable[0]
- 100
`)
// { args: [ '$variable[0]', 100 ] } |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply! I had figured out that the block collection works but the flow syntax is preferred.
Is there perhaps a way for me to add support somehow to meet a requirement, even if not technically valid yaml? Perhaps a custom tag could handle an entry when starting with $ or handle processing of args? 🙂
…________________________________
From: Eemeli Aro ***@***.***>
Sent: Saturday, November 12, 2022 12:48:30 AM
To: eemeli/yaml ***@***.***>
Cc: Frank Bell ***@***.***>; Author ***@***.***>
Subject: Re: [eemeli/yaml] Guidance: Nested indexer [] within flow sequence (Discussion #423)
Short answer: not really, because the latter "required syntax" is not valid YAML.
Within flow collections, plain scalars cannot contain [] or {} characters: https://yaml.org/spec/1.2.2/#733-plain-style
They're fine is a block collection though:
YAML.parse(`
args:
- $variable[0]
- 100
`)
// { args: [ '$variable[0]', 100 ] }
—
Reply to this email directly, view it on GitHub<#423 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AORABCW7JSYSTTU32VUONLTWH3SN5ANCNFSM6AAAAAAR5XZRUQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I see, thank you.
It seems the only way then would be if the lexer was somehow tolerant of nested [ ], perhaps by using a stack to track corresponding opening and closing brackets, but as you point out is invalid yaml.
…________________________________
From: Eemeli Aro ***@***.***>
Sent: Saturday, November 12, 2022 12:35:49 PM
To: eemeli/yaml ***@***.***>
Cc: Frank Bell ***@***.***>; Author ***@***.***>
Subject: Re: [eemeli/yaml] Guidance: Nested indexer [] within flow sequence (Discussion #423)
Not really, because this already happens in the lexer, and your input is ambiguous. Consider what happens here:
args: [ $variable[0], 100 ]
^
If [] were allowed in scalar flow values, how could we know at that point whether the outer [...] collection was being closed or not?
—
Reply to this email directly, view it on GitHub<#423 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AORABCS3JK7PGNFWR2W5YODWH6FKLANCNFSM6AAAAAAR5XZRUQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Short answer: not really, because the latter "required syntax" is not valid YAML.
Within flow collections, plain scalars cannot contain
[]
or{}
characters: https://yaml.org/spec/1.2.2/#733-plain-styleThey're fine is a block collection though: