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.

gas.go 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package g
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Gas lexer.
  7. var Gas = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "GAS",
  10. Aliases: []string{"gas", "asm"},
  11. Filenames: []string{"*.s", "*.S"},
  12. MimeTypes: []string{"text/x-gas"},
  13. },
  14. Rules{
  15. "root": {
  16. Include("whitespace"),
  17. {`(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+):`, NameLabel, nil},
  18. {`\.(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameAttribute, Push("directive-args")},
  19. {`lock|rep(n?z)?|data\d+`, NameAttribute, nil},
  20. {`(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameFunction, Push("instruction-args")},
  21. {`[\r\n]+`, Text, nil},
  22. },
  23. "directive-args": {
  24. {`(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameConstant, nil},
  25. {`"(\\"|[^"])*"`, LiteralString, nil},
  26. {`@(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameAttribute, nil},
  27. {`(?:0[xX][a-zA-Z0-9]+|\d+)`, LiteralNumberInteger, nil},
  28. {`[\r\n]+`, Text, Pop(1)},
  29. Include("punctuation"),
  30. Include("whitespace"),
  31. },
  32. "instruction-args": {
  33. {`([a-z0-9]+)( )(<)((?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+))(>)`, ByGroups(LiteralNumberHex, Text, Punctuation, NameConstant, Punctuation), nil},
  34. {`([a-z0-9]+)( )(<)((?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+))([-+])((?:0[xX][a-zA-Z0-9]+|\d+))(>)`, ByGroups(LiteralNumberHex, Text, Punctuation, NameConstant, Punctuation, LiteralNumberInteger, Punctuation), nil},
  35. {`(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameConstant, nil},
  36. {`(?:0[xX][a-zA-Z0-9]+|\d+)`, LiteralNumberInteger, nil},
  37. {`%(?:[a-zA-Z$_][\w$.@-]*|\.[\w$.@-]+)`, NameVariable, nil},
  38. {`$(?:0[xX][a-zA-Z0-9]+|\d+)`, LiteralNumberInteger, nil},
  39. {`$'(.|\\')'`, LiteralStringChar, nil},
  40. {`[\r\n]+`, Text, Pop(1)},
  41. Include("punctuation"),
  42. Include("whitespace"),
  43. },
  44. "whitespace": {
  45. {`\n`, Text, nil},
  46. {`\s+`, Text, nil},
  47. {`[;#].*?\n`, Comment, nil},
  48. },
  49. "punctuation": {
  50. {`[-*,.()\[\]!:]+`, Punctuation, nil},
  51. },
  52. },
  53. ))