Check-in [3cdeaf46fb]

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

Overview
Comment:[2b12c9d54e] Final changes for implementing all combinator.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3cdeaf46fb61a5f8092cf05e7c6a3c8d9cd044f7
User & Date: CrosslandA 2016-10-10 19:24:11
Context
2016-10-10
19:28
Turned off file system watching. check-in: a3c0274a20 user: CrosslandA tags: trunk
19:24
[2b12c9d54e] Final changes for implementing all combinator. check-in: 3cdeaf46fb user: CrosslandA tags: trunk
17:30
All test still failing. Investigating why. check-in: b62dfde2d3 user: CrosslandA tags: trunk
Changes

Changes to src/pcomb.ts.

37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
...
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
236
237
238
239
240
241
242

















    add(parserApp: ParserApplication): void {
        this.parsers.push(parserApp);
    }

    parse(toTry: Parser, text: string): ParseResult {
        let input = this.inputObj.copy();
        input.text = text;
        let output = this.outputObj.copy();


        let result = toTry(input, output);

        return result;
    }
}

function lastMatched(output: ParserOutput): string {
    let foundMatch: string = null;

    if (output.matched.length > 0) {
        foundMatch = output.matched[output.matched[output.matched.length - 1]];
    }

    return foundMatch;
}

/** Execute all of the given parsers, in order, until one of them
     returns true. A matching parser terminates parsing immediately. */
................................................................................
    }
}

/** Execute the given parser until it fails; return all matched characters as a single match. */
export function all(of: Parser): Parser {
    return (input: ParserInput, output: ParserOutput, action?: ParserAction): ParseResult => {
        let result: ParseResult = [false, input.copy(), output.copy()];

        let matched: string = "";
        let tempInput: ParserInput = input.copy();
        let tempOutput: ParserOutput;
        let eachResult: ParseResult;

        do {
            eachResult = of(tempInput, tempOutput);
            if (eachResult[0]) {
                matched = matched.concat(lastMatched(tempOutput));
                tempInput = eachResult[1];
            }
        } while (eachResult[0]);

        if (matched.length > 0) {
            result[0] = true;
            result[1].text = input.text.slice(matched.length);
................................................................................
                result[2] = newOutput;
            }
        }

        return result;
    }
}
























<

>










|







 







>


|





|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
    add(parserApp: ParserApplication): void {
        this.parsers.push(parserApp);
    }

    parse(toTry: Parser, text: string): ParseResult {
        let input = this.inputObj.copy();
        input.text = text;


        let output = this.outputObj.copy();
        let result = toTry(input, output);

        return result;
    }
}

function lastMatched(output: ParserOutput): string {
    let foundMatch: string = null;

    if (output.matched.length > 0) {
        foundMatch = output.matched[output.matched.length - 1];
    }

    return foundMatch;
}

/** Execute all of the given parsers, in order, until one of them
     returns true. A matching parser terminates parsing immediately. */
................................................................................
    }
}

/** Execute the given parser until it fails; return all matched characters as a single match. */
export function all(of: Parser): Parser {
    return (input: ParserInput, output: ParserOutput, action?: ParserAction): ParseResult => {
        let result: ParseResult = [false, input.copy(), output.copy()];

        let matched: string = "";
        let tempInput: ParserInput = input.copy();
        let tempOutput: ParserOutput = output.copy();
        let eachResult: ParseResult;

        do {
            eachResult = of(tempInput, tempOutput);
            if (eachResult[0]) {
                matched = matched.concat(lastMatched(eachResult[2]));
                tempInput = eachResult[1];
            }
        } while (eachResult[0]);

        if (matched.length > 0) {
            result[0] = true;
            result[1].text = input.text.slice(matched.length);
................................................................................
                result[2] = newOutput;
            }
        }

        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;
    }
}

Changes to tests/test.ts.

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
..
61
62
63
64
65
66
67

68
69
70
71
72
73
74
75
76
77
78
...
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

    private parsers: pcomb.ParserSet;

    private litName: pcomb.Parser;
    private litValue: pcomb.Parser;
    private litValueOther: pcomb.Parser;
    private litColon: pcomb.Parser;
    private litSemicolon;
    private litSpace;
    private nameValuePair: pcomb.Parser;
    private nameValuePair2: pcomb.Parser;
    private eitherNameValuePair: pcomb.Parser;
    private allStoreName: pcomb.Parser;
    private optWsParser: pcomb.Parser;
    private optParser: pcomb.Parser;
    private anyParser1: pcomb.Parser;
................................................................................
    private numericSequence: pcomb.Parser;
    private storeNameValue: (matched: string, output: testOutput) => testOutput;
    private recordWhitespace: (matched: string, output: testOutput) => testOutput;
    private dumbGrabber: (matched: string, output: testOutput) => testOutput;

    constructor() {
        super();

    }

    setUp() {
        this.parsers = new pcomb.ParserSet(this.input.copy(), this.output.copy());
        this.litName = pcomb.lit("name");
        this.litValue = pcomb.lit("value");
        this.litValueOther = pcomb.lit("othervalue");
        this.litColon = pcomb.lit(":");
        this.litSemicolon = pcomb.lit(";");
        this.litSpace = pcomb.lit(" ");
        this.optWsParser = pcomb.opt(this.litSpace);
................................................................................
        this.areIdentical(tryResult2[2].matched[1], ":");
        this.areIdentical(tryResult2[2].matched[2], "value");
        foo = <testOutput>tryResult2[2];
        this.isFalse(foo.containsWhitespace);
    }

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








|
|







 







>



<







 







<

<







43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
..
61
62
63
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
...
275
276
277
278
279
280
281

282

283
284
285
286
287
288
289

    private parsers: pcomb.ParserSet;

    private litName: pcomb.Parser;
    private litValue: pcomb.Parser;
    private litValueOther: pcomb.Parser;
    private litColon: pcomb.Parser;
    private litSemicolon: pcomb.Parser;
    private litSpace: pcomb.Parser;
    private nameValuePair: pcomb.Parser;
    private nameValuePair2: pcomb.Parser;
    private eitherNameValuePair: pcomb.Parser;
    private allStoreName: pcomb.Parser;
    private optWsParser: pcomb.Parser;
    private optParser: pcomb.Parser;
    private anyParser1: pcomb.Parser;
................................................................................
    private numericSequence: pcomb.Parser;
    private storeNameValue: (matched: string, output: testOutput) => testOutput;
    private recordWhitespace: (matched: string, output: testOutput) => testOutput;
    private dumbGrabber: (matched: string, output: testOutput) => testOutput;

    constructor() {
        super();
        this.parsers = new pcomb.ParserSet(this.input.copy(), this.output.copy());
    }

    setUp() {

        this.litName = pcomb.lit("name");
        this.litValue = pcomb.lit("value");
        this.litValueOther = pcomb.lit("othervalue");
        this.litColon = pcomb.lit(":");
        this.litSemicolon = pcomb.lit(";");
        this.litSpace = pcomb.lit(" ");
        this.optWsParser = pcomb.opt(this.litSpace);
................................................................................
        this.areIdentical(tryResult2[2].matched[1], ":");
        this.areIdentical(tryResult2[2].matched[2], "value");
        foo = <testOutput>tryResult2[2];
        this.isFalse(foo.containsWhitespace);
    }

    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");
    }
}