Parser

SaxaMLLParser

Attributes

executor: SaxaMLLExecutor

  • Type: SaxaMLLExecutor

  • Description: An instance of the SaxaMLLExecutor class used to handle parsing events.

ast: XMLNode

  • Type: XMLNode

  • Description: The Abstract Syntax Tree (AST) representing the parsed XML structure. This is a read-only property that returns the current state of the AST.

state: ParserState

  • Type: ParserState

  • Description: The current state of the parser. This is a read-only property that returns the current parsing state.

stack: { node: XMLNode; state: ParserState }[]

  • Type: Array of objects containing node and state properties

  • Description: The parsing stack, representing the current nesting level of XML nodes. This is a read-only property.

Methods

parse(input: string): void

  • Parameters:

    • input: string - The XML-like content to be parsed.

  • Description: This method adds the input to an internal buffer and processes each character sequentially. It updates the parser's state and builds the Abstract Syntax Tree (AST) as it parses.

update(): void

  • Description: This method flushes the current parsing state, which can trigger "update" events for any complete nodes. It's useful for processing partial inputs in streaming scenarios.

end(): void

  • Description: This method should be called when all input has been provided. It ensures that all remaining nodes are properly closed and added to the AST. It will also trigger any remaining "tagClose" events.

setExecutor(executor: SaxaMLLExecutor): void

  • Parameters:

    • executor: SaxaMLLExecutor - The new executor instance to be used by the parser.

  • Description: This method allows you to replace the current executor with a new one, which can be useful for changing event handling behavior.

SaxaMLLExecutor

Methods

upon(event: T): ExecutionHandlerBuilder

  • Parameters:

    • event: SaxaMLLEventType - The type of event to handle. Can be "tagOpen", "tagClose", or "update".

  • Returns: ExecutionHandlerBuilder - A builder object for defining event handlers.

  • Description: This method is the entry point for defining custom event handlers. It allows for fluent chaining of method calls to specify the exact conditions and actions for the event.

onTagOpen(): ExecutionHandlerBuilder<"tagOpen">

  • Returns: ExecutionHandlerBuilder<"tagOpen"> - A builder object for defining tagOpen event handlers.

  • Description: Convenience method for handling tagOpen events.

onTagClose(): ExecutionHandlerBuilder<"tagClose">

  • Returns: ExecutionHandlerBuilder<"tagClose"> - A builder object for defining tagClose event handlers.

  • Description: Convenience method for handling tagClose events.

onUpdate(): ExecutionHandlerBuilder<"update">

  • Returns: ExecutionHandlerBuilder<"update"> - A builder object for defining update event handlers.

  • Description: Convenience method for handling update events.

addHandler(event: T, tag: XMLNodeDescription | string, callback: SaxaMLLEventTypeToCallback[T]): void

  • Parameters:

    • event: SaxaMLLEventType - The type of event to handle.

    • tag: XMLNodeDescription | string - The tag to associate with this handler.

    • callback: SaxaMLLEventTypeToCallback[T] - The function to be called when the event occurs.

  • Description: This method directly adds an event handler to the executor. It's used internally by the ExecutionHandlerBuilder but can also be used directly for more fine-grained control.

ExecutionHandlerBuilder

Constructor

  • Parameters:

    • executor: SaxaMLLExecutor - The executor instance associated with this builder.

    • eventType: T - The type of event this handler is for.

    • tag?: XMLNodeDescription | string - Optional. The tag associated with this handler.

Methods

for(tag: XMLNodeDescription | string): this

  • Parameters:

    • tag: XMLNodeDescription | string - The tag to associate with this handler.

  • Returns: this - The current builder instance for method chaining.

  • Description: Specifies the tag for which the handler is being built.

do(callback: SaxaMLLEventTypeToCallback[T]): void

  • Parameters:

    • callback: SaxaMLLEventTypeToCallback[T] - The function to be called when the event occurs.

  • Description: Adds a handler for the specified event type and tag.

getEventName(): string

  • Returns: string - The full event name, including the tag if specified.

  • Description: Gets the full event name for the current event and tag combination.

Last updated