MCPcopy
hub / github.com/lutzroeder/netron / _tokenize

Method _tokenize

source/python.js:1922–2057  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1920 return position + 1;
1921 }
1922 _tokenize() {
1923 if (this._token.type !== '\n') {
1924 this._skipWhitespace();
1925 }
1926 if (this._token.type === 'dedent') {
1927 this._indentation.pop();
1928 this._outdent--;
1929 if (this._outdent > 0) {
1930 this._token = { type: 'dedent', value: '' };
1931 return;
1932 }
1933 }
1934 if (this._token.type === '\n') {
1935 let indent = '';
1936 let i = this._position;
1937 while (i < this._text.length) {
1938 const c = this._text[i];
1939 if (ast._Tokenizer._isSpace(c)) {
1940 indent += c;
1941 i++;
1942 } else if (ast._Tokenizer._isNewline(c)) {
1943 indent = '';
1944 i = this._newLine(i);
1945 this._position = i;
1946 this.linepos = i;
1947 this.lineno += 1;
1948 } else if (c === '#') {
1949 indent = '';
1950 while (i < this._text.length && !ast._Tokenizer._isNewline(this._text[i])) {
1951 i++;
1952 }
1953 continue;
1954 } else {
1955 break;
1956 }
1957 }
1958 let type = null;
1959 if (indent.length > 0) {
1960 const current = this._indentation.length > 0 ? this._indentation[this._indentation.length - 1] : '';
1961 if (indent.length > current.length) {
1962 type = 'indent';
1963 this._indentation.push(indent);
1964 } else if (indent.length > 0 && indent.length < current.length) {
1965 type = 'dedent';
1966 this._outdent = 0;
1967 for (let j = this._indentation.length - 1; j >= 0 && indent.length < this._indentation[j].length; j--) {
1968 this._outdent++;
1969 }
1970 } else {
1971 this._position += indent.length;
1972 }
1973 } else if (i >= this._text.length) {
1974 this._token = { type: 'eof', value: '' };
1975 return;
1976 } else if (this._indentation.length > 0) {
1977 type = 'dedent';
1978 this._outdent = this._indentation.length;
1979 }

Callers 2

peekMethod · 0.45
readMethod · 0.45

Calls 12

_operatorMethod · 0.80
_skipWhitespaceMethod · 0.45
popMethod · 0.45
_isSpaceMethod · 0.45
_isNewlineMethod · 0.45
_newLineMethod · 0.45
pushMethod · 0.45
_getMethod · 0.45
_stringMethod · 0.45
_numberMethod · 0.45
_identifierMethod · 0.45
locationMethod · 0.45

Tested by

no test coverage detected