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.

blitz.go 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package b
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Blitzbasic lexer.
  7. var Blitzbasic = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "BlitzBasic",
  10. Aliases: []string{"blitzbasic", "b3d", "bplus"},
  11. Filenames: []string{"*.bb", "*.decls"},
  12. MimeTypes: []string{"text/x-bb"},
  13. CaseInsensitive: true,
  14. },
  15. Rules{
  16. "root": {
  17. {`[ \t]+`, Text, nil},
  18. {`;.*?\n`, CommentSingle, nil},
  19. {`"`, LiteralStringDouble, Push("string")},
  20. {`[0-9]+\.[0-9]*(?!\.)`, LiteralNumberFloat, nil},
  21. {`\.[0-9]+(?!\.)`, LiteralNumberFloat, nil},
  22. {`[0-9]+`, LiteralNumberInteger, nil},
  23. {`\$[0-9a-f]+`, LiteralNumberHex, nil},
  24. {`\%[10]+`, LiteralNumberBin, nil},
  25. {Words(`\b`, `\b`, `Shl`, `Shr`, `Sar`, `Mod`, `Or`, `And`, `Not`, `Abs`, `Sgn`, `Handle`, `Int`, `Float`, `Str`, `First`, `Last`, `Before`, `After`), Operator, nil},
  26. {`([+\-*/~=<>^])`, Operator, nil},
  27. {`[(),:\[\]\\]`, Punctuation, nil},
  28. {`\.([ \t]*)([a-z]\w*)`, NameLabel, nil},
  29. {`\b(New)\b([ \t]+)([a-z]\w*)`, ByGroups(KeywordReserved, Text, NameClass), nil},
  30. {`\b(Gosub|Goto)\b([ \t]+)([a-z]\w*)`, ByGroups(KeywordReserved, Text, NameLabel), nil},
  31. {`\b(Object)\b([ \t]*)([.])([ \t]*)([a-z]\w*)\b`, ByGroups(Operator, Text, Punctuation, Text, NameClass), nil},
  32. {`\b([a-z]\w*)(?:([ \t]*)(@{1,2}|[#$%])|([ \t]*)([.])([ \t]*)(?:([a-z]\w*)))?\b([ \t]*)(\()`, ByGroups(NameFunction, Text, KeywordType, Text, Punctuation, Text, NameClass, Text, Punctuation), nil},
  33. {`\b(Function)\b([ \t]+)([a-z]\w*)(?:([ \t]*)(@{1,2}|[#$%])|([ \t]*)([.])([ \t]*)(?:([a-z]\w*)))?`, ByGroups(KeywordReserved, Text, NameFunction, Text, KeywordType, Text, Punctuation, Text, NameClass), nil},
  34. {`\b(Type)([ \t]+)([a-z]\w*)`, ByGroups(KeywordReserved, Text, NameClass), nil},
  35. {`\b(Pi|True|False|Null)\b`, KeywordConstant, nil},
  36. {`\b(Local|Global|Const|Field|Dim)\b`, KeywordDeclaration, nil},
  37. {Words(`\b`, `\b`, `End`, `Return`, `Exit`, `Chr`, `Len`, `Asc`, `New`, `Delete`, `Insert`, `Include`, `Function`, `Type`, `If`, `Then`, `Else`, `ElseIf`, `EndIf`, `For`, `To`, `Next`, `Step`, `Each`, `While`, `Wend`, `Repeat`, `Until`, `Forever`, `Select`, `Case`, `Default`, `Goto`, `Gosub`, `Data`, `Read`, `Restore`), KeywordReserved, nil},
  38. {`([a-z]\w*)(?:([ \t]*)(@{1,2}|[#$%])|([ \t]*)([.])([ \t]*)(?:([a-z]\w*)))?`, ByGroups(NameVariable, Text, KeywordType, Text, Punctuation, Text, NameClass), nil},
  39. },
  40. "string": {
  41. {`""`, LiteralStringDouble, nil},
  42. {`"C?`, LiteralStringDouble, Pop(1)},
  43. {`[^"]+`, LiteralStringDouble, nil},
  44. },
  45. },
  46. ))