Skip to content

Trim matches #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 60 commits into
base: serde
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
21beef2
Deserializing unit structs implemented
tailhook Aug 15, 2017
db3f06f
Implements decoding mappings
tailhook Aug 15, 2017
e05b59d
Deserializes struct values
tailhook Aug 15, 2017
d679dfb
Implements deserialisation of enums
tailhook Aug 15, 2017
f67f519
Fixes final test
tailhook Aug 15, 2017
2b4c327
Merge branch 'serde': all original tests work
tailhook Aug 15, 2017
f84217f
vagga.yaml: upgrades rust and other things
tailhook Aug 15, 2017
21dae11
Removes old decode module (rustc_serialize) and fixes all tests
tailhook Aug 15, 2017
d50c2cd
Fixes tests for paths on windows
tailhook Aug 15, 2017
0671734
Adds `duration` and `regex` helper modules
tailhook Aug 16, 2017
32241e0
Fixes `deserialize_str` (fixes `regex` and `duration` modules)
tailhook Aug 16, 2017
b467588
Also test build without modules on travis
tailhook Aug 16, 2017
a314885
More options for booleans supported
tailhook Aug 16, 2017
6452d89
Renames json tests to transcode tests, fixes them
tailhook Aug 16, 2017
048896b
Shows path in errors again
tailhook Aug 16, 2017
62e883a
Hides `Error` type under a newtype
tailhook Aug 16, 2017
9e795bc
Exposed error constructors again (for use in include handlers)
tailhook Aug 16, 2017
237a0d4
Revert "More options for booleans supported"
tailhook Aug 17, 2017
2b630bf
Tweaks error messages
tailhook Aug 17, 2017
d1d88b6
Deserializing newtype structs is implemented
tailhook Aug 23, 2017
5dd2f3f
Fixes deserializing non-string mapping keys
tailhook Aug 23, 2017
db0ff2e
Upgrades rust to 1.20, adds packaging stuff
tailhook Sep 4, 2017
7d8c995
Version bumped to v0.3.0
tailhook Sep 4, 2017
b897eda
Custom errors for validators
anti-social Sep 20, 2017
1240b17
Refactor Error's constructors names
anti-social Sep 21, 2017
78bf7f2
Merge pull request #11 from anti-social/dev/custom-error
tailhook Sep 21, 2017
3e32f14
Adds "config" category to Cargo.toml
tailhook Sep 21, 2017
c2e792d
Converted README.rst -> README.md
tailhook Sep 21, 2017
d43953d
Version bumped to v0.3.1
tailhook Sep 21, 2017
8a6d8a3
vagga.yaml: Upgrade rust to v1.22.1, remove cargo-outdated from conta…
tailhook Dec 16, 2017
a767538
Eliminate few warnings
tailhook Dec 16, 2017
a412bcb
[breaking] Add support of IncludeSeq and IncludeMap
tailhook Dec 16, 2017
265511a
Allow tag and anchor in any order
tailhook Feb 9, 2018
9e75f86
Fix empty lines in literals when CRLF newlines are used
tailhook Apr 11, 2018
221cbdb
Better error reporting for nonimplemented things
tailhook Apr 11, 2018
c1d8464
[breaking] Remove regex module (use serde_regex), remove json module
tailhook May 25, 2018
9d247ed
Fix most warnings
tailhook May 25, 2018
ceb6b03
Remove unused attributes of Deserializer
tailhook May 25, 2018
7438579
Fix more warnings
tailhook May 25, 2018
3fbcb63
Remove duration parser (use humantime directly)
tailhook May 25, 2018
d1e7bdf
Implement debug for everything
tailhook May 25, 2018
bca4800
Make Error implement Send + Sync
tailhook May 25, 2018
cbdfe17
Fix duration test
tailhook May 25, 2018
1012d42
Version bumped to v0.4.0
tailhook May 27, 2018
3caa66d
Fix typo
tailhook May 31, 2018
1963992
vagga.yaml: upgrade containers
tailhook Jul 23, 2018
ea44229
Upgrade dependencies
tailhook Jul 23, 2018
91ad284
Error on tag or anchor before alias
tailhook Jul 23, 2018
a6dc2f6
Version bumped to v0.4.1
tailhook Jul 23, 2018
47f1489
Document there is more documentation
stappersg Jul 21, 2019
7167bfe
Bumped the year in sphinx-doc
tailhook Jul 21, 2019
f7b046d
Working example for lib.rs
stappersg Jul 22, 2019
4a431f8
Merge pull request #18 from stappersg/libRSexample
tailhook Jul 30, 2019
db76602
Merge pull request #16 from stappersg/bumpDocYear
tailhook Jul 30, 2019
1c0f06d
Merge pull request #13 from stappersg/moreDoc
tailhook Jul 30, 2019
6bd7aad
Added simple expample
stappersg Aug 4, 2019
04b5bfa
Information for programmer in documation
stappersg Aug 4, 2019
aed331f
Added examples/README.text
stappersg Aug 4, 2019
f4d7117
Merge pull request #19 from hendrikx-itc/master
tailhook Aug 4, 2019
96f2e71
trim_left_matches superseded by trim_start_matches
stappersg Aug 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
sudo: false
dist: trusty
language: rust
rust:
- stable
- beta
- nightly
script:
- cargo build --verbose
- cargo test --verbose

