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.

chaiscript.go 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package c
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Chaiscript lexer.
  7. var Chaiscript = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "ChaiScript",
  10. Aliases: []string{"chai", "chaiscript"},
  11. Filenames: []string{"*.chai"},
  12. MimeTypes: []string{"text/x-chaiscript", "application/x-chaiscript"},
  13. DotAll: true,
  14. },
  15. Rules{
  16. "commentsandwhitespace": {
  17. {`\s+`, Text, nil},
  18. {`//.*?\n`, CommentSingle, nil},
  19. {`/\*.*?\*/`, CommentMultiline, nil},
  20. {`^\#.*?\n`, CommentSingle, nil},
  21. },
  22. "slashstartsregex": {
  23. Include("commentsandwhitespace"),
  24. {`/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/([gim]+\b|\B)`, LiteralStringRegex, Pop(1)},
  25. {`(?=/)`, Text, Push("#pop", "badregex")},
  26. Default(Pop(1)),
  27. },
  28. "badregex": {
  29. {`\n`, Text, Pop(1)},
  30. },
  31. "root": {
  32. Include("commentsandwhitespace"),
  33. {`\n`, Text, nil},
  34. {`[^\S\n]+`, Text, nil},
  35. {`\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|\.\.(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?`, Operator, Push("slashstartsregex")},
  36. {`[{(\[;,]`, Punctuation, Push("slashstartsregex")},
  37. {`[})\].]`, Punctuation, nil},
  38. {`[=+\-*/]`, Operator, nil},
  39. {`(for|in|while|do|break|return|continue|if|else|throw|try|catch)\b`, Keyword, Push("slashstartsregex")},
  40. {`(var)\b`, KeywordDeclaration, Push("slashstartsregex")},
  41. {`(attr|def|fun)\b`, KeywordReserved, nil},
  42. {`(true|false)\b`, KeywordConstant, nil},
  43. {`(eval|throw)\b`, NameBuiltin, nil},
  44. {"`\\S+`", NameBuiltin, nil},
  45. {`[$a-zA-Z_]\w*`, NameOther, nil},
  46. {`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
  47. {`0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
  48. {`[0-9]+`, LiteralNumberInteger, nil},
  49. {`"`, LiteralStringDouble, Push("dqstring")},
  50. {`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
  51. },
  52. "dqstring": {
  53. {`\$\{[^"}]+?\}`, LiteralStringInterpol, nil},
  54. {`\$`, LiteralStringDouble, nil},
  55. {`\\\\`, LiteralStringDouble, nil},
  56. {`\\"`, LiteralStringDouble, nil},
  57. {`[^\\"$]+`, LiteralStringDouble, nil},
  58. {`"`, LiteralStringDouble, Pop(1)},
  59. },
  60. },
  61. ))