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