MCPcopy Index your code
hub / github.com/csev/py4e / tokenBase

Function tokenBase

tools/pythonauto/static/codemirrorepl/python.js:60–160  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

58
59 // tokenizers
60 function tokenBase(stream, state) {
61 // Handle scope changes
62 if (stream.sol()) {
63 var scopeOffset = state.scopes[0].offset;
64 if (stream.eatSpace()) {
65 var lineOffset = stream.indentation();
66 if (lineOffset > scopeOffset) {
67 indentInfo = 'indent';
68 } else if (lineOffset < scopeOffset) {
69 indentInfo = 'dedent';
70 }
71 return null;
72 } else {
73 if (scopeOffset > 0) {
74 dedent(stream, state);
75 }
76 }
77 }
78 if (stream.eatSpace()) {
79 return null;
80 }
81
82 var ch = stream.peek();
83
84 // Handle Comments
85 if (ch === '#') {
86 stream.skipToEnd();
87 return 'comment';
88 }
89
90 // Handle Number Literals
91 if (stream.match(/^[0-9\.]/, false)) {
92 var floatLiteral = false;
93 // Floats
94 if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
95 if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
96 if (stream.match(/^\.\d+/)) { floatLiteral = true; }
97 if (floatLiteral) {
98 // Float literals may be "imaginary"
99 stream.eat(/J/i);
100 return 'number';
101 }
102 // Integers
103 var intLiteral = false;
104 // Hex
105 if (stream.match(/^0x[0-9a-f]+/i)) { intLiteral = true; }
106 // Binary
107 if (stream.match(/^0b[01]+/i)) { intLiteral = true; }
108 // Octal
109 if (stream.match(/^0o[0-7]+/i)) { intLiteral = true; }
110 // Decimal
111 if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
112 // Decimal literals may be "imaginary"
113 stream.eat(/J/i);
114 // TODO - Can you have imaginary longs?
115 intLiteral = true;
116 }
117 // Zero by itself with no other piece of number.

Callers

nothing calls this directly

Calls 3

dedentFunction · 0.70
tokenStringFactoryFunction · 0.70
nextMethod · 0.45

Tested by

no test coverage detected