YAML-Macros | macro system for YAML files | Code Editor library
kandi X-RAY | YAML-Macros Summary
kandi X-RAY | YAML-Macros Summary
Sublime Text syntax definitions can often have a lot of boilerplate and repeated code. Consider this simple syntax that highlights SQL keywords:.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Run the builder
- Process macros
- Build a build process
- Create yaml instance
- Format string
- Get the resource for a resource
- Returns the path to the data for a given parent_of
- Find files matching a glob pattern
- Searches for all installed sublime - packages in data_path
- Decorator for raw macros
- Replace keywords with underscores
- Merge two dictionaries
- Return yaml instance
- Create a clone of a class
- Expects a match expression
- Returns a dictionary of rule keys
- Apply the extension to the base
- Build a yaml file from input_
- Defines a pop rule
- Define meta rules
- Include a resource
- Include macros
- Apply function to args
- Return the sort key for a given package file
- Extend a yaml file
- Decorator to mark a function as deprecated
- Creates a stack
YAML-Macros Key Features
YAML-Macros Examples and Code Snippets
Community Discussions
Trending Discussions on YAML-Macros
QUESTION
I have a set of YAML files. I would like to cache these files so that as much work as possible is re-used.
Each of these files contains two documents. The first document contains “static” information that will always be interpreted in the same way. The second document contains “dynamic” information that must be reinterpreted every time the file is used. Specifically, it uses a tag-based macro system, and the document must be constructed anew each time the file is used. However, the file itself will not change, so the results of parsing the entire file could be cached (at a considerable resource savings).
In ruamel.yaml, is there a simple way to parse an entire file into multiple parsed documents, then run construction on each document individually? This would allow me to cache the result of constructing the first “static” document and cache the parse of the second “dynamic” document for later construction.
Example file:
...ANSWER
Answered 2019-Jun-05 at 19:29If you don't want to process all YAML documents in a stream completely, you'll have to split up the stream by hand, which is not entirely easy to do in a generic way.
What you need to know is what a YAML stream can consist of:
zero or more documents. Subsequent documents require some sort of separation marker line. If a document is not terminated by a document end marker line, then the following document must begin with a directives end marker line.
A document end marker line is a line that starts with ...
followed by space/newline and a directives end marker line is ---
followed by space/newline.
The actual production rules are slightly more complicated and "starts with" should ignore the fact that you need to skip any mid-stream byte-order marks.
If you don't have any directives, byte-order-marks and no document-end-markers (and most multi-document YAML streams that I have seen, do not have those), then you can just data = Path().read()
the multi-document YAML as a string, split using l = data.split('\n---')
and process only the appropriate element of the resulting list with YAML().load(l[N])
.
I am not sure the following properly handles all cases, but it does handle your multi-doc stream:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install YAML-Macros
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page