-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSyntax.ahk
65 lines (54 loc) · 1.87 KB
/
Syntax.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#SingleInstance, Prompt
SetBatchLines, -1
#Include lib\Console.ahk
#Include lib\Commands.ahk
Colors := [0x3f3f3f,0x3F85CD,0x688060,0x80d4aa
,0xbc6c4c,0xbc6c9c,0xccdc90,0xdcdccc
,0x9f9f9f,0x87CEEB,0x9ece9e,0x8cd0d3
,0xf18c96,0xbc8cbc,0xf8f893,0xefefef]
Console.SetFont(8, 8)
Console.SetSize(105, 70)
Console.SetColors(Colors)
FileRead, File, %A_ScriptFullPath%
NormalColor := [Console.Colors.White, Console.Colors.Black]
File := RegExReplace(File, "\R", "`n")
Regexes := {"([+*!~&/<>^|=?:,.%(){}\[\]\-]+)": Console.Colors.Aqua
, "m`n)^(\s*#[^\s,\R]+)": Console.Colors.Teal, "\b(0x[0-9A-Fa-f]+|\d+)\b": Console.Colors.Yellow}
for Regex, NewColor in Regexes
File := RegExReplace(File, Regex, Chr(3) Chr(NewColor) "$1" Chr(3) Chr(NormalColor[1]))
for Type, Words in Commands
{
if Type in Flow,Indent
NewColor := Chr(3) Chr(Console.Colors.Lime)
else
NewColor := Chr(3) Chr(Console.Colors.Navy)
StringReplace, Words, Words, %A_Space%, |, All
File := RegExReplace(File, "i)\b(" Words ")\b", NewColor "$1" Chr(3) Chr(NormalColor[1]))
}
File := StrSplit(File)
Console.SetColor(NormalColor*)
Quoted := false, Commented := false
Last := "`n" ; This lets me put comments and similar on the first line in the file.
While ((Char := File.Remove(1)) != "")
{
if (Asc(Char) == 3)
{
NewColor := Asc(File.Remove(1))
if (!Quoted && !Commented)
Console.SetColor(NewColor, NormalColor[2])
}
else
{
if (Char == "`n") ; Newline
Quoted := False, Commented := False, Console.SetColor(NormalColor*)
else if (Char == """" && !Commented) ; This is a comment with "quotes" in it
Quoted := !Quoted, Console.SetColor("Red", NormalColor[2])
else if (Char == ";" && InStr(" `t`n", Last))
Commented := True, Quoted := False, Console.SetColor("Green", NormalColor[2])
Console.Print(Char)
if (Char == """" && !Commented && !Quoted)
Console.SetColor(NormalColor*)
Last := Char
}
}
MsgBox