Skip to content

Commit 8764fe0

Browse files
committed
Initial commit
0 parents  commit 8764fe0

File tree

562 files changed

+55265
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

562 files changed

+55265
-0
lines changed

.gitattributes

+562
Large diffs are not rendered by default.

AphidCodeGenerator/Aphid.Code.alx

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#'Std';
2+
3+
idCode = "
4+
state = 0;
5+
6+
do
7+
{
8+
if (state == 0 &&
9+
((currentChar >= 'a' && currentChar <= 'z') ||
10+
(currentChar >= 'A' && currentChar <= 'Z') ||
11+
currentChar == '_' ||
12+
(currentChar >= '\\u007f' && currentChar <= '\\uffff')))
13+
state = 1;
14+
else if (state == 1 &&
15+
((currentChar >= 'a' && currentChar <= 'z') ||
16+
(currentChar >= 'A' && currentChar <= 'Z') ||
17+
(currentChar >= '0' && currentChar <= '9') ||
18+
currentChar == '_' ||
19+
(currentChar >= '\\u007f' && currentChar <= '\\uffff')))
20+
state = 1;
21+
else if (state == 1 || state == 2)
22+
{
23+
charIndex--;
24+
25+
return AphidTokenType.Identifier;
26+
}
27+
else
28+
{
29+
break;
30+
}
31+
}
32+
while (NextChar());
33+
";
34+
35+
zeroXCode = "
36+
currentChar = text[++charIndex];
37+
state = 0;
38+
39+
do
40+
{
41+
if ((state == 0 || state == 1) &&
42+
((currentChar > 47 && currentChar < 58) ||
43+
(64 < currentChar && currentChar < 71) ||
44+
(96 < currentChar && currentChar < 103)))
45+
state = 1;
46+
else if (state == 1)
47+
{
48+
charIndex--;
49+
50+
return AphidTokenType.HexNumber;
51+
}
52+
else
53+
{
54+
charIndex--;
55+
56+
return AphidTokenType.Unknown;
57+
}
58+
}
59+
while (NextChar());
60+
";
61+
62+
singleLineCommentCode = "
63+
state = 0;
64+
while (NextChar())
65+
{
66+
if (currentChar == '\\r' || currentChar == '\\n')
67+
{
68+
PreviousChar();
69+
70+
return AphidTokenType.Comment;
71+
}
72+
else if (currentChar == '?')
73+
{
74+
state = 1;
75+
}
76+
else if (state == 1 && currentChar == '>')
77+
{
78+
charIndex -= 2;
79+
80+
return AphidTokenType.Comment;
81+
}
82+
else
83+
{
84+
state = 0;
85+
}
86+
}
87+
88+
return AphidTokenType.Comment;
89+
";
90+
91+
commentCode = "
92+
state = 0;
93+
94+
while (NextChar())
95+
{
96+
if ((state == 0 || state == 1) && currentChar == '*')
97+
state = 1;
98+
else if (state == 1 && currentChar == '/')
99+
return AphidTokenType.Comment;
100+
else
101+
state = 0;
102+
}
103+
104+
return AphidTokenType.Comment;
105+
";

AphidCodeGenerator/Aphid.Tmpl.alx

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#'Std';
2+
3+
keywordHelperTmpl = "
4+
NextChar();
5+
state = 0;
6+
7+
do
8+
{{
9+
if (((currentChar >= 'a' && currentChar <= 'z') ||
10+
(currentChar >= 'A' && currentChar <= 'Z') ||
11+
(currentChar >= '0' && currentChar <= '9') ||
12+
currentChar == '_' ||
13+
(currentChar >= '\\u007f' && currentChar <= '\\uffff')))
14+
{{
15+
state = 1;
16+
}}
17+
else if (state == 1)
18+
{{
19+
charIndex--;
20+
21+
return AphidTokenType.Identifier;
22+
}}
23+
else
24+
{{
25+
charIndex--;
26+
27+
return AphidTokenType.{0};
28+
}}
29+
}}
30+
while (NextChar());
31+
";
32+
33+
getKeywordHelper = @(type) sprintf(keywordHelperTmpl, type);
34+
35+
stringTmpl = "
36+
{0} escaped = false;
37+
38+
while (NextChar())
39+
{{
40+
if (!escaped && currentChar == '{1}')
41+
return AphidTokenType.String;
42+
43+
escaped = !escaped && currentChar == '\\\\';
44+
}}
45+
46+
return AphidTokenType.String;
47+
";
48+
49+
firstStr = true;
50+
51+
getString = @(delim) {
52+
regex;
53+
escapedDelim;
54+
escapedType;
55+
56+
if (delim == '"') {
57+
regex = '"';
58+
escapedDelim = '"';
59+
} else {
60+
regex = "'";
61+
escapedDelim = "\\'";
62+
}
63+
64+
if (firstStr)
65+
{
66+
firstStr = false;
67+
escapedType = 'bool';
68+
}
69+
70+
ret { regex: regex, code: sprintf(stringTmpl, escapedType, escapedDelim) };
71+
};
72+
73+
74+
numberTmpl = "
75+
state = 0;
76+
77+
do
78+
{{
79+
if ((state == 0 || state == 1) && currentChar > 47 && currentChar < 58)
80+
state = 1;
81+
else if (state == 1 && currentChar == '.')
82+
state = 2;
83+
else if (state == 2 || state == 3 && currentChar > 47 && currentChar < 58)
84+
state = 3;
85+
else if ((state == 1 || state == 3) && (currentChar == 'E' || currentChar == 'e'))
86+
{{
87+
state = 4;
88+
}}
89+
else if (state == 4 && (currentChar == '-' || currentChar == '+'))
90+
{{
91+
state = 6;
92+
}}
93+
else if (state == 4 && currentChar > 47 && currentChar < 58)
94+
{{
95+
state = 5;
96+
}}
97+
else if (state == 5 && currentChar > 47 && currentChar < 58)
98+
{{
99+
continue;
100+
}}
101+
else if (state == 6)
102+
{{
103+
if (currentChar > 47 && currentChar < 58)
104+
{{
105+
state = 5;
106+
continue;
107+
}}
108+
else
109+
{{
110+
return AphidTokenType.Unknown;
111+
}}
112+
}}
113+
else if (state == 1 || state == 3 || state == 5)
114+
{{
115+
charIndex--;
116+
117+
return AphidTokenType.Number;
118+
}}
119+
else
120+
{{
121+
break;
122+
}}
123+
}}
124+
while (NextChar());
125+
126+
{0}
127+
";
128+
129+
getNumber = @(tail) sprintf(numberTmpl, tail);

