You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cfengine3.go 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package c
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Cfengine3 lexer.
  7. var Cfengine3 = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "CFEngine3",
  10. Aliases: []string{"cfengine3", "cf3"},
  11. Filenames: []string{"*.cf"},
  12. MimeTypes: []string{},
  13. },
  14. Rules{
  15. "root": {
  16. {`#.*?\n`, Comment, nil},
  17. {`(body)(\s+)(\S+)(\s+)(control)`, ByGroups(Keyword, Text, Keyword, Text, Keyword), nil},
  18. {`(body|bundle)(\s+)(\S+)(\s+)(\w+)(\()`, ByGroups(Keyword, Text, Keyword, Text, NameFunction, Punctuation), Push("arglist")},
  19. {`(body|bundle)(\s+)(\S+)(\s+)(\w+)`, ByGroups(Keyword, Text, Keyword, Text, NameFunction), nil},
  20. {`(")([^"]+)(")(\s+)(string|slist|int|real)(\s*)(=>)(\s*)`, ByGroups(Punctuation, NameVariable, Punctuation, Text, KeywordType, Text, Operator, Text), nil},
  21. {`(\S+)(\s*)(=>)(\s*)`, ByGroups(KeywordReserved, Text, Operator, Text), nil},
  22. {`"`, LiteralString, Push("string")},
  23. {`(\w+)(\()`, ByGroups(NameFunction, Punctuation), nil},
  24. {`([\w.!&|()]+)(::)`, ByGroups(NameClass, Punctuation), nil},
  25. {`(\w+)(:)`, ByGroups(KeywordDeclaration, Punctuation), nil},
  26. {`@[{(][^)}]+[})]`, NameVariable, nil},
  27. {`[(){},;]`, Punctuation, nil},
  28. {`=>`, Operator, nil},
  29. {`->`, Operator, nil},
  30. {`\d+\.\d+`, LiteralNumberFloat, nil},
  31. {`\d+`, LiteralNumberInteger, nil},
  32. {`\w+`, NameFunction, nil},
  33. {`\s+`, Text, nil},
  34. },
  35. "string": {
  36. {`\$[{(]`, LiteralStringInterpol, Push("interpol")},
  37. {`\\.`, LiteralStringEscape, nil},
  38. {`"`, LiteralString, Pop(1)},
  39. {`\n`, LiteralString, nil},
  40. {`.`, LiteralString, nil},
  41. },
  42. "interpol": {
  43. {`\$[{(]`, LiteralStringInterpol, Push()},
  44. {`[})]`, LiteralStringInterpol, Pop(1)},
  45. {`[^${()}]+`, LiteralStringInterpol, nil},
  46. },
  47. "arglist": {
  48. {`\)`, Punctuation, Pop(1)},
  49. {`,`, Punctuation, nil},
  50. {`\w+`, NameVariable, nil},
  51. {`\s+`, Text, nil},
  52. },
  53. },
  54. ))