Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function ($B) {
- "use strict";
- var _b_ = $B.builtins
- $B._PyPegen_lookahead = function(p, positive, rule) {
- let mark = p.mark;
- let res = rule.apply(p);
- p.mark = mark;
- return (res != null) == positive;
- }
- $B._PyPegen_lookahead_with_arg = function (p, positive, rule, target, arg) {
- let mark = p.mark;
- let res;
- if (target != null) {
- res = rule(target, arg)
- } else {
- res = rule.apply(p, [arg]);
- }
- p.mark = mark;
- return (res != null) == positive;
- }
- $B._PyPegen_expect_token = function(p, type) {
- if (p.mark == p.fill) {
- if ($B._PyPegen_fill_token(p) < 0) {
- p.error_indicator = 1;
- return null;
- }
- }
- let t = p.tokens[p.mark];
- // console.log(t, type);
- if (t.type == 'NUMBER' && type == 'NUMBER') {
- p.mark += 1;
- return t;
- }
- if (t.string != type) {
- return null;
- }
- p.mark += 1;
- return t;
- }
- $B._PyPegen_is_memoized = function (p, type) {
- if (p.mark == p.fill) {
- if ($B._PyPegen_fill_token(p) < 0) {
- p.error_indicator = 1;
- return null;
- }
- }
- let t = p.tokens[p.mark];
- if (t.memo == null) {
- return [null, false]
- }
- if (t.memo[type] === undefined) {
- return [null, false]
- }
- return [t.memo[type], true];
- }
- $B._PyPegen_insert_memo = $B._PyPegen_update_memo = function (p, mark, type, value) {
- let t = p.tokens[mark];
- if (t.memo == null) {
- t.memo = {};
- }
- return t.memo[type] = value;
- }
- $B._PyPegen_name_from_token = function (p, t) {
- throw new Error('fail for now');
- }
- // expr_ty
- // _PyPegen_name_token(Parser * p)
- // {
- // Token * t = _PyPegen_expect_token(p, NAME);
- // return _PyPegen_name_from_token(p, t);
- // }
- $B._PyPegen_expect_soft_keyword = function(p, keyword) {
- if (p.mark == p.fill) {
- if ($B._PyPegen_fill_token(p) < 0) {
- p.error_indicator = 1;
- return null;
- }
- }
- let t = p.tokens[p.mark];
- if (t.type != 'NAME') {
- return null;
- }
- if (t.string == keyword) {
- p.mark += 1;
- return t;
- }
- return null;
- }
- $B._PyPegen_fill_token = function(p) {
- while (true) {
- var next = p.tokenizer.next();
- if (!next.done) {
- var value = next.value;
- if (!['ENCODING', 'NL', 'COMMENT'].includes(value.type)) {
- p.tokens.push(value);
- p.fill += 1;
- break;
- }
- } else {
- throw Error('tokenizer exhausted')
- }
- }
- return 1;
- }
- })(__BRYTHON__)
Advertisement
Add Comment
Please, Sign In to add comment