funkwerk.stdx.data.json.lexer

Provides JSON lexing facilities.

Synopsis:

// Lex a JSON string into a lazy range of tokens
auto tokens = lexJSON(`{"name": "Peter", "age": 42}`);

with (JSONToken) {
    assert(tokens.map!(t => t.kind).equal(
        [Kind.objectStart, Kind.string, Kind.colon, Kind.string, Kind.comma,
        Kind.string, Kind.colon, Kind.number, Kind.objectEnd]));
}

// Get detailed information
tokens.popFront(); // skip the '{'
assert(tokens.front.string == "name");
tokens.popFront(); // skip "name"
tokens.popFront(); // skip the ':'
assert(tokens.front.string == "Peter");
assert(tokens.front.location.line == 0);
assert(tokens.front.location.column == 9);

Members

Enums

JSONTokenKind
enum JSONTokenKind

Identifies the kind of a JSON token.

LexOptions
enum LexOptions

Flags for configuring the JSON lexer.

Functions

escapeStringLiteral
void escapeStringLiteral(Input input, Output output)
Undocumented in source. Be warned that the author may not have intended to support it.
escapeStringLiteral
String escapeStringLiteral(String str)
Undocumented in source. Be warned that the author may not have intended to support it.
isValidStringLiteral
bool isValidStringLiteral(String str)
Undocumented in source. Be warned that the author may not have intended to support it.
lexJSON
JSONLexerRange!(Input, options, String) lexJSON(Input input, string filename)

Returns a lazy range of tokens corresponding to the given JSON input string.

skipStringLiteral
bool skipStringLiteral(Array input, Array destination, string error, size_t column, bool has_escapes)
Undocumented in source. Be warned that the author may not have intended to support it.
unescapeStringLiteral
bool unescapeStringLiteral(Input input, Output output, String sliced_result, OutputInitFunc output_init, string error, size_t column)
Undocumented in source. Be warned that the author may not have intended to support it.
unescapeStringLiteral
bool unescapeStringLiteral(String str_lit, String dst)
Undocumented in source. Be warned that the author may not have intended to support it.

Structs

JSONLexerRange
struct JSONLexerRange(Input, LexOptions options = LexOptions.init, String = string)

* A lazy input range of JSON tokens. * * This range type takes an input string range and converts it into a range of * JSONToken values. * * See lexJSON for more information.

JSONNumber
struct JSONNumber

Represents a JSON number literal with lazy conversion.

JSONString
struct JSONString(String)

Represents a JSON string literal with lazy (un)escaping.

JSONToken
struct JSONToken(S)

* A low-level JSON token as returned by JSONLexer.

Meta

Authors

Sönke Ludwig

Credits

Support for escaped UTF-16 surrogates was contributed to the original vibe.d JSON module by Etienne Cimon. The number parsing code is based on the version contained in Andrei Alexandrescu's "std.jgrandson" module draft.