rework of syntax highlighting, almost done
This commit is contained in:
parent
9db2d08a57
commit
516f259bb5
2
dub.json
2
dub.json
@ -15,7 +15,7 @@
|
|||||||
"libs-windows": [],
|
"libs-windows": [],
|
||||||
"preGenerateCommands-linux": ["./build.sh"],
|
"preGenerateCommands-linux": ["./build.sh"],
|
||||||
"preGenerateCommands-windows": [],
|
"preGenerateCommands-windows": [],
|
||||||
"dflags": ["-Xcc=-mno-sse", "-P-I/usr/include/freetype2"],
|
"dflags": ["-Xcc=-mno-sse", "-P-I/usr/include/freetype2", "-Jbuild"],
|
||||||
"dflags-dmd": ["-P=-DSTBI_NO_SIMD"]
|
"dflags-dmd": ["-P=-DSTBI_NO_SIMD"]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Subproject commit c0d9de9c4e7fd33e3329745496e601431f6e2970
|
Subproject commit 79d128c872e10075e29d19616645d82cb53e3450
|
||||||
@ -1 +1 @@
|
|||||||
Subproject commit 16820bdde294d59425fda6e115ae7b2d1e532e51
|
Subproject commit f3b7536c8e4edea80d3b7ef3e4265e521a050c03
|
||||||
File diff suppressed because it is too large
Load Diff
@ -212,51 +212,55 @@ DrawText(Editor* ed, f32 x, f32 y, f32 px, string str)
|
|||||||
void
|
void
|
||||||
DrawBuffer(Editor* ed, f32 x, f32 y, f32 px, FlatBuffer* fb)
|
DrawBuffer(Editor* ed, f32 x, f32 y, f32 px, FlatBuffer* fb)
|
||||||
{
|
{
|
||||||
const Vec4[TT.max] cols = [
|
const Vec4[TS.max] cols = [
|
||||||
TT.None: Vec4(1.0, 1.0, 1.0, 1.0),
|
TS.None: Vec4(1.0, 1.0, 1.0, 1.0),
|
||||||
TT.ImportTarget: Vec4(0.4, 0.7, 0.2, 1.0),
|
TS.ImportTarget: Vec4(0.4, 0.7, 0.2, 1.0),
|
||||||
TT.Keyword: Vec4(1.0, 0.0, 0.0, 1.0),
|
TS.Keyword: Vec4(1.0, 0.0, 0.0, 1.0),
|
||||||
TT.Bracket: Vec4(0.3, 0.3, 0.3, 1.0),
|
TS.Bracket: Vec4(0.3, 0.3, 0.3, 1.0),
|
||||||
TT.String: Vec4(0.2, 0.6, 0.2, 1.0),
|
TS.String: Vec4(0.2, 0.6, 0.2, 1.0),
|
||||||
TT.Number: Vec4(0.2, 0.3, 0.8, 1.0),
|
TS.Char: Vec4(0.3, 0.5, 0.5, 1.0),
|
||||||
TT.Function: Vec4(0.4, 0.3, 0.7, 1.0),
|
TS.Number: Vec4(0.2, 0.3, 0.8, 1.0),
|
||||||
TT.Identifier: Vec4(0.8, 0.4, 0.5, 1.0),
|
TS.Function: Vec4(0.4, 0.3, 0.7, 1.0),
|
||||||
|
TS.Identifier: Vec4(0.8, 0.4, 0.5, 1.0),
|
||||||
|
TS.Macro: Vec4(0.1, 0.3, 0.3, 1.0),
|
||||||
|
TS.Op: Vec4(0.5, 0.8, 0.2, 1.0),
|
||||||
|
TS.Comment: Vec4(0.3, 0.3, 0.3, 1.0),
|
||||||
|
TS.Type: Vec4(1.0, 1.0, 0.5, 1.0),
|
||||||
];
|
];
|
||||||
|
|
||||||
u32 tab_count = 2;
|
u32 tab_count = 2;
|
||||||
f32 x_pos = x;
|
f32 x_pos = x;
|
||||||
f32 y_pos = y;
|
f32 y_pos = y + px;
|
||||||
f32 scale = px / ed.atlas_buf.atlas.size;
|
f32 scale = px / ed.atlas_buf.atlas.size;
|
||||||
|
|
||||||
foreach(i; 0 .. fb.length)
|
foreach(i; 0 .. fb.length)
|
||||||
{
|
{
|
||||||
u8 ch = fb.data[i];
|
u8 ch = fb.data[i];
|
||||||
|
|
||||||
foreach(glyph; ed.atlas_buf.atlas.glyphs)
|
if (ch > 0 && ch < ed.atlas_buf.atlas.glyphs.length)
|
||||||
{
|
{
|
||||||
if (ch == glyph.ch)
|
Glyph* g = ed.atlas_buf.atlas.glyphs.ptr + ch;
|
||||||
|
|
||||||
|
if (g.advance > 0.0)
|
||||||
{
|
{
|
||||||
if (ch == '\t')
|
if (ch == '\t')
|
||||||
{
|
{
|
||||||
Glyph g = glyph;
|
|
||||||
g.atlas_left = g.atlas_right = 0.0;
|
g.atlas_left = g.atlas_right = 0.0;
|
||||||
foreach(j; 0 .. tab_count)
|
foreach(j; 0 .. tab_count)
|
||||||
{
|
{
|
||||||
DrawGlyph(ed, &g, scale, &x_pos, y_pos);
|
DrawGlyph(ed, g, scale, &x_pos, y_pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ch == '\n')
|
else if (ch == '\n')
|
||||||
{
|
{
|
||||||
Glyph g = glyph;
|
|
||||||
g.atlas_left = g.atlas_right = 0.0;
|
g.atlas_left = g.atlas_right = 0.0;
|
||||||
DrawGlyph(ed, &g, scale, &x_pos, y_pos);
|
DrawGlyph(ed, g, scale, &x_pos, y_pos);
|
||||||
y_pos += px;
|
y_pos += px;
|
||||||
x_pos = 0.0;
|
x_pos = 0.0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DrawGlyph(ed, &glyph, scale, &x_pos, y_pos, cols[fb.tk.buffer[i]]);
|
DrawGlyph(ed, g, scale, &x_pos, y_pos, cols[fb.tk.buffer[i]]);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
70
test/files/syntax_highlighting.d
Normal file
70
test/files/syntax_highlighting.d
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import std.stdio;
|
||||||
|
|
||||||
|
@nogc: bool
|
||||||
|
Test()
|
||||||
|
{
|
||||||
|
int x = 5;
|
||||||
|
int y = 10;
|
||||||
|
|
||||||
|
x = x + y;
|
||||||
|
x = x - y;
|
||||||
|
x = x / y;
|
||||||
|
x = x * y;
|
||||||
|
x = x % y;
|
||||||
|
|
||||||
|
x += y;
|
||||||
|
x -= y;
|
||||||
|
x /= y;
|
||||||
|
x *= y;
|
||||||
|
x %= y;
|
||||||
|
|
||||||
|
x = x & y;
|
||||||
|
x = x | y;
|
||||||
|
x = x ^ y;
|
||||||
|
x = ~x;
|
||||||
|
x ~= x;
|
||||||
|
|
||||||
|
// Commented here
|
||||||
|
if (x > 1L && y < 2u || x <= 3U && y >= 4Lu || x == 5LU && x != 6uL || x == 7UL)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float z = 10.5F;
|
||||||
|
float w = 11.25f;
|
||||||
|
real r = 200.55L;
|
||||||
|
|
||||||
|
z = e+102.5;
|
||||||
|
z = e-00.25;
|
||||||
|
|
||||||
|
int hex = 0x555;
|
||||||
|
int hex2 = 0X555;
|
||||||
|
|
||||||
|
int hexp = p+0X5555;
|
||||||
|
hexp = p-0x555;
|
||||||
|
|
||||||
|
string str_literal = r"Teststring";
|
||||||
|
string str = "test string";
|
||||||
|
char ch = 'c';
|
||||||
|
|
||||||
|
u8[] array = [
|
||||||
|
1, 2, 3, 4, 5
|
||||||
|
];
|
||||||
|
|
||||||
|
array[5] = 22;
|
||||||
|
|
||||||
|
int value = WithParameters(z, str);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int WithParameters(float x, string y)
|
||||||
|
{
|
||||||
|
assert(y.length > 0, "String must not be empty");
|
||||||
|
return cast(int)(x) - y[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
T MacroFunc(T)(T x)
|
||||||
|
{
|
||||||
|
return x;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user