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

Function tokenBase

mini-code-edit/cm/mode/coffeescript/coffeescript.js:39–164  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

37
38 // Tokenizers
39 function tokenBase(stream, state) {
40 // Handle scope changes
41 if (stream.sol()) {
42 var scopeOffset = state.scopes[0].offset;
43 if (stream.eatSpace()) {
44 var lineOffset = stream.indentation();
45 if (lineOffset > scopeOffset) {
46 return 'indent';
47 } else if (lineOffset < scopeOffset) {
48 return 'dedent';
49 }
50 return null;
51 } else {
52 if (scopeOffset > 0) {
53 dedent(stream, state);
54 }
55 }
56 }
57 if (stream.eatSpace()) {
58 return null;
59 }
60
61 var ch = stream.peek();
62
63 // Handle docco title comment (single line)
64 if (stream.match("####")) {
65 stream.skipToEnd();
66 return 'comment';
67 }
68
69 // Handle multi line comments
70 if (stream.match("###")) {
71 state.tokenize = longComment;
72 return state.tokenize(stream, state);
73 }
74
75 // Single line comment
76 if (ch === '#') {
77 stream.skipToEnd();
78 return 'comment';
79 }
80
81 // Handle number literals
82 if (stream.match(/^-?[0-9\.]/, false)) {
83 var floatLiteral = false;
84 // Floats
85 if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i)) {
86 floatLiteral = true;
87 }
88 if (stream.match(/^-?\d+\.\d*/)) {
89 floatLiteral = true;
90 }
91 if (stream.match(/^-?\.\d+/)) {
92 floatLiteral = true;
93 }
94
95 if (floatLiteral) {
96 // prevent from getting extra . on 1..

Callers

nothing calls this directly

Calls 2

tokenFactoryFunction · 0.85
dedentFunction · 0.70

Tested by

no test coverage detected