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