MCPcopy Index your code
hub / github.com/lutzroeder/netron / parse

Method parse

source/python.js:685–713  ·  view source on GitHub ↗
(text, file, debug, mode)

Source from the content-addressed store, hash-verified

683 };
684 }
685 parse(text, file, debug, mode) {
686 this._tokenizer = new ast._Tokenizer(text, file);
687 this._debug = debug;
688 const position = this._position();
689 let body = [];
690 while (!this._tokenizer.match('eof')) {
691 const statement = this._parseStatement();
692 if (statement) {
693 body.push(statement);
694 continue;
695 }
696 if (this._tokenizer.accept('\n') || this._tokenizer.accept(';') || this._tokenizer.peek().type === 'eof') {
697 continue;
698 }
699 if (this._tokenizer.accept('indent') && this._tokenizer.peek().type === 'eof') {
700 continue;
701 }
702 throw new python.Error(`Unsupported statement ${this._location()}`);
703 }
704 if (mode === 'eval') {
705 if (body.length !== 1 || body[0] instanceof ast.Expr === false) {
706 throw new python.Error('Expected expression.');
707 }
708 body = body[0].value;
709 }
710 const module = new ast.Module(body);
711 this._mark(module, position);
712 return module;
713 }
714 _parseSuite() {
715 const body = [];
716 let statement = null;

Callers

nothing calls this directly

Calls 11

_positionMethod · 0.80
_parseStatementMethod · 0.80
_markMethod · 0.80
text_strMethod · 0.80
filenameMethod · 0.80
matchMethod · 0.45
pushMethod · 0.45
acceptMethod · 0.45
peekMethod · 0.45
_locationMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected