Add Golang build in functions support

main
Leonid Maslakov 5 months ago
parent 0cf97f2602
commit b3f8ceb9c1
  1. 31
      highlight_golang.go
  2. 4
      highlight_golang_test.go

@ -100,6 +100,23 @@ package highlight
// rune
// string
//
// Supported built-in functions (const StyleBuildInFunc):
// append
// cap
// close
// complex
// copy
// delete
// imag
// len
// make
// new
// panic
// print
// println
// real
// recover
//
// Also supported:
// Single-line comments (//)
// Multi-line comments (/* */)
@ -148,6 +165,15 @@ func Golang(code string) string {
"string",
}
// Build-in functions
buildInFuncs := []string{
"append", "cap", "close",
"complex", "copy", "delete",
"imag", "len", "make",
"new", "panic", "print",
"println", "real", "recover",
}
// Multi-line comments
code = formatOpenClose(code, "/*", "*/", StyleComment)
@ -176,6 +202,11 @@ func Golang(code string) string {
code = formatWord(code, word, defaultKeywordChars, defaultKeywordChars, StyleVarType)
}
// Build-in functions
for _, word := range buildInFuncs {
code = formatWord(code, word, defaultKeywordChars, defaultKeywordChars, StyleBuildInFunc)
}
// Numbers
code = formatNumber(code, defaultNumberChars, defaultNumberChars)

@ -113,10 +113,10 @@ if myBool == true {
`,
ExpectResult: `
<span class='` + StyleKeyword + `'>if</span> myBool <span class='` + StyleOperator + `'>==</span> <span class='` + StyleValue + `'>true</span> {
println(<span class='` + StyleBrackets + `'>"OK"</span>)
<span class='` + StyleBuildInFunc + `'>println</span>(<span class='` + StyleBrackets + `'>"OK"</span>)
} <span class='` + StyleKeyword + `'>else</span> {
println(<span class='` + StyleBrackets + `'>"FAIL"</span>)
<span class='` + StyleBuildInFunc + `'>println</span>(<span class='` + StyleBrackets + `'>"FAIL"</span>)
}
`,
},

Loading…
Cancel
Save