Check-in [a7570b453e]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[e317a8826e] Implemented whitespace parser and accompanying tests. This parser does not aggressively consume whtiespace, as the all combinator exists to consume multiple spaces.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a7570b453e8941819c34b7e317435a2f8566a2ac
User & Date: CrosslandA 2016-10-10 20:07:29
Context
2016-10-10
20:39
Added tslint to visual studio; added configuration file with sane value and made required code changes. check-in: 36ac7749fe user: CrosslandA tags: trunk
20:07
[e317a8826e] Implemented whitespace parser and accompanying tests. This parser does not aggressively consume whtiespace, as the all combinator exists to consume multiple spaces. check-in: a7570b453e user: CrosslandA tags: trunk
19:28
Turned off file system watching. check-in: a3c0274a20 user: CrosslandA tags: trunk
Changes

Changes to src/pcomb.ts.

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260


















        return result;
    }
}

export function numeric(outerAction?: ParserAction): Parser {
    return (input: ParserInput, output: ParserOutput, action?: ParserAction): ParseResult => {
                    let inCopy = input.copy();
            let outCopy = output.copy();
            let result: ParseResult = [false, inCopy, outCopy];
            let cur: string = input.text.slice(0, 1);
            let curAsNum: number = Number(cur);
            if (cur != "" && !isNaN(curAsNum)) {
                result[0] = true;
                result[1].text = input.text.slice(1);
                result[2].matched.push(cur);
            }

            return result;
    }
}
























|
|
|
|
|
|
|
|
|
|

|

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

        return result;
    }
}

export function numeric(outerAction?: ParserAction): Parser {
    return (input: ParserInput, output: ParserOutput, action?: ParserAction): ParseResult => {
        let inCopy = input.copy();
        let outCopy = output.copy();
        let result: ParseResult = [false, inCopy, outCopy];
        let cur: string = input.text.slice(0, 1);
        let curAsNum: number = Number(cur);
        if (cur != "" && !isNaN(curAsNum)) {
            result[0] = true;
            result[1].text = input.text.slice(1);
            result[2].matched.push(cur);
        }

        return result;
    }
}

export function whitespace(outerAction?: ParserAction): Parser {
    return (input: ParserInput, output: ParserOutput, action?: ParserAction): ParseResult => {
        let result: ParseResult = [false, input.copy(), output.copy()];

        if (input.text.length > 0) {
            let cur = input.text.slice(0,1);
            if (' \t\n\r\v'.indexOf(cur) > -1) {
                result[0] = true;
                result[1].text = result[1].text.slice(1);
                result[2].matched.push(cur);
            }
        }

        return result;
    }
}

Changes to tests/test.ts.

281
282
283
284
285
286
287
288







289




























    allTest() {
        let tryResult = this.parsers.parse(this.numericSequence, "1234Hello!");
        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[1].text, "Hello!");
        this.areIdentical(tryResult[2].matched.length, 1);
        this.areIdentical(tryResult[2].matched[0], "1234");
    }
}











































|
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
    allTest() {
        let tryResult = this.parsers.parse(this.numericSequence, "1234Hello!");
        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[1].text, "Hello!");
        this.areIdentical(tryResult[2].matched.length, 1);
        this.areIdentical(tryResult[2].matched[0], "1234");
    }

    wsTest() {
        let tryParser = pcomb.all(pcomb.whitespace());
        let tryResult = this.parsers.parse(tryParser, "   ");
        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[1].text.length, 0);
        this.areIdentical(tryResult[2].matched.length, 1);
        this.areIdentical(tryResult[2].matched[0].length, 3);

        tryParser = pcomb.and(this.litName, pcomb.whitespace(), this.litValue);
        tryResult = this.parsers.parse(tryParser, "name value");
        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[1].text.length, 0);
        this.areIdentical(tryResult[2].matched.length, 3);
        this.areIdentical(tryResult[2].matched[0], "name");
        this.areIdentical(tryResult[2].matched[1].length, 1);
        this.areIdentical(tryResult[2].matched[2], "value");

        tryResult = this.parsers.parse(tryParser, "name\tvalue");
        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[1].text.length, 0);
        this.areIdentical(tryResult[2].matched.length, 3);
        this.areIdentical(tryResult[2].matched[0], "name");
        this.areIdentical(tryResult[2].matched[1].length, 1);
        this.areIdentical(tryResult[2].matched[2], "value");

        tryParser = pcomb.and(this.litName, pcomb.all(pcomb.whitespace()), this.litValue);
        tryResult = this.parsers.parse(tryParser, 'name\n \t\v \rvalue');
        this.isTrue(tryResult[0]);
        this.areIdentical(tryResult[1].text.length, 0);
        this.areIdentical(tryResult[2].matched.length, 3);
        this.areIdentical(tryResult[2].matched[0], "name");
        this.areIdentical(tryResult[2].matched[1].length, 6);
        this.areIdentical(tryResult[2].matched[2], "value");
   }
}