MCPcopy Index your code
hub / github.com/josdejong/mathjs / tokenBase

Function tokenBase

examples/code_editor/mathjs-lang.js:91–163  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

89 }
90
91 function tokenBase(stream, state) {
92 // whitespaces
93 if (stream.eatSpace()) return null
94
95 // Handle one line Comments
96 if (stream.match('#{')) {
97 state.tokenize = tokenComment
98 stream.skipToEnd()
99 return 'comment'
100 }
101
102 if (stream.match(/^#/)) {
103 stream.skipToEnd()
104 return 'comment'
105 }
106
107 // Handle Number Literals
108 if (stream.match(/^[0-9.+-]/, false)) {
109 if (stream.match(/^[+-]?0x[0-9a-fA-F]+[ij]?/)) {
110 stream.tokenize = tokenBase
111 return 'number'
112 }
113 if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?[ij]?/)) {
114 return 'number'
115 }
116 if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?[ij]?/)) {
117 return 'number'
118 }
119 }
120 if (stream.match(wordRegexp(numberLiterals))) {
121 return 'number'
122 }
123
124 // Handle Strings
125 let m = stream.match(/^"(?:[^"]|"")*("|$)/) || stream.match(/^'(?:[^']|'')*('|$)/)
126 if (m) {
127 return m[1] ? 'string' : 'string error'
128 }
129
130 // Handle words
131 if (stream.match(keywords)) {
132 return 'keyword'
133 }
134 if (stream.match(builtins)) {
135 return 'builtin'
136 }
137 if (stream.match(physicalConstants)) {
138 return 'tag'
139 }
140 if (stream.match(units)) {
141 return 'attribute'
142 }
143 if (stream.match(identifiers)) {
144 return 'variable'
145 }
146 if (stream.match(singleOperators) || stream.match(doubleOperators)) {
147 return 'operator'
148 }

Callers 1

tokenTransposeFunction · 0.85

Calls 1

wordRegexpFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…