cache:
- cargo

before_cache:
- rm -r $TRAVIS_BUILD_DIR/target/debug

jobs:
include:
- os: linux
rust: stable
- os: linux
rust: beta
- os: linux
rust: nightly

# deploy
- stage: publish
os: linux
rust: stable
env:
# CARGO_TOKEN
- secure: "IPm2lHXAtXUY8pJtUMRV+jgLSCPKRJQyP3ax5aUhyaGlR83w4krEOcIpqQgu5a4rgw3SZUjDhxQMsRbzRZIehU+C3u2LTDpn0yycPnGmFRKVqnoS5dHdFMQ6IKLDZQK99MFZ/vMThipImnS9WFm2D1X/8XS31Mpn81Y7o54rIHk="
install: true
script: true

deploy:
- provider: script
script: 'cargo publish --verbose --token=$CARGO_TOKEN'
on:
tags: true
15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
name = "quire"
description = "A YAML-based configuration parsing library"
license = "MIT/Apache-2.0"
readme = "README.rst"
readme = "README.md"
keywords = ["config", "yaml", "parser"]
homepage = "http://github.com/tailhook/rust-quire"
version = "0.2.3"
categories = ["config"]
version = "0.4.1"
authors = ["[email protected]"]

[dependencies]
rustc-serialize = "0.3"
quick-error = "1.0.0"
regex = "0.1.80"
humantime = "1.0.0"
num-traits = "0.1.36"
quick-error = "1.2.0"
num-traits = "0.2.5"
humannum = "0.1.0"
serde = "1.0.10"

[dev-dependencies]
serde_derive = "1.0.10"
serde_json = "1.0.2"
serde-transcode = "1.0.0"
serde-humantime = "0.1.1"
17 changes: 9 additions & 8 deletions README.rst → README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
==========
Rust Quire
==========

:Status: Beta
*Status: Beta*


The ``rust-quire`` is a Rust_ port for quire_ configuration parsing library.
It also contains YAML_ parser (however, it tuned for configuration parsing
rather than generic YAML parser, e.g. it assumes YAML always fits memory).
The ``rust-quire`` is a [Rust][1] port for [quire][2] configuration parsing
library. It also contains [YAML][3] parser (however, it tuned for
configuration parsing rather than generic YAML parser, e.g. it assumes YAML
always fits memory).

See `doc/` for additional information.

.. _quire: http://github.com/tailhook/quire
.. _YAML: http://yaml.org
.. _Rust: http://rust-lang.org
[1]: http://github.com/tailhook/quire
[2]: http://yaml.org
[3]: http://rust-lang.org


License
Expand Down
15 changes: 15 additions & 0 deletions bulk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
minimum-bulk: v0.4.5

versions:

- file: Cargo.toml
block-start: ^\[package\]
block-end: ^\[.*\]
regex: ^version\s*=\s*"(\S+)"

- file: doc/conf.py
regex: ^version\s*=\s*'(\S+)'
partial-version: ^\d+\.\d+

- file: doc/conf.py
regex: ^release\s*=\s*'(\S+)'
11 changes: 11 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
doc/
====

In this directory documentation in [sphinx-doc][1] format.

Type `make html` to get HTML generated. Expect to get errors
when *sphinx-doc* is not installed on your system.

With `make` you get a list of possible output formats.

[1]: http://www.sphinx-doc.org/
6 changes: 3 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@

# General information about the project.
project = 'Quire'
copyright = '2013, Paul Colomiets'
copyright = '2013-2019, Paul Colomiets'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '2.0'
version = '0.4'
# The full version, including alpha/beta/rc tags.
release = '2.0-beta1'
release = '0.4.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Contents:
:maxdepth: 2

user
programmer

.. _Yaml: http://yaml.org

Expand Down
44 changes: 44 additions & 0 deletions doc/programmer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

================
Programmer Guide
================

As a programmer you are looking for source code.
You found it, here it is.

.. literalinclude:: ../examples/simple.rs
:language: rust


Key link
========

The key link between configuration file
and the executable programm that you are writen
is the configuration ``struct``.

In the demo source code is that struct named *Config*
and is *cfg* a variable of type Config.


config.yaml
===========

Nothing of ``Config`` or ``cfg`` needs to be in the YAML.
But the field names **must**.

Here the *.yaml* that goes with the above example source code.


.. literalinclude:: ../examples/config.yaml
:language: yaml


See also
========

The documentation of `serde <https://serde.rs/>`_.

Our ``examples`` directory.

