Login
rsconf.cr at tip
Login

File src/remilib/rsconf.cr from the latest check-in


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
#### libremiliacr
#### Copyright(C) 2020-2024 Remilia Scarlet <remilia@posteo.jp>
####
#### This program is free software: you can redistribute it and/or modify it
#### under the terms of the GNU General Public License as published the Free
#### Software Foundation, either version 3 of the License, or (at your option)
#### any later version.
####
#### This program is distributed in the hope that it will be useful, but WITHOUT
#### ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#### FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for
#### more details.
####
#### You should have received a copy of the GNU General Public License along
#### with this program.If not, see<http:####www.gnu.org/licenses/.>
require "./rsconf/common"
require "./rsconf/parser"
require "./rsconf/serializable"
require "./rsconf/fromrsconf"
require "./rsconf/writer"
require "./rsconf/builder"
require "./rsconf/torsconf"

# RSConf is a data serialization format that's somewhere in-between JSON and
# hjson.  It has a few more features than JSON that make it nicer for config
# files, such as comments, not needing commas, and unquoted strings.  But it
# it's less strict and has fewer features than hjson to keep parsing simple.
#
# It was created to fill a niche and scratch an itch for a nice, easy-to-use
# config format that doubles as a data serialization format.  JSON is nice and
# (usually) easy to visually parse as a human, but is too strict with its
# syntax, and doesn't have comments.  YAML is nice, but has far too many bells
# and whistles, leading to all sorts of strange edge cases, and a large space
# for possible security problems.  TOML is just ugly and hard to visually parse
# once it gets complex.  Hjson is nice, but has just a few too many unnecessary
# features, and is a bit too flexible.  Thus, RSConf was born to fill the hole
# left by these other formats.
#
# As a high-level overview, RSConf is like JSON, but:
#
# * Keys don't need quoting if they do not contain spaces.
# * Commas don't need to come after values/key-value pairs unless there are
#   multiple values/key-value pairs on the same line.
# * Toplevel braces (`{` and `}`) can be omitted if the toplevel is an object.
# * Integers and floats are differentiated.
# * Integers can be in hex, octal, or binary.  Floats can be in decimal or
#   "scientific notation" (and accept either `e` or `d` for their character).
# * The null value is called `nil`.
# * Comments are allowed and use semicolons (`;`)
# * Explicit minimum limits for integers and floats.
# * Stricter whitespace.
#
# It is also a lot like hsjon, except:
#
# * All strings are multi-line strings; no separate syntax.
# * No quoteless strings.
# * Integers can be in hex, octal, or binary.  Floats can be in decimal or
#   "scientific notation" (and accept either `e` or `d` for their character).
# * The null value is called `nil`.
# * Comments are allowed and use semicolons (`;`)
# * No multi-line comments.
# * Explicit minimum limits for integers and floats.
# * Slightly stricter whitespace.
#
# The reference implementation for RSConf is in Common Lisp and is part of the
# sibling library to libremiliacr,
# [CL-SDM](https://chiselapp.com/user/MistressRemilia/repository/cl-sdm/).  This
# is a direct port of that reference implementation, adapted to Crystal.
#
# Some well-formatted example RSConf data:
#
# ```
# ;;;;
# ;;;; Example Document
# ;;;;
#
# some-object: {
#   values: [ 1, 2, 3] ;; Recommended syntax for short arrays
#
#   ;; Better syntax for larger arrays, or ones with long values.
#   values-2: [
#     "foo"
#     "bar"
#     "baz"
#   ]
#
#   name: "test"
#   sub-obj: {
#     id: 1, ;; Comma here is optional
#     enabled: false ;; or "true"
#     something-else: nil ;; Null values are represented with "nil"
#   }
# }
# ```
module RemiLib::RSConf
end