CS Parser

Source: ResultSet.js

_/**
 * A container that stores parse results
 */
class ResultSet {
	constructor() {
		this._results = []
	}

	/**
	 * Saves the provided data as a parsing result.
	 * You can pass an array as multiple results
	 * @param {mixed|mixed[]|ResultSet} Result The data to add
	 * @param {boolean} KeepsArray=false
	 * If `true`, stores the result as a single result even if it is an array
	 * @return {ResultSet} This
	 * @chainable
	 */
	add(Result, KeepsArray = false) {
		if (Array.isArray(Result) && !KeepsArray) {
			for (let item of Result) this._results.push(item)
		} else this._results.push(Result)
		return this
	}

	/**
	 * Performs traversal
	 * @param {function} Fn
	 * The callback that receives every single result as the 1st parameter
	 * @param {mixed} Arg=null
	 * Additional argument to pass to `Fn` as the 2nd parameter
	 */
	traverse(Fn, Arg = null) {
		for (let item of this._results) {
			if (item instanceof ResultSet) item.traverse(Fn, Arg)
			else Fn(item, Arg)
		}
	}
}

export default ResultSet

© 2018 Satoshi Soma

Licensed under the Apache License 2.0

Documentation generated by JSDoc 3.6.11 using Docolatte theme on Tue, 05 Sep 2023 18:54:56 GMT

    Hint: You don't need to click on the search box to input.

    Just start typing your words at any time to search for it.

    Classes

    • Composite
      • addChild
      • addChildren
      • traverse
      • verifyChild
    • Context
      • addChild
      • addChildren
      • cleanupChildren
      • clearBuffer
      • end
      • outline
      • parseChunk
      • populate
      • start
      • step
      • traverse
      • updateState
      • verifyChild
    • ContextManager
      • feed
    • Main
      • create
      • newRule
    • Parser
      • addRule
      • addRules
      • onComplete
      • onStart
      • parse
      • parseFile
    • ResultSet
      • add
      • traverse
    • Rule
      • addChild
      • addChildren
      • endsWith
      • express
      • fin
      • init
      • on
      • parse
      • startsWith
      • traverse
      • verifyChild