AphidCodeGenerator/Aphid.alx

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#'Std';
2+
#'Aphid.Tmpl';
3+
#'Aphid.Code';
4+
5+
ret
6+
{
7+
name: "Components.Aphid.Lexer.Aphid",
8+
modes:
9+
[
10+
{
11+
mode: "Aphid",
12+
tokens:
13+
[
14+
{ regex: "#", type: "LoadScriptOperator" },
15+
{ regex: "##", type: "LoadLibraryOperator" },
16+
17+
{ regex: ",", type: "Comma" },
18+
{ regex: ":", type: "ColonOperator" },
19+
{ regex: "@", type: "functionOperator" },
20+
{ regex: "\\?", type: "ExistsOperator" },
21+
22+
{ regex: "\\(", type: "LeftParenthesis" },
23+
{ regex: "\\)", type: "RightParenthesis" },
24+
{ regex: "\\[", type: "LeftBracket" },
25+
{ regex: "\\]", type: "RightBracket" },
26+
{ regex: "{", type: "LeftBrace" },
27+
{ regex: "}", type: "RightBrace" },
28+
29+
{ regex: "-", type: "MinusOperator" },
30+
{ regex: "=", type: "AssignmentOperator" },
31+
{ regex: "\\+=", type: "PlusEqualOperator" },
32+
{ regex: "-=", type: "MinusEqualOperator" },
33+
{ regex: "\\*=", type: "MultiplicationEqualOperator" },
34+
{ regex: "/=", type: "DivisionEqualOperator" },
35+
{ regex: "%=", type: "ModulusEqualOperator" },
36+
{ regex: "\\|=", type: "OrEqualOperator" },
37+
{ regex: "^=", type: "XorEqualOperator" },
38+
39+
{ regex: "\\+", type: "AdditionOperator" },
40+
{ regex: "\\*", type: "MultiplicationOperator" },
41+
{ regex: "/", type: "DivisionOperator" },
42+
{ regex: "%", type: "ModulusOperator" },
43+
{ regex: "\\+\\+", type: "IncrementOperator" },
44+
{ regex: "--", type: "DecrementOperator" },
45+
{ regex: "&", type: "BinaryAndOperator" },
46+
{ regex: "\\|", type: "BinaryOrOperator" },
47+
{ regex: "^", type: "XorOperator" },
48+
{ regex: "~", type: "ComplementOperator" },
49+
{ regex: "<<", type: "ShiftLeft" },
50+
{ regex: ">>", type: "ShiftRight" },
51+
{ regex: ".", type: "MemberOperator" },
52+
53+
{ regex: "!", type: "NotOperator" },
54+
{ regex: "&&", type: "AndOperator" },
55+
{ regex: "\\|\\|", type: "OrOperator" },
56+
57+
{ regex: "==", type: "EqualityOperator" },
58+
{ regex: "!=", type: "NotEqualOperator" },
59+
{ regex: "<>", type: "NotEqualOperator" },
60+
{ regex: "<", type: "LessThanOperator" },
61+
{ regex: ">", type: "GreaterThanOperator" },
62+
{ regex: "<=", type: "LessThanOrEqualOperator" },
63+
{ regex: ">=", type: "GreaterThanOrEqualOperator" },
64+
65+
{ regex: "\\|>", type: "PipelineOperator" },
66+
67+
{ regex: "$", type: "AsyncOperator" },
68+
{ regex: "$>", type: "JoinOperator" },
69+
70+
{ regex: ";", type: "EndOfStatement" },
71+
72+
{ regex: "\\r|\\n|\\t|\\v|\\s", type: "WhiteSpace" },
73+
{ code: idCode },
74+
{ regex: "0", code: getNumber('return AphidTokenType.Number;') },
75+
{ regex: "0x", code: zeroXCode },
76+
{ code: getNumber() },
77+
getString('"'),
78+
getString("'"),
79+
{ regex: "//", code: singleLineCommentCode },
80+
{ regex: "/\\*", code: commentCode }
81+
],
82+
keywords:
83+
[
84+
"true",
85+
"false",
86+
"null",
87+
88+
"if",
89+
"else",
90+
91+
"ret",
92+
93+
"for",
94+
"in",
95+
"break",
96+
97+
"this",
98+
],
99+
keywordDefault: getKeywordHelper('Identifier'),
100+
keywordTail: getKeywordHelper('{Keyword}')
101+
}
102+
],
103+
ignore: [ "WhiteSpace", "Comment" ]
104+
};
105+

0 commit comments

Comments
 (0)