{"id":13804518,"url":"https://github.com/jdonnerstag/vlang-yaml","last_synced_at":"2025-05-13T17:32:32.837Z","repository":{"id":42008807,"uuid":"378734683","full_name":"jdonnerstag/vlang-yaml","owner":"jdonnerstag","description":"YAML reader in native Vlang","archived":false,"fork":false,"pushed_at":"2022-04-19T07:31:12.000Z","size":187,"stargazers_count":24,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-18T20:51:24.266Z","etag":null,"topics":["vlang","vlang-module","yaml","yaml-parser"],"latest_commit_sha":null,"homepage":"","language":"V","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jdonnerstag.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-20T20:31:01.000Z","updated_at":"2024-01-05T00:34:35.000Z","dependencies_parsed_at":"2022-09-21T13:31:25.461Z","dependency_job_id":null,"html_url":"https://github.com/jdonnerstag/vlang-yaml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdonnerstag%2Fvlang-yaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdonnerstag%2Fvlang-yaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdonnerstag%2Fvlang-yaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdonnerstag%2Fvlang-yaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdonnerstag","download_url":"https://codeload.github.com/jdonnerstag/vlang-yaml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253993319,"owners_count":21996284,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["vlang","vlang-module","yaml","yaml-parser"],"created_at":"2024-08-04T01:00:49.228Z","updated_at":"2025-05-13T17:32:32.510Z","avatar_url":"https://github.com/jdonnerstag.png","language":"V","funding_links":[],"categories":["Applications"],"sub_categories":["Serialization"],"readme":"# Native YAML support for [V-lang](https://vlang.io)\n\nI think this YAML parser covers many important aspects of the YAML spec, but certainly not everything. I've been using the [YAML spec](https://yaml.org/spec/1.2/spec.html) and [this online tool](https://www.json2yaml.com/) whenever I was in doubt.\n\nThis is an initial version. Please apply some caution and report issues back to me.\n\nSince this is an initial version, it is not yet performance tested. I'm sure there is room for improvements.\n\n\n## Key Features\n\n- Read and parse yaml files (or data blocks); utf-8 only\n- Tokenize the YAML file and derive YAML events (tokens) \n- Convert YAML events to a JSON string (and leverage V's built-in JSON decoder to load json)\n- Load the YAML file into a tree-like structure of dynamic YamlValue's  (V is currently lacking the feature to map (YAML) values to struct variables. The respective JSON logic is build into the compiler. It is not possible for\nusers to define their own [attributes] right now)\n- Value types, such as string, int, float and bool are auto-detected and carried forward\n- Tag definitions and references are mostly supported. By default references get replaced with their definition.\n- Multiple YAML documents within a file is supported (mostly)\n- un-escape and interpolate strings, hex numbers, etc.\n\n\n## Architecture\n\n```\nTextScanner: split text into string tokens (generic)\n    -\u003e Scanner: map into basic yaml-like tokens\n        -\u003e Tokenizer: derive proper yaml tokens (events)\n            -\u003e JSON output: convert into JSON string\n                -\u003e print\n                -\u003e json.decode() V built-in: load into V struct's\n            -\u003e Reader: load into dynamic YamlValue structure\n                -\u003e Accessor: path-like access to tree-like YamlValue structure\n```\n\n**TextScanner**: A generic module, not YAML specific, with re-useable functions to detect newline, handle line count, skip whitespace, move to end-of-line, set a marker at a certain position and retrieve the text between the marker and the current postion, read quoted strings, etc.\n\n**Scanner**: Leverage TextScanner to parse the YAML file into basic YAML tokens, properly determine indentation (very important in YAML), the different multi-line text variants, identify special chars such as `-:{}[],!---...`, etc. The token generated consist of a type, the indentiation level and the associated string.\n\n**Tokenizer**: What we really want are YAML events such as start-list, close, start-object, key, value, end-of-document, tag-definition, tag-reference, etc.. YAML files very human readable, but not very computer friendly. The Tokenizer creates a nice stream of YAML events that can easily be leveraged for different purposes, such as generate JSON, or create dynamic YamlValue's.\n\n**JSON output**: Convert the stream of YAML events into a JSON string. This json string can be used by V's build-in decoder to load the YAML data into V struct's. \n\n**YAML Reader**: User defined [attributes] are not yet supported. Hence the YAML data can only be loaded into V struct's via JSON's built-in JSON decoder. Reader creates a completely dynamic tree-like structure, based on YamlValue's, reflecting lists, objects, key and values, including value types (string, int, float, bool). This is a little bit like in dynamic languages, such as Python.\n\n**Accessor**: Traversing the tree of YamlValue's that make up a yaml file, is not especially pleasant. Accessor provides getter functions, so that by means of a 'path' the value can be accessed. Additionally type converters are provided, to return i8, i16, int, i64, f32, f64, bool etc. values.\n\n## API\n\n```v\n\timport yaml\n\t\n\tcontent := os.read_file(\"myfile.yaml\")?\n\tscanner := yaml.yaml_scanner(content, debug)?\n\tfor i, tok in scanner.tokens { .. }\n\n\ttokenizer := yaml.yaml_tokenizer(content, replace_tags: true, debug: debug)?\n\tfor i, tok in tokenizer.tokens { .. }\n\n\tjson_data := yaml.yaml_to_json(content, replace_tags: true, debug: debug)?\n\tprintln(json_data)\n\n\tdocs := yaml.yaml_reader(content)?\n\tx := docs.get(0)\t// Most files have only 1 (implict) document\n\tassert x.get(\"american\", 0)?.string()? == \"Boston Red Sox\"\n\n\t// with additional options\n\tdocs := yaml.yaml_reader(content, replace_tags: yaml.ReplaceTagsEnum.in_reader, debug: debug)?\n\n\t// Path-like getter for YAML values\n\tassert x1.get(0, \"center\", \"x\")?.int()? == 73\n```\n\n## Examples\n\nThere is a reasonable amount of test cases for each major component. Probably a good starting point for anybody who want to dig a bit deeper.\n\n### Yaml-to-json command line tool\n\nIn the `./examples` folder is a little command line utility that reads a yaml file and prints json to the console \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdonnerstag%2Fvlang-yaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdonnerstag%2Fvlang-yaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdonnerstag%2Fvlang-yaml/lists"}