Parser
Usage
Minimal Example
1try {
2    el::conf::Parser parser;
3    auto document = parser.parseOrThrow(Source::fromFile(u8"configuration.elcl"))
4    // ...
5} catch (const el::conf::Error &error) {
6    std::cerr << error.toText().toCharString() << "\n";
7    exit(1);
8}
Without Exceptions
1el::conf::Parser parser;
2auto document = parser.parse(Source::fromFile(u8"configuration.elcl"))
3if (document == nullptr) {
4    std::cerr << parser.lastError().toText().toCharString() << "\n";
5    exit(1);
6}
With Customized Behaviour
try {
    el::conf::Parser parser;
    parser.setSourceResolver(std::make_shared<MySourceResolver>());
    parser.setAccessCheck(std::make_shared<MyAccessCheck>());
    parser.setSignatureValidator(std::make_shared<MySignatureValidator>());
    auto document = parser.parseOrThrow(Source::fromFile(u8"configuration.elcl"))
    // ...
} catch (const el::conf::Error &error) {
    std::cerr << error.toText().toCharString() << "\n";
    exit(1);
}
See AccessCheck, SourceResolver and SignatureValidator for details.
Interface
- 
class Parser
 This parser reads the Erbsland Configuration Language.
Multithreading: This parser is reentrant, and therefore it can be used in multiple threads, as long each thread uses an individual instance of the parser.
- Tested:
 ParserAccessTest,ParserBasicTest,ParserComplianceTest,ParserErrorClassTest,ParserIncludeTest,ParserSignatureTest
Public Functions
- 
Parser() = default
 Default constructor.
- 
~Parser() = default
 Default destructor.
- 
void setSourceResolver(const SourceResolverPtr &sourceResolver) noexcept
 Set a custom source resolver used to resolve include directives while parsing.
By default, an instance of
FileSourceResolveris used, which supports file-based includes, as specified in the format recommended in the documentation.- Parameters:
 sourceResolver – The custom source resolver, or
nullptrto disable theincludemeta-command.
- 
void setAccessCheck(const AccessCheckPtr &accessCheck) noexcept
 Set a custom access check.
By default, an instance of
FileAccessCheckwith default options is used. This instance limits included files to the same directory and subdirectories of the including configuration.- Parameters:
 accessCheck – An instance of a source access check implementation, or
nullptrto disable theincludemeta-command.
- 
void setSignatureValidator(const SignatureValidatorPtr &signatureValidator) noexcept
 Set a signature validator.
By default, no signature validator is set. This allows parsing all unsigned configuration documents. Documents with a
signaturemeta-value get rejected by the parser.- Parameters:
 signatureValidator – An instance of a signature validator implementation, or
nullptrto disable signature validation.
- 
DocumentPtr parseOrThrow(const SourcePtr &source)
 Parse the given source into a configuration document and throw an exception on any error.
- Parameters:
 source – The source to parse. Should be closed.
- Throws:
 Error – if there was any problem with the parsed source or document.
- Returns:
 The root node of the parsed configuration tree.
- 
DocumentPtr parse(const SourcePtr &source)
 Parse the given source into a configuration document.
- Parameters:
 source – The source to parse. Should be closed.
- Returns:
 The root node of the parsed configuration tree or nullptr on any error. Use
lastError()to access the last error.