Skip to content

Latest commit

 

History

History
46 lines (28 loc) · 2.73 KB

README.md

File metadata and controls

46 lines (28 loc) · 2.73 KB

@smotaal/matcher

Matchers are stateful expressions that use interlaced capture hooks (ie entities) to mutate both state and matches. This mere abstraction makes it possible to leverage Regular Expressions beyond the traditional context-free limitations.

Matcher extends the exec method of the RegExp class to iterate over the entities array for respective capture(s).

By default:

  • A capture position is any position in the match array except for the match position itself (ie match[0]).

  • A capture represents an initialized element in a capture position that is not undefined.

  • An entity position in the entities array maps to the capture position of the following index in the match where entityIndex == captueIndex - 1.

  • A null entity in the entities array is always skipped.

  • A ‹identity› entity that is non-callable and which is expected to always be coercible to a string or symbol is assigned to the respective match.capture[‹identity›], where the intact value of ‹identity› last captured is also iteratively reflected as the match.identity.

  • A ‹handler› entity that is callable is called with match[0], capture index, the match, and the state of the Matcher instance, which is expected to independently handle all mutations of the match instance, including mutations to the match.capture or match.identity if necessary.

    Note: By design, there are no safeguards in place for preserving ‹handler› mutations to any match or match.capture fields, but which can be implemented by extensions that would justify such exponential expansive costs.

Token Matcher extends the Matcher interface with a tokenize method that

Progress