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

Function tokenBase

tools/pythonauto/static/codemirror/python.js:61–168  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

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