Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

gura dart parser

this repository contains the implementation of a gura configuration format parser for dart, written in pure dart. (compliant with spec version 1.0.0).

installation

dart pub add gura

usage

import package:gura/gura.dart and use the [parse()], [parsefile()], or [parsefilesync()]
functions to convert your gura input into a map<string, dynamic> for use in your code.

examples

import 'package:gura/gura.dart';

final string gurastring = '''
# this is a gura document.
title: "gura example"

an_object:
    username: "stephen"
    pass: "hawking"

# line breaks are ok when inside arrays
hosts: [
    "alpha",
    "omega"
]
''';

void main()
{
    // parse: transforms a gura string into a map of gura key/value pairs
    final map<string, dynamic> parsedgura = parse(gurastring);
    print(parsedgura);

    // access a specific field
    print('title -> ${parsedgura['title']}');

    // iterate over structures (parsedgura['hosts'] is list<dynamic> but we know
    // it contains strings so we can safely cast to string when iterating over it)
    for (final string host in parsedgura['hosts'])
        print('host -> $host');

    // dump: stringifies map<string, dynamic> as a gura-compatible string
    print(dump(parsedgura));
}
import 'dart:io';
import 'package:gura/gura.dart';

future<void> main() async
{
    final file gurafile = file('foo_bar.ura');
    final map<string, dynamic> parsedgura = await parsefile(gurafile);
    ...
}
import 'dart:io';
import 'package:gura/gura.dart';

void main()
{
    final file gurafile = file('foo_bar.ura');
    final map<string, dynamic> parsedgura = parsefilesync(gurafile);
    ...
}

in the event that any of the library function names (parse, parsefile, etc.)
conflict with functions from another library, alias gura and use qualified function
calls via the alias:

import 'dart:io';
import 'package:gura/gura.dart' as gura;

void main()
{
    final file gurafile = file('foo_bar.ura');
    final map<string, dynamic> parsedgura = await gura.parsefile(gurafile);
    ...
}

contributing

  1. download this project
  2. create new branch for your feature
  3. commit and push your changes
  4. submit a pull request

sadly, dart’s selection of tools for maintaining a consistent code style do not
allow for much customization in a way that supports my personal code style, and
i don’t like the opinionated style of dartfmt, so if you choose to contribute,
please do your best to maintain code style consistent with the rest of the repo
in your contributions. i’ll review prs to ensure this.

tests

to run all tests, run dart test in the project root.


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.