MCPcopy Create free account
hub / github.com/nwutils/nw-sample-apps / tokenBase

Function tokenBase

mini-code-edit/cm/mode/python/python.js:54–154  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

tokenStringFactoryFunction · 0.85
dedentFunction · 0.70

Tested by

no test coverage detected