45 lines
795 B
JavaScript
45 lines
795 B
JavaScript
import { StreamLanguage } from '@codemirror/language'
|
|
|
|
// 简单的.env语法高亮
|
|
const envLanguage = StreamLanguage.define({
|
|
token(stream) {
|
|
// 注释
|
|
if (stream.match(/^\s*#.*/)) {
|
|
return 'comment'
|
|
}
|
|
|
|
// 变量名
|
|
if (stream.match(/^[A-Z_][A-Z0-9_]*/)) {
|
|
return 'variableName'
|
|
}
|
|
|
|
// 等号
|
|
if (stream.match(/=/)) {
|
|
return 'operator'
|
|
}
|
|
|
|
// 字符串
|
|
if (stream.match(/^"[^"]*"/) || stream.match(/^'[^']*'/)) {
|
|
return 'string'
|
|
}
|
|
|
|
// 布尔值
|
|
if (stream.match(/^(true|false)\b/i)) {
|
|
return 'keyword'
|
|
}
|
|
|
|
// 数字
|
|
if (stream.match(/^\d+(\.\d+)?/)) {
|
|
return 'number'
|
|
}
|
|
|
|
// 跳过其他字符
|
|
stream.next()
|
|
return null
|
|
}
|
|
})
|
|
|
|
export function env() {
|
|
return envLanguage
|
|
}
|