gitea

Development moved to Codeberg

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
package b

import (
	. "github.com/alecthomas/chroma" // nolint
	"github.com/alecthomas/chroma/lexers/internal"
)

// Blitzbasic lexer.
var Blitzbasic = internal.Register(MustNewLazyLexer(
	&Config{
		Name:            "BlitzBasic",
		Aliases:         []string{"blitzbasic", "b3d", "bplus"},
		Filenames:       []string{"*.bb", "*.decls"},
		MimeTypes:       []string{"text/x-bb"},
		CaseInsensitive: true,
	},
	blitzbasicRules,
))

func blitzbasicRules() Rules {
	return Rules{
		"root": {
			{`[ \t]+`, Text, nil},
			{`;.*?\n`, CommentSingle, nil},
			{`"`, LiteralStringDouble, Push("string")},
			{`[0-9]+\.[0-9]*(?!\.)`, LiteralNumberFloat, nil},
			{`\.[0-9]+(?!\.)`, LiteralNumberFloat, nil},
			{`[0-9]+`, LiteralNumberInteger, nil},
			{`\$[0-9a-f]+`, LiteralNumberHex, nil},
			{`\%[10]+`, LiteralNumberBin, nil},
			{Words(`\b`, `\b`, `Shl`, `Shr`, `Sar`, `Mod`, `Or`, `And`, `Not`, `Abs`, `Sgn`, `Handle`, `Int`, `Float`, `Str`, `First`, `Last`, `Before`, `After`), Operator, nil},
			{`([+\-*/~=<>^])`, Operator, nil},
			{`[(),:\[\]\\]`, Punctuation, nil},
			{`\.([ \t]*)([a-z]\w*)`, NameLabel, nil},
			{`\b(New)\b([ \t]+)([a-z]\w*)`, ByGroups(KeywordReserved, Text, NameClass), nil},
			{`\b(Gosub|Goto)\b([ \t]+)([a-z]\w*)`, ByGroups(KeywordReserved, Text, NameLabel), nil},
			{`\b(Object)\b([ \t]*)([.])([ \t]*)([a-z]\w*)\b`, ByGroups(Operator, Text, Punctuation, Text, NameClass), nil},
			{`\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},
			{`\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},
			{`\b(Type)([ \t]+)([a-z]\w*)`, ByGroups(KeywordReserved, Text, NameClass), nil},
			{`\b(Pi|True|False|Null)\b`, KeywordConstant, nil},
			{`\b(Local|Global|Const|Field|Dim)\b`, KeywordDeclaration, nil},
			{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},
			{`([a-z]\w*)(?:([ \t]*)(@{1,2}|[#$%])|([ \t]*)([.])([ \t]*)(?:([a-z]\w*)))?`, ByGroups(NameVariable, Text, KeywordType, Text, Punctuation, Text, NameClass), nil},
		},
		"string": {
			{`""`, LiteralStringDouble, nil},
			{`"C?`, LiteralStringDouble, Pop(1)},
			{`[^"]+`, LiteralStringDouble, nil},
		},
	}
}