`Reverse dependencies <https://crates.io/crates/quire/reverse_dependencies>`_.
85 changes: 84 additions & 1 deletion doc/user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ node that contains tag. For example:
.. code-block:: yaml

# config.yaml
items: !Include items.yaml
items: !*Include items.yaml

.. code-block:: yaml

Expand All @@ -209,6 +209,89 @@ Is equivalent of:
- banana


.. _include-seq:

Include Sequences of Files
--------------------------

The ``!*IncludeSeq`` tag includes files matched by glob as a sequence:

.. code-block:: yaml

items: !*IncludeSeq "fruits/*.yaml"

Can be parsed as:

.. code-block:: yaml

items:
- apple
- banana
- cherry

This depends on the exact application, but usually files returned by `glob`
are sorted in alphabetical order. All the power of globs is supported, so you
can do:

.. code-block:: yaml

items: !*IncludeSeq "files/**/*.yaml"

Another trick is merge multiple files, each with it's own set of keys into
a single one (see map-merge_ below):

.. code-block:: yaml

# file1.yaml
key1: 1
key2: 2
# file2.yaml
key3: 3
key4: 4
# main.yaml
<<: !*IncludeSeq "configs/*.yaml"

This results into the following config:

.. code-block:: yaml

key1: 1
key2: 2
key3: 3
key4: 4

Note: merging is not recursive, i.e. top level keys are considered as a whole,
even if they are dicts.


.. _include-map:

Include Mapping from Files
--------------------------

The ``!*IncludeMap`` tag works similarly to ``!*IncludeSeq`` but requires to
mark part of a name used as a key. For example:

.. code-block:: yaml

items: !*IncludeMap "fruits/(*).yaml"

Might result into the folowing:

.. code-block:: yaml

items:
apple: { color: orange }
banana: { color: yellow }
cherry: { color: red }

You can parenthesize any part as well as a whole path:

.. code-block:: yaml

files: !*IncludeMap "(**/*.yaml)"


.. _map-merge:

Merging Mappings
Expand Down
10 changes: 10 additions & 0 deletions examples/README.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Run
cargo build --examples
anywhere to get examples been compiled.

For
cargo run --example simple
be in the top directory of the project.
That is for having the correct start point
to get path to config.yaml right.
8 changes: 8 additions & 0 deletions examples/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
---
item1: foo
# comment
item2: bar
_item3: underscore used to comment out a keyword
...
# l l
31 changes: 31 additions & 0 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
extern crate quire;
#[macro_use] extern crate serde_derive;
use quire::{parse_config, Options};
use quire::validate::{Structure, Scalar};

#[derive(Deserialize)]
#[allow(dead_code)]
struct Config {
item1: String,
item2: Option<String>,
}

fn validator() -> Structure<'static> {
Structure::new()
.member("item1", Scalar::new())
.member("item2", Scalar::new().optional())
}

fn work(cfg: &Config) {
println!("item1 is {}.", cfg.item1);
//intln!("item2 is {}.", cfg.item2);
// hey, this is just demonstration code ...
}

fn main() {
let cfg: Config;
cfg = parse_config("examples/config.yaml",
&validator(), &Options::default())
.expect("valid config");
work(&cfg)
}
12 changes: 9 additions & 3 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::collections::BTreeMap;
use super::tokenizer::Pos;
use super::errors::{Error, ErrorCollector};
use super::parser::Node as P;
use super::parser::{Directive, Node, Document};
use super::parser::{Node, Document};
use super::tokenizer::TokenType as T;
use self::Ast::*;
use self::NullKind::*;
Expand Down Expand Up @@ -118,7 +118,6 @@ impl Ast {

struct Context<'a, 'b: 'a> {
options: &'a Options<'b>,
directives: Vec<Directive<'a>>,
err: &'a ErrorCollector,
}

Expand Down Expand Up @@ -179,6 +178,14 @@ impl<'a, 'b: 'a> Context<'a, 'b> {
return self.options.include(&tok.start,
&Include::File { filename: val }, self.err);
}
P::Scalar(Some("!*IncludeSeq"), _anch, ref val, ref tok) => {
return self.options.include(&tok.start,
&Include::Sequence { pattern: val }, self.err);
}
P::Scalar(Some("!*IncludeMap"), _anch, ref val, ref tok) => {
return self.options.include(&tok.start,
&Include::Mapping { pattern: val }, self.err);
}
P::Scalar(ref tag, _, ref val, ref tok) => {
let pos = tok.start.clone();
let tag = self.string_to_tag(&pos, tag);
Expand Down Expand Up @@ -371,7 +378,6 @@ impl<'a, 'b: 'a> Context<'a, 'b> {
pub fn process(opt: &Options, doc: Document, err: &ErrorCollector) -> Ast {
let mut ctx = Context {
options: opt,
directives: doc.directives,
err: err,
};
return ctx.process(&doc.root);
Expand Down
Loading