Files
  • public
  • src
    • App.js
    • App.css
    • index.css
    • index.js
    • logo.svg
  • package.json
src/App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React, {
    Component
} from 'react';
import './App.css';
import {
    Parjs
} from 'parjs';
let Application = /** @class */ (function() {
    function Application(val) {
        this._name = "Application";
        [this.func, this.val] = val;
        // console.log(val,"Application done");
    }
    return Application;
}());
let Definition = /** @class */ (function() {
    function Definition(val) {
        this._name = "Definition";
        [this.arg, this.ret] = val;
        // console.log(val,"Definition done");
    }
    return Definition;
}());
let Letter = /** @class */ (function() {
    function Letter(input) {
        this._name = "Letter";
        this.input = input;
        // console.log(input,"Letter done");
    }
    return Letter;
}());
class App extends Component {
    constructor(props) {
        super(props);
        this.state = {
            input: "\\a.(a a)"
        };
        this.setup = this.setup.bind(this);
    }
    render() {
        return ( <
            div className = "App" >
            <
            input type = "text"
            ref = "input"
            value = {
                this.state.input
            }
            onChange = {
                this.update("input")
            }
            /> <
            button onClick = {
                this.setup
            } > Run < /button> <
            input readOnly type = "text"
            ref = "output" / >
            <
            /div>
        );
    }
    update(name) {
        return (value) => {
            this.setState({
                [name]: value.target.value
            });
        }
    }
    setup() {
        let setName = (i, e) => ({
            action: Object.assign(i.action, {
                _name: e
            })
        });
        let term, exp, def, letter, application, _exp, _term;
        exp = Parjs.late(() => _exp);
        term = Parjs.late(() => _term);
        letter = setName(Parjs.letter, "letter");
        def = setName(Parjs.seq(Parjs.string("\\").q, letter, Parjs.string(".").q, exp).map(i => new Definition(i)).soft, "def");
        application = setName(Parjs.seq(term, Parjs.string(" "), exp).map(i => new Application(i)).soft, "application");
        _exp = setName(Parjs.any(term, application, def), "exp");
        _term = setName(Parjs.any(exp.between("(", ")").soft, letter).soft, "term");
        let res = exp.parse(this.refs.input.value);
        console.log(res);
        if (res.hasOwnProperty("trace")) console.log(Parjs.visualizer(res.trace));

    }
}

export default App;