Skip to content

eguneys/tamcher

Repository files navigation

Tamcher test workflow

Make composable text matchers.

Install

yarn add tamcher --save

Use

    import { mm } from 'tamcher';

    let mNumber = mm.mr(/^(\d*)(.*)/s, 'number'); // returns a matcher

    mNumber('333') // returns { number: '333' }

See esra for an example use of this library, that parses chess PGN files.

Matchers

import { mm } from 'tamcher';

mm.mr(/regex/, matcherType) Match a regex

Regex Format Regex has to match the rest of the string at the end, so it has to be in this format: /^Extra(YourCapturingGroup)Extra(.*)/s

mm.mseq3([matcher, matcher, matcher], reducer) Match three matchers in sequence:

reducer is a Reducer that defines how to combine the three matchers.

mm.mstar(matcher) Match a matcher greedily

mm.mgroup(matcher, mm.oneMatcherNode(matcherType)) Group a matcher into an object

See matchmaker.ts for all matchers.

Reducers

You can make a reducer for selecting matchers like this: _ => _[0].

import { rr } from 'tamcher';

rr.fFirstTwo(matcherType) Array of first two matchers wrapped to an object with key matcherType.

rr.fLastTwo(matcherType)

rr.fAll(matcherType) Array all matchers

See reducers.ts for all reducers.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published