Donner SVG main
0.8.0 ยท 766e862a0.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::svg::parser::SVGParserContext Class Reference

Stores the current state of SVGParser during parsing. More...

#include "donner/svg/parser/details/SVGParserContext.h"

Public Member Functions

 SVGParserContext (std::string_view input, ParseWarningSink &warningSink, const SVGParser::Options &options)
 Construct a new context for the given input string.
const SVGParser::Options & options () const
 Get the parser options.
void setNamespacePrefix (const RcString &namespacePrefix)
 Set the XML document's default namespace prefix, such as "http://www.w3.org/2000/svg".
std::string_view namespacePrefix () const
 Get the XML document's default namespace prefix, such as "http://www.w3.org/2000/svg".
ParseDiagnostic fromSubparser (ParseDiagnostic &&error, ParserOrigin origin)
 Remap a parse error from a subparser back to the original input string, translating the line numbers.
void addWarning (ParseDiagnostic &&warning)
 Add a warning to the list of warnings.
bool warningsEnabled () const
 Whether the document parser collects diagnostics.
const std::vector< ParseDiagnostic > & warnings () const
 Warnings collected so far, in the order they were added.
void setTypedAttributesOnly (bool typedOnly)
 Restrict attribute parsing to type-specific attributes: an attribute that falls through to the common attribute path (presentation, conditional-processing and generic attributes) is left alone and only recorded, see fellThroughToCommonAttributes.
bool typedAttributesOnly () const
 Whether attribute parsing skips common attributes, see setTypedAttributesOnly.
void noteCommonAttributeFallThrough ()
 Records that an attribute fell through to the common attribute path.
bool takeCommonAttributeFallThrough ()
 Returns whether an attribute fell through to the common attribute path since the last call, and clears the record.
void addRecoverableWarnings (ParseWarningSink &&warnings)
 Forward recovered parser diagnostics directly, preserving bounded sink refusal flags.
SourceRange documentSourceRange (SourceRange range) const
 Annotate a known document source range when original input is available.
void addSubparserWarning (ParseDiagnostic &&warning, ParserOrigin origin)
 Add a warning from a subparser to the list of warnings, remapping the error back to the original input string.
std::optional< SourceRange > getAttributeLocation (const xml::XMLNode &node, const xml::XMLQualifiedNameRef &attributeName) const
 Get the location of an element's attribute in the input string, from an XMLNode.
std::optional< SourceRange > getAttributeLocation (const SVGElement &element, const xml::XMLQualifiedNameRef &attributeName) const
 Get the location of an element's attribute in the input string, from an SVGElement.
ParserOrigin parserOriginFrom (std::string_view substring) const
 Create a ParserOrigin for the given substring, where substring is within the XML parser's original string.
size_t offsetToLine (size_t offset) const
 Return line numbers for the given offset.
size_t lineOffset (size_t line) const
 Returns the offset of a given 1-indexed line number.

Detailed Description

Stores the current state of SVGParser during parsing.

Used to add parse warnings and store global state like the parsing options.

Constructor & Destructor Documentation

◆ SVGParserContext()

donner::svg::parser::SVGParserContext::SVGParserContext ( std::string_view input,
ParseWarningSink & warningSink,
const SVGParser::Options & options )
inline

Construct a new context for the given input string.

Parameters
inputInput string.
warningSinkSink to collect warnings encountered during parsing.
optionsOptions for parsing.

Member Function Documentation

◆ addRecoverableWarnings()

void donner::svg::parser::SVGParserContext::addRecoverableWarnings ( ParseWarningSink && warnings)
inline

Forward recovered parser diagnostics directly, preserving bounded sink refusal flags.

Parameters
warningsDiagnostics whose semantic failure has already been recovered.

◆ addSubparserWarning()

void donner::svg::parser::SVGParserContext::addSubparserWarning ( ParseDiagnostic && warning,
ParserOrigin origin )
inline

Add a warning from a subparser to the list of warnings, remapping the error back to the original input string.

Parameters
warningWarning to add.
originOrigin of the subparser.

◆ addWarning()

void donner::svg::parser::SVGParserContext::addWarning ( ParseDiagnostic && warning)
inline

Add a warning to the list of warnings.

Parameters
warningWarning to add.

◆ documentSourceRange()

SourceRange donner::svg::parser::SVGParserContext::documentSourceRange ( SourceRange range) const
inline

Annotate a known document source range when original input is available.

Parameters
rangeRange already mapped to document source bytes.
Returns
Range with document line information, or unchanged for source-less documents.

◆ fromSubparser()

ParseDiagnostic donner::svg::parser::SVGParserContext::fromSubparser ( ParseDiagnostic && error,
ParserOrigin origin )
inline

Remap a parse error from a subparser back to the original input string, translating the line numbers.

Parameters
errorError to remap.
originOrigin of the subparser.
Returns
ParseDiagnostic Remapped error.

◆ getAttributeLocation() [1/2]

std::optional< SourceRange > donner::svg::parser::SVGParserContext::getAttributeLocation ( const SVGElement & element,
const xml::XMLQualifiedNameRef & attributeName ) const
inline

Get the location of an element's attribute in the input string, from an SVGElement.

Parameters
elementElement containing the attribute.
attributeNameName of the attribute.
Returns
std::optional<size_t> Offset of the element's attribute in the input string.

◆ getAttributeLocation() [2/2]

std::optional< SourceRange > donner::svg::parser::SVGParserContext::getAttributeLocation ( const xml::XMLNode & node,
const xml::XMLQualifiedNameRef & attributeName ) const
inline

Get the location of an element's attribute in the input string, from an XMLNode.

Parameters
nodeNode containing the attribute.
attributeNameName of the attribute.
Returns
std::optional<size_t> Offset of the element's attribute in the input string.

◆ lineOffset()

size_t donner::svg::parser::SVGParserContext::lineOffset ( size_t line) const
inline

Returns the offset of a given 1-indexed line number.

Parameters
lineLine number, 1-indexed.

◆ offsetToLine()

size_t donner::svg::parser::SVGParserContext::offsetToLine ( size_t offset) const
inline

Return line numbers for the given offset.

For example, given a string: "abc\n123", offsets 0-3 would be considered line 1, and offsets after 4 (corresponding to the index of '1'), would be line 2. Values beyond the length of the string return the last line number.

Parameters
offsetCharacter index.
Returns
size_t Line number, 1-indexed.

◆ parserOriginFrom()

ParserOrigin donner::svg::parser::SVGParserContext::parserOriginFrom ( std::string_view substring) const
inline

Create a ParserOrigin for the given substring, where substring is within the XML parser's original string.

Parameters
substringSubstring within the XML parser's original string.

◆ setNamespacePrefix()

void donner::svg::parser::SVGParserContext::setNamespacePrefix ( const RcString & namespacePrefix)
inline

Set the XML document's default namespace prefix, such as "http://www.w3.org/2000/svg".

Parameters
namespacePrefixThe default namespace prefix, such as "http://www.w3.org/2000/svg".

◆ setTypedAttributesOnly()

void donner::svg::parser::SVGParserContext::setTypedAttributesOnly ( bool typedOnly)
inline

Restrict attribute parsing to type-specific attributes: an attribute that falls through to the common attribute path (presentation, conditional-processing and generic attributes) is left alone and only recorded, see fellThroughToCommonAttributes.

Parameters
typedOnlyWhether to skip common attributes.

The documentation for this class was generated from the following file:
  • donner/svg/parser/details/SVGParserContext.h