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.

ceylon.go 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package c
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Ceylon lexer.
  7. var Ceylon = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "Ceylon",
  10. Aliases: []string{"ceylon"},
  11. Filenames: []string{"*.ceylon"},
  12. MimeTypes: []string{"text/x-ceylon"},
  13. DotAll: true,
  14. },
  15. Rules{
  16. "root": {
  17. {`^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)([a-zA-Z_]\w*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil},
  18. {`[^\S\n]+`, Text, nil},
  19. {`//.*?\n`, CommentSingle, nil},
  20. {`/\*`, CommentMultiline, Push("comment")},
  21. {`(shared|abstract|formal|default|actual|variable|deprecated|small|late|literal|doc|by|see|throws|optional|license|tagged|final|native|annotation|sealed)\b`, NameDecorator, nil},
  22. {`(break|case|catch|continue|else|finally|for|in|if|return|switch|this|throw|try|while|is|exists|dynamic|nonempty|then|outer|assert|let)\b`, Keyword, nil},
  23. {`(abstracts|extends|satisfies|super|given|of|out|assign)\b`, KeywordDeclaration, nil},
  24. {`(function|value|void|new)\b`, KeywordType, nil},
  25. {`(assembly|module|package)(\s+)`, ByGroups(KeywordNamespace, Text), nil},
  26. {`(true|false|null)\b`, KeywordConstant, nil},
  27. {`(class|interface|object|alias)(\s+)`, ByGroups(KeywordDeclaration, Text), Push("class")},
  28. {`(import)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
  29. {`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
  30. {`'\\.'|'[^\\]'|'\\\{#[0-9a-fA-F]{4}\}'`, LiteralStringChar, nil},
  31. {"\".*``.*``.*\"", LiteralStringInterpol, nil},
  32. {`(\.)([a-z_]\w*)`, ByGroups(Operator, NameAttribute), nil},
  33. {`[a-zA-Z_]\w*:`, NameLabel, nil},
  34. {`[a-zA-Z_]\w*`, Name, nil},
  35. {`[~^*!%&\[\](){}<>|+=:;,./?-]`, Operator, nil},
  36. {`\d{1,3}(_\d{3})+\.\d{1,3}(_\d{3})+[kMGTPmunpf]?`, LiteralNumberFloat, nil},
  37. {`\d{1,3}(_\d{3})+\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?`, LiteralNumberFloat, nil},
  38. {`[0-9][0-9]*\.\d{1,3}(_\d{3})+[kMGTPmunpf]?`, LiteralNumberFloat, nil},
  39. {`[0-9][0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?`, LiteralNumberFloat, nil},
  40. {`#([0-9a-fA-F]{4})(_[0-9a-fA-F]{4})+`, LiteralNumberHex, nil},
  41. {`#[0-9a-fA-F]+`, LiteralNumberHex, nil},
  42. {`\$([01]{4})(_[01]{4})+`, LiteralNumberBin, nil},
  43. {`\$[01]+`, LiteralNumberBin, nil},
  44. {`\d{1,3}(_\d{3})+[kMGTP]?`, LiteralNumberInteger, nil},
  45. {`[0-9]+[kMGTP]?`, LiteralNumberInteger, nil},
  46. {`\n`, Text, nil},
  47. },
  48. "class": {
  49. {`[A-Za-z_]\w*`, NameClass, Pop(1)},
  50. },
  51. "import": {
  52. {`[a-z][\w.]*`, NameNamespace, Pop(1)},
  53. },
  54. "comment": {
  55. {`[^*/]`, CommentMultiline, nil},
  56. {`/\*`, CommentMultiline, Push()},
  57. {`\*/`, CommentMultiline, Pop(1)},
  58. {`[*/]`, CommentMultiline, nil},
  59. },
  60. },
  61. ))