Skip to content

Commit 1d00078

Browse files
authored
Merge pull request #138 from KubaO/staging
Use tB IDE themes for syntax highlighting.
2 parents 4b78287 + deab8b4 commit 1d00078

9 files changed

Lines changed: 1248 additions & 7 deletions

File tree

docs/_plugins/twinbasic.rb

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33

44
require "rouge"
55

6+
# Register tB-specific token types so the highlighter can distinguish symbols
7+
# the way the twinBASIC IDE's theme system does -- e.g. Boolean / Empty /
8+
# Nothing / Null are each their own slot in tB's Symbol* palette, and the
9+
# line-continuation '_' has its own SymbolContinuationCharacter colour.
10+
module Rouge::Token::Tokens
11+
[
12+
[Literal, :Boolean, 'lb'],
13+
[Literal, :Empty, 'le'],
14+
[Literal, :Nothing, 'ln'],
15+
[Literal, :Null, 'lu'],
16+
[Punctuation, :LineContinuation, 'lc'],
17+
].each do |parent, name, shortname|
18+
parent.token(name, shortname) unless parent.const_defined?(name, false)
19+
end
20+
end
21+
622
module Rouge
723
module Lexers
824
class TwinBasic < RegexLexer
@@ -17,20 +33,30 @@ def self.keywords
1733
@keywords ||= Set.new %w(
1834
alias byref byval call case class close coclass const
1935
continue declare default delegate dim do each else elseif
20-
empty end endif enum erase error event exit extends
21-
false finally for friend function get global gosub
36+
end endif enum erase error event exit extends
37+
finally for friend function get global gosub
2238
goto handles if implements imports inherits input interface
2339
let lib line lock loop me mid module
24-
namespace new next nothing null of on open option optional
40+
namespace new next of on open option optional
2541
overloads paramarray preserve print private property public
2642
put raiseevent redim resume return select set
2743
shared static step stop structure sub
28-
then throw to true try type unlock until
44+
then throw to try type unlock until
2945
using wend when while width
3046
with withevents write
3147
)
3248
end
3349

50+
def self.keyword_constants
51+
@keyword_constants ||= {
52+
'true' => Literal::Boolean,
53+
'false' => Literal::Boolean,
54+
'empty' => Literal::Empty,
55+
'nothing' => Literal::Nothing,
56+
'null' => Literal::Null,
57+
}
58+
end
59+
3460
def self.keywords_type
3561
@keywords_type ||= Set.new %w(
3662
any boolean byte currency date decimal double integer long
@@ -54,7 +80,7 @@ def self.builtins
5480
id = /[a-z_]\w*/i
5581

5682
state :whitespace do
57-
rule %r/_[ \t]*\n/, Keyword
83+
rule %r/_[ \t]*\n/, Punctuation::LineContinuation
5884
rule %r/\n/, Text, :bol
5985
rule %r/[^\S\n]+/, Text
6086
rule %r/rem\b.*?$/i, Comment::Single
@@ -72,12 +98,15 @@ def self.builtins
7298
rule %r(
7399
[#]If\b .*? \bThen
74100
| [#]ElseIf\b .*? \bThen
101+
| [#]Else\b
75102
| [#]End \s+ If
76103
| [#]Const
77104
| [#]Region .*? \n
78105
| [#]End \s+ Region
79106
)xi, Comment::Preproc
80107

108+
rule %r/#\d[^#\n]*#/, Literal::Date
109+
81110
rule %r/\[/, Punctuation, :attribute
82111

83112
rule %r/(\d+\.\d*|\d*\.\d+)(e[+-]?\d+)?[!#@]?/i, Num::Float
@@ -103,7 +132,9 @@ def self.builtins
103132

104133
rule id do |m|
105134
key = m[0].downcase
106-
if self.class.keywords.include? key
135+
if (kc = self.class.keyword_constants[key])
136+
token kc
137+
elsif self.class.keywords.include? key
107138
token Keyword
108139
elsif self.class.keywords_type.include? key
109140
token Keyword::Type
@@ -157,7 +188,9 @@ def self.builtins
157188
rule %r/\d+[%&!#@]?/, Num::Integer
158189
rule id do |m|
159190
key = m[0].downcase
160-
if self.class.keywords.include? key
191+
if (kc = self.class.keyword_constants[key])
192+
token kc
193+
elsif self.class.keywords.include? key
161194
token Keyword
162195
elsif self.class.keywords_type.include? key
163196
token Keyword::Type
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/* twinBASIC Dark theme - Rouge syntax highlighting */
2+
/* Selectors are the Rouge HTML formatter classes emitted by docs/_plugins/twinbasic.rb. */
3+
/* Scoped under .language-tb .highlight so they only repaint tB fenced code blocks. */
4+
5+
.language-tb .highlight {
6+
.c1 { /* SymbolComment — ' comments and REM */
7+
color: #448a63;
8+
font-style: normal;
9+
font-weight: normal;
10+
text-decoration: none;
11+
}
12+
13+
.cm { /* SymbolComment — C-style block comments */
14+
color: #448a63;
15+
font-style: normal;
16+
font-weight: normal;
17+
text-decoration: none;
18+
}
19+
20+
.cp { /* SymbolConditionalCompilationDirective — #If / #ElseIf / #Else / #End If / #Const / #Region */
21+
color: #ad8c98;
22+
font-style: normal;
23+
font-weight: normal;
24+
text-decoration: none;
25+
}
26+
27+
.k { /* SymbolKeyword — Dim, If, End, Sub, ... */
28+
color: #6c8eda;
29+
font-style: normal;
30+
font-weight: normal;
31+
text-decoration: none;
32+
}
33+
34+
.kd { /* SymbolKeyword — Option Strict / Explicit / Compare / Base */
35+
color: #6c8eda;
36+
font-style: normal;
37+
font-weight: normal;
38+
text-decoration: none;
39+
}
40+
41+
.kt { /* SymbolBuiltInDataType — Boolean, Integer, String, ... */
42+
color: #b1551f;
43+
font-style: normal;
44+
font-weight: normal;
45+
text-decoration: none;
46+
}
47+
48+
.lb { /* SymbolLiteralBoolean — True, False */
49+
color: #c495d3;
50+
font-style: normal;
51+
font-weight: normal;
52+
text-decoration: none;
53+
}
54+
55+
.lc { /* SymbolContinuationCharacter — '_' line-continuation marker */
56+
color: #808080;
57+
font-style: normal;
58+
font-weight: normal;
59+
text-decoration: none;
60+
}
61+
62+
.ld { /* SymbolLiteralDate — #m/d/yyyy [h:mm:ss am/pm]# date-time literals */
63+
color: #c495d3;
64+
font-style: normal;
65+
font-weight: normal;
66+
text-decoration: none;
67+
}
68+
69+
.le { /* SymbolLiteralEmpty — Empty */
70+
color: #c495d3;
71+
font-style: normal;
72+
font-weight: normal;
73+
text-decoration: none;
74+
}
75+
76+
.ln { /* SymbolLiteralNothing — Nothing */
77+
color: #c495d3;
78+
font-style: normal;
79+
font-weight: normal;
80+
text-decoration: none;
81+
}
82+
83+
.lu { /* SymbolLiteralNull — Null */
84+
color: #c495d3;
85+
font-style: normal;
86+
font-weight: normal;
87+
text-decoration: none;
88+
}
89+
90+
.mi { /* SymbolLiteralNumeric — integer literals */
91+
color: #aeca89;
92+
font-style: normal;
93+
font-weight: normal;
94+
text-decoration: none;
95+
}
96+
97+
.mf { /* SymbolLiteralNumeric — float literals */
98+
color: #aeca89;
99+
font-style: normal;
100+
font-weight: normal;
101+
text-decoration: none;
102+
}
103+
104+
.s { /* SymbolLiteralString — string literals */
105+
color: #aeca89;
106+
font-style: oblique;
107+
font-weight: normal;
108+
text-decoration: none;
109+
}
110+
111+
.se { /* SymbolLiteralString — "" escape inside string literals */
112+
color: #aeca89;
113+
font-style: oblique;
114+
font-weight: normal;
115+
text-decoration: none;
116+
}
117+
118+
.o { /* SymbolOperator — +, -, =, <, >, &, ... */
119+
color: #80a1a5;
120+
font-style: normal;
121+
font-weight: normal;
122+
text-decoration: none;
123+
}
124+
125+
.ow { /* SymbolNamedOperator — And, Or, Not, Is, Mod, ... */
126+
color: #80a1a5;
127+
font-style: normal;
128+
font-weight: normal;
129+
text-decoration: none;
130+
}
131+
132+
.na { /* SymbolAttribute — [Documentation(...)] attribute names */
133+
color: #5c5c53;
134+
font-style: normal;
135+
font-weight: normal;
136+
text-decoration: none;
137+
}
138+
139+
.nb { /* SymbolClass — Debug, Err */
140+
color: #e4c685;
141+
font-style: normal;
142+
font-weight: normal;
143+
text-decoration: none;
144+
}
145+
146+
.nc { /* SymbolClass — Class / CoClass / Enum / Interface / Type / Structure names */
147+
color: #e4c685;
148+
font-style: normal;
149+
font-weight: normal;
150+
text-decoration: none;
151+
}
152+
153+
.nf { /* SymbolFunction — Function / Sub / Property names */
154+
color: #cf9a5d;
155+
font-style: normal;
156+
font-weight: normal;
157+
text-decoration: none;
158+
}
159+
160+
.nn { /* SymbolModule — Module / Namespace / Imports targets */
161+
color: #a8a887;
162+
font-style: normal;
163+
font-weight: normal;
164+
text-decoration: none;
165+
}
166+
167+
.nv { /* SymbolVariable — Dim / Const / ReDim variable names */
168+
color: #8b8b52;
169+
font-style: normal;
170+
font-weight: normal;
171+
text-decoration: none;
172+
}
173+
}
174+
175+
/* tB CodePanelBackColor scoped to tB code-block containers (.language-tb). */
176+
/* The .language-tb class lives on the outer .highlighter-rouge div emitted */
177+
/* by kramdown for ```tb``` fenced blocks, so `.language-tb.highlighter-rouge` */
178+
/* (no space) hits the outer container and `.language-tb <descendant>` hits */
179+
/* the nested .highlight / pre / etc. The partial is imported inside */
180+
/* `html.dark-mode { ... }` by just-the-docs-combined.scss, so SCSS nesting */
181+
/* confines these rules to dark mode automatically. */
182+
.language-tb.highlighter-rouge,
183+
.language-tb .highlight,
184+
.language-tb pre.highlight,
185+
.language-tb .highlight pre {
186+
background-color: rgb(33, 33, 33);
187+
}

0 commit comments

Comments
 (0)