mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-25 07:25:13 +00:00
merge: avoid using the /v
modifier (#5)
Reviewed-on: https://git.joinsharkey.org/Sharkey/sfm.js/pulls/5
This commit is contained in:
commit
58dc6c3b2e
3 changed files with 43 additions and 1 deletions
|
@ -181,6 +181,18 @@ export function notMatch(parser: Parser<any>): Parser<null> {
|
|||
});
|
||||
}
|
||||
|
||||
export function difference(parserIncluded: Parser<any>, parserExcluded: Parser<any>): Parser<string> {
|
||||
return new Parser((input, index, state) => {
|
||||
const exclude = parserExcluded.handler(input, index, state);
|
||||
|
||||
if (exclude.success) {
|
||||
return failure();
|
||||
}
|
||||
|
||||
return parserIncluded.handler(input, index, state);
|
||||
});
|
||||
}
|
||||
|
||||
export const cr = str('\r');
|
||||
export const lf = str('\n');
|
||||
export const crlf = str('\r\n');
|
||||
|
|
|
@ -12,7 +12,7 @@ import twemojiRegex from '@twemoji/parser/dist/lib/regex';
|
|||
type ArgPair = { k: string, v: string | true };
|
||||
type Args = Record<string, string | true>;
|
||||
|
||||
const space = P.regexp(/[\s--[\n\r]]/v);
|
||||
const space = P.difference(P.regexp(/\s/), P.newline);
|
||||
const alphaAndNum = P.regexp(/\p{Letter}|\p{Number}/iu);
|
||||
const newLine = P.alt([P.crlf, P.cr, P.lf]);
|
||||
|
||||
|
|
30
test/core.ts
Normal file
30
test/core.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import assert from 'assert';
|
||||
import * as P from '../src/internal/core';
|
||||
|
||||
describe('core', () => {
|
||||
describe('difference', () => {
|
||||
test('basic', () => {
|
||||
const parser = P.difference(P.regexp(/\p{Letter}/u), P.str('x'));
|
||||
|
||||
let result = parser.handler('x',0,{}) as P.Success<any>;
|
||||
assert.deepStrictEqual(result,P.failure());
|
||||
|
||||
result = parser.handler('a',0,{}) as P.Success<any>;
|
||||
assert.deepStrictEqual(result,P.success(1,'a'));
|
||||
});
|
||||
|
||||
test('horizontal whitespace', () => {
|
||||
const parser = P.difference(P.regexp(/\s/u), P.newline);
|
||||
|
||||
let result = parser.handler('\n',0,{}) as P.Success<any>;
|
||||
assert.deepStrictEqual(result,P.failure());
|
||||
|
||||
result = parser.handler(' ',0,{}) as P.Success<any>;
|
||||
assert.deepStrictEqual(result,P.success(1,' '));
|
||||
|
||||
result = parser.handler('\t',0,{}) as P.Success<any>;
|
||||
assert.deepStrictEqual(result,P.success(1,'\t'));
|
||||
});
|
||||
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue