<commit_before>'use strict';

var word = require('./word');

function interpret (str, done) {
    var w, wordLink;

    this.io.buf = str;
    this.io.ptr = 0;
    this.io.last = str.length - 1;
    while (true) {
        w = this.io.word('\\s');
        if (w === undefined) {
            if (typeof done === 'function') {
                done();
            }
            return;
        }
        wordLink = this.O[w.toLowerCase()];
        if (this.state) { // compile
            if (wordLink) {
                if (wordLink.immediate) {
                    this[wordLink.index]();
                } else {
                   this.pos.push({
                       type: 'ExpressionStatement',
                       expression: {
                           type: 'CallExpression',
                           callee: {
                               type: 'MemberExpression',
                               computed: true,
                               object: {
                                   type: 'ThisExpression'
                               },
                               property: {
                                   type: 'Literal',
                                   value: wordLink.index,
                                   raw: wordLink.index + ''
                               }
                           },
                           arguments: []
                       }
                   });
               }
            } else {
                if (Number.isNaN(Number(w))) {
                    console.log('word: ' + w + ' is not defined');
                    throw new Error;
                } else {
                    this.pos.push({
                        type: 'ExpressionStatement',
                        expression: {
                            type: 'CallExpression',
                            callee: {
                                type: 'MemberExpression',
                                computed: false,
                                object: {
                                    type: 'ThisExpression'
                                },
                                property: {
                                    type: 'Identifier',
                                    name: 'dpush'
                                }
                            },
                            arguments: [
                                {
                                    type: 'Literal',
                                    value: Number(w),
                                    raw: w
                                }
                            ]
                        }
                    });
                }
            }
        } else { // interpret
            if (wordLink) {
                this[wordLink.index]();
            } else {
                this.dpush(Number(w));
            }
        }
    }
}

function main (cxt) {
    cxt.io = {
        buf: 'nop',
        ptr: 0,
        last: 2,
        word: word.str
    };
    cxt.state = 0; // 0 = interpret, 1 = compile
    cxt.interpret = interpret;
}

module.exports = main;
<commit_msg>using estarverse syntax and exposing parse<commit_after>'use strict';

var word = require('./word'),
    estraverse = require('estraverse');

var Syntax = estraverse.Syntax;

function dpush (e) {
    return {
        type: Syntax.ExpressionStatement,
        expression: {
            type: Syntax.CallExpression,
            callee: {
                type: Syntax.MemberExpression,
                computed: false,
                object: {
                    type: Syntax.ThisExpression
                },
                property: {
                    type: Syntax.Identifier,
                    name: 'dpush'
                }
            },
            arguments: [
                {
                    type: Syntax.Literal,
                    value: Number(e),
                    raw: e
                }
            ]
        }
    };
}

function callword (e) {
    return {
        type: Syntax.ExpressionStatement,
        expression: {
            type: Syntax.CallExpression,
            callee: {
                type: Syntax.MemberExpression,
                computed: true,
                object: {
                    type: Syntax.ThisExpression
                },
                property: {
                    type: Syntax.Literal,
                    value: e,
                    raw: e + ''
                }
            },
            arguments: []
        }
    };
}

function interpret (str, done) {
    var w, wordLink;

    this.io.buf = str;
    this.io.ptr = 0;
    this.io.last = str.length - 1;
    while (true) {
        w = this.io.word('\\s');
        if (w === undefined) {
            if (typeof done === 'function') {
                done();
            }
            return;
        }
        wordLink = this.O[w.toLowerCase()];
        if (this.state) { // compile
            if (wordLink) {
                if (wordLink.immediate) {
                    this[wordLink.index]();
                } else {
                   this.pos.push(callword(wordLink.index));
               }
            } else {
                if (Number.isNaN(Number(w))) {
                    console.log('word: ' + w + ' is not defined');
                    throw new Error;
                } else {
                    this.pos.push(dpush(w));
                }
            }
        } else { // interpret
            if (wordLink) {
                this[wordLink.index]();
            } else {
                this.dpush(Number(w));
            }
        }
    }
}

function main (cxt) {
    cxt.io = {
        buf: 'nop',
        ptr: 0,
        last: 2,
        parse: word.take,
        word: word.str
    };
    cxt.state = 0; // 0 = interpret, 1 = compile
    cxt.interpret = interpret;
}

module.exports = main;

{'fraction_non_alphanumeric': 0.10242403550699898, 'fraction_numerical': 0.002389894161829976, 'mean_word_length': 0.7510460251046025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2079892', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1376, 'n_words': 284}