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.

awk.go 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package a
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Awk lexer.
  7. var Awk = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "Awk",
  10. Aliases: []string{"awk", "gawk", "mawk", "nawk"},
  11. Filenames: []string{"*.awk"},
  12. MimeTypes: []string{"application/x-awk"},
  13. },
  14. Rules{
  15. "commentsandwhitespace": {
  16. {`\s+`, Text, nil},
  17. {`#.*$`, CommentSingle, nil},
  18. },
  19. "slashstartsregex": {
  20. Include("commentsandwhitespace"),
  21. {`/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/\B`, LiteralStringRegex, Pop(1)},
  22. {`(?=/)`, Text, Push("#pop", "badregex")},
  23. Default(Pop(1)),
  24. },
  25. "badregex": {
  26. {`\n`, Text, Pop(1)},
  27. },
  28. "root": {
  29. {`^(?=\s|/)`, Text, Push("slashstartsregex")},
  30. Include("commentsandwhitespace"),
  31. {`\+\+|--|\|\||&&|in\b|\$|!?~|(\*\*|[-<>+*%\^/!=|])=?`, Operator, Push("slashstartsregex")},
  32. {`[{(\[;,]`, Punctuation, Push("slashstartsregex")},
  33. {`[})\].]`, Punctuation, nil},
  34. {`(break|continue|do|while|exit|for|if|else|return)\b`, Keyword, Push("slashstartsregex")},
  35. {`function\b`, KeywordDeclaration, Push("slashstartsregex")},
  36. {`(atan2|cos|exp|int|log|rand|sin|sqrt|srand|gensub|gsub|index|length|match|split|sprintf|sub|substr|tolower|toupper|close|fflush|getline|next|nextfile|print|printf|strftime|systime|delete|system)\b`, KeywordReserved, nil},
  37. {`(ARGC|ARGIND|ARGV|BEGIN|CONVFMT|ENVIRON|END|ERRNO|FIELDWIDTHS|FILENAME|FNR|FS|IGNORECASE|NF|NR|OFMT|OFS|ORFS|RLENGTH|RS|RSTART|RT|SUBSEP)\b`, NameBuiltin, nil},
  38. {`[$a-zA-Z_]\w*`, NameOther, nil},
  39. {`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
  40. {`0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
  41. {`[0-9]+`, LiteralNumberInteger, nil},
  42. {`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
  43. {`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
  44. },
  45. },
  46. ))