A Gura parser implementation for Dart

Overview

Gura Dart parser

Pub Version GitHub top language GitHub Workflow Status GitHub issues documentation Discord

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. Fork 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.

Credits

Credit for the vast majority of code and logic in this project goes to the original authors of the TS/JS Gura parser.

This parser started as a 1:1 port of the TypeScript/JavaScript parser implementation, but I've since done a lot of cleanup, restructuring, some logic refactoring, and I've redocumented everything, all to help me better solidify my understanding of the inner-workings of the original implementation.

There are also a lot of TypeScript/JavaScript mechanics that simply didn't translate well to Dart so keeping the implementation port 1:1 was never going to work out, though I didn't know quite how frequently I would encounter that problem until I started the project.

License

This repository is distributed under the terms of the MIT license.

You might also like...

Flutter's sync log component implementation by DartNative.

Flutter's sync log component implementation by DartNative

Apr 30, 2022

A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

Oct 26, 2022

Dart wrapper via dart:ffi for https://github.com/libusb/libusb

libusb Dart wrapper via dart:ffi for https://github.com/libusb/libusb Environment Windows(10) macOS Linux(Ubuntu 18.04 LTS) Usage Checkout example Fea

Dec 20, 2022

Extensible Dart interpreter for Dart with full interop

dart_eval is an extensible interpreter for the Dart language, written in Dart. It's powered under the hood by the Dart analyzer, so it achieves 100% c

Dec 28, 2022

Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Jan 2, 2023

AOP for Flutter(Dart)

AOP for Flutter(Dart)

AspectD Salute to AspectJ. AspectD is an AOP(aspect oriented programming) framework for dart. Like other traditional aop framework, AspectD provides c

Jan 7, 2023

Environment specific config generator for Dart and Flutter applications during CI/CD builds

Environment Config Generator Environment specific config generator. Allows to specify env configuration during CI/CD build. Primarily created to simpl

Dec 2, 2022

A Very Good Command Line Interface for Dart created by Very Good Ventures πŸ¦„

A Very Good Command Line Interface for Dart created by Very Good Ventures πŸ¦„

Very Good CLI Developed with πŸ’™ by Very Good Ventures πŸ¦„ A Very Good Command Line Interface for Dart. Installing $ dart pub global activate very_good_

Jan 8, 2023

πŸš€The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time.

πŸš€The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time.

Flutter Gen Zeplin Extension πŸš€ The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time. ⬇ 1.1k Getti

Oct 12, 2022
Releases(v1.3.3)
Owner
Zack Campbell
TypeScript, Dart, Nim, C#, Lua/Moonscript. I'm always interested in trying new languages.
Zack Campbell
Dart phone number parser, based on libphonenumber and PhoneNumberKit.

Dart library for parsing phone numbers. Inspired by Google's libphonenumber and PhoneNumberKit for ios.

cedvdb 39 Dec 31, 2022
Dart phone number parser, based on libphonenumber and PhoneNumberKit.

Phone Numbers Parser Dart library for parsing phone numbers. Inspired by Google's libphonenumber and PhoneNumberKit for ios. The advantage of this lib

cedvdb 39 Dec 31, 2022
Args simple - A simple argument parser and handler, integrated with JSON and dart

args_simple A simple argument parser and handler, integrated with JSON and dart:

Graciliano Monteiro Passos 1 Jan 22, 2022
Parser tool is a real-time compiler and runtime engine for strongly typed PEG parsers

parser_tool Version 0.1.1 (BETA) Parser tool is a real-time compiler and runtime engine for strongly typed PEG parsers. Parser tool contains libraries

null 6 Jun 28, 2021
JSON API parser for Flutter

Flutter Japx - JSON:API Decoder/Encoder Lightweight [JSON:API][1] parser that flattens complex [JSON:API][1] structure and turns it into simple JSON a

Infinum 23 Dec 20, 2022
A pure Dart implementation of the Pusher Channels Client

pusher_channels is a pure Dart pusher channels client. This client is work in progress and it is unstable. Usage A simple usage example: import 'packa

Indaband 7 Nov 6, 2022
Reference implementation for the Zenon SDK for Dart and Flutter apps compatible

Zenon Dart SDK Reference implementation for the Zenon SDK for Dart and Flutter apps compatible with the Zenon Alphanet - Network of Momentum Phase 0.

null 8 Nov 23, 2022
Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques

Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques. The use of dynamic reflection is constrained in order to ensure that the specialized code can be generated and will have a reasonable size.

Google 318 Dec 31, 2022
Provides null-safety implementation to simplify JSON data handling by adding extension method to JSON object

Lazy JSON Provides null-safety implementation to simplify JSON data handling by adding extension method to JSON object and JSON array. Getting started

Kinnara Digital Studio 0 Oct 27, 2021
Flutter implementation of Clean Architecture, inspired on the guidelines created by Uncle Bob.

clean_framework Flutter implementation of Clean Architecture, inspired on the guidelines created by Uncle Bob. see http://www.amazon.com/dp/0134494164

Acme Software 21 Dec 13, 2022