Skip to content
Snippets Groups Projects
Commit 58dc6c3b authored by Marie's avatar Marie
Browse files

merge: avoid using the `/v` modifier (#5)

Reviewed-on: https://git.joinsharkey.org/Sharkey/sfm.js/pulls/5
parents 2b2305c0 cb611b27
No related branches found
No related tags found
1 merge request!1push develop into stable
......@@ -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]);
......
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'));
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment