-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8764fe0
Showing
562 changed files
with
55,265 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#'Std'; | ||
|
||
idCode = " | ||
state = 0; | ||
|
||
do | ||
{ | ||
if (state == 0 && | ||
((currentChar >= 'a' && currentChar <= 'z') || | ||
(currentChar >= 'A' && currentChar <= 'Z') || | ||
currentChar == '_' || | ||
(currentChar >= '\\u007f' && currentChar <= '\\uffff'))) | ||
state = 1; | ||
else if (state == 1 && | ||
((currentChar >= 'a' && currentChar <= 'z') || | ||
(currentChar >= 'A' && currentChar <= 'Z') || | ||
(currentChar >= '0' && currentChar <= '9') || | ||
currentChar == '_' || | ||
(currentChar >= '\\u007f' && currentChar <= '\\uffff'))) | ||
state = 1; | ||
else if (state == 1 || state == 2) | ||
{ | ||
charIndex--; | ||
|
||
return AphidTokenType.Identifier; | ||
} | ||
else | ||
{ | ||
break; | ||
} | ||
} | ||
while (NextChar()); | ||
"; | ||
|
||
zeroXCode = " | ||
currentChar = text[++charIndex]; | ||
state = 0; | ||
|
||
do | ||
{ | ||
if ((state == 0 || state == 1) && | ||
((currentChar > 47 && currentChar < 58) || | ||
(64 < currentChar && currentChar < 71) || | ||
(96 < currentChar && currentChar < 103))) | ||
state = 1; | ||
else if (state == 1) | ||
{ | ||
charIndex--; | ||
|
||
return AphidTokenType.HexNumber; | ||
} | ||
else | ||
{ | ||
charIndex--; | ||
|
||
return AphidTokenType.Unknown; | ||
} | ||
} | ||
while (NextChar()); | ||
"; | ||
|
||
singleLineCommentCode = " | ||
state = 0; | ||
while (NextChar()) | ||
{ | ||
if (currentChar == '\\r' || currentChar == '\\n') | ||
{ | ||
PreviousChar(); | ||
|
||
return AphidTokenType.Comment; | ||
} | ||
else if (currentChar == '?') | ||
{ | ||
state = 1; | ||
} | ||
else if (state == 1 && currentChar == '>') | ||
{ | ||
charIndex -= 2; | ||
|
||
return AphidTokenType.Comment; | ||
} | ||
else | ||
{ | ||
state = 0; | ||
} | ||
} | ||
|
||
return AphidTokenType.Comment; | ||
"; | ||
|
||
commentCode = " | ||
state = 0; | ||
|
||
while (NextChar()) | ||
{ | ||
if ((state == 0 || state == 1) && currentChar == '*') | ||
state = 1; | ||
else if (state == 1 && currentChar == '/') | ||
return AphidTokenType.Comment; | ||
else | ||
state = 0; | ||
} | ||
|
||
return AphidTokenType.Comment; | ||
"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#'Std'; | ||
|
||
keywordHelperTmpl = " | ||
NextChar(); | ||
state = 0; | ||
|
||
do | ||
{{ | ||
if (((currentChar >= 'a' && currentChar <= 'z') || | ||
(currentChar >= 'A' && currentChar <= 'Z') || | ||
(currentChar >= '0' && currentChar <= '9') || | ||
currentChar == '_' || | ||
(currentChar >= '\\u007f' && currentChar <= '\\uffff'))) | ||
{{ | ||
state = 1; | ||
}} | ||
else if (state == 1) | ||
{{ | ||
charIndex--; | ||
|
||
return AphidTokenType.Identifier; | ||
}} | ||
else | ||
{{ | ||
charIndex--; | ||
|
||
return AphidTokenType.{0}; | ||
}} | ||
}} | ||
while (NextChar()); | ||
"; | ||
|
||
getKeywordHelper = @(type) sprintf(keywordHelperTmpl, type); | ||
|
||
stringTmpl = " | ||
{0} escaped = false; | ||
|
||
while (NextChar()) | ||
{{ | ||
if (!escaped && currentChar == '{1}') | ||
return AphidTokenType.String; | ||
|
||
escaped = !escaped && currentChar == '\\\\'; | ||
}} | ||
|
||
return AphidTokenType.String; | ||
"; | ||
|
||
firstStr = true; | ||
|
||
getString = @(delim) { | ||
regex; | ||
escapedDelim; | ||
escapedType; | ||
|
||
if (delim == '"') { | ||
regex = '"'; | ||
escapedDelim = '"'; | ||
} else { | ||
regex = "'"; | ||
escapedDelim = "\\'"; | ||
} | ||
|
||
if (firstStr) | ||
{ | ||
firstStr = false; | ||
escapedType = 'bool'; | ||
} | ||
|
||
ret { regex: regex, code: sprintf(stringTmpl, escapedType, escapedDelim) }; | ||
}; | ||
|
||
|
||
numberTmpl = " | ||
state = 0; | ||
|
||
do | ||
{{ | ||
if ((state == 0 || state == 1) && currentChar > 47 && currentChar < 58) | ||
state = 1; | ||
else if (state == 1 && currentChar == '.') | ||
state = 2; | ||
else if (state == 2 || state == 3 && currentChar > 47 && currentChar < 58) | ||
state = 3; | ||
else if ((state == 1 || state == 3) && (currentChar == 'E' || currentChar == 'e')) | ||
{{ | ||
state = 4; | ||
}} | ||
else if (state == 4 && (currentChar == '-' || currentChar == '+')) | ||
{{ | ||
state = 6; | ||
}} | ||
else if (state == 4 && currentChar > 47 && currentChar < 58) | ||
{{ | ||
state = 5; | ||
}} | ||
else if (state == 5 && currentChar > 47 && currentChar < 58) | ||
{{ | ||
continue; | ||
}} | ||
else if (state == 6) | ||
{{ | ||
if (currentChar > 47 && currentChar < 58) | ||
{{ | ||
state = 5; | ||
continue; | ||
}} | ||
else | ||
{{ | ||
return AphidTokenType.Unknown; | ||
}} | ||
}} | ||
else if (state == 1 || state == 3 || state == 5) | ||
{{ | ||
charIndex--; | ||
|
||
return AphidTokenType.Number; | ||
}} | ||
else | ||
{{ | ||
break; | ||
}} | ||
}} | ||
while (NextChar()); | ||
|
||
{0} | ||
"; | ||
|
||
getNumber = @(tail) sprintf(numberTmpl, tail); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#'Std'; | ||
#'Aphid.Tmpl'; | ||
#'Aphid.Code'; | ||
|
||
ret | ||
{ | ||
name: "Components.Aphid.Lexer.Aphid", | ||
modes: | ||
[ | ||
{ | ||
mode: "Aphid", | ||
tokens: | ||
[ | ||
{ regex: "#", type: "LoadScriptOperator" }, | ||
{ regex: "##", type: "LoadLibraryOperator" }, | ||
|
||
{ regex: ",", type: "Comma" }, | ||
{ regex: ":", type: "ColonOperator" }, | ||
{ regex: "@", type: "functionOperator" }, | ||
{ regex: "\\?", type: "ExistsOperator" }, | ||
|
||
{ regex: "\\(", type: "LeftParenthesis" }, | ||
{ regex: "\\)", type: "RightParenthesis" }, | ||
{ regex: "\\[", type: "LeftBracket" }, | ||
{ regex: "\\]", type: "RightBracket" }, | ||
{ regex: "{", type: "LeftBrace" }, | ||
{ regex: "}", type: "RightBrace" }, | ||
|
||
{ regex: "-", type: "MinusOperator" }, | ||
{ regex: "=", type: "AssignmentOperator" }, | ||
{ regex: "\\+=", type: "PlusEqualOperator" }, | ||
{ regex: "-=", type: "MinusEqualOperator" }, | ||
{ regex: "\\*=", type: "MultiplicationEqualOperator" }, | ||
{ regex: "/=", type: "DivisionEqualOperator" }, | ||
{ regex: "%=", type: "ModulusEqualOperator" }, | ||
{ regex: "\\|=", type: "OrEqualOperator" }, | ||
{ regex: "^=", type: "XorEqualOperator" }, | ||
|
||
{ regex: "\\+", type: "AdditionOperator" }, | ||
{ regex: "\\*", type: "MultiplicationOperator" }, | ||
{ regex: "/", type: "DivisionOperator" }, | ||
{ regex: "%", type: "ModulusOperator" }, | ||
{ regex: "\\+\\+", type: "IncrementOperator" }, | ||
{ regex: "--", type: "DecrementOperator" }, | ||
{ regex: "&", type: "BinaryAndOperator" }, | ||
{ regex: "\\|", type: "BinaryOrOperator" }, | ||
{ regex: "^", type: "XorOperator" }, | ||
{ regex: "~", type: "ComplementOperator" }, | ||
{ regex: "<<", type: "ShiftLeft" }, | ||
{ regex: ">>", type: "ShiftRight" }, | ||
{ regex: ".", type: "MemberOperator" }, | ||
|
||
{ regex: "!", type: "NotOperator" }, | ||
{ regex: "&&", type: "AndOperator" }, | ||
{ regex: "\\|\\|", type: "OrOperator" }, | ||
|
||
{ regex: "==", type: "EqualityOperator" }, | ||
{ regex: "!=", type: "NotEqualOperator" }, | ||
{ regex: "<>", type: "NotEqualOperator" }, | ||
{ regex: "<", type: "LessThanOperator" }, | ||
{ regex: ">", type: "GreaterThanOperator" }, | ||
{ regex: "<=", type: "LessThanOrEqualOperator" }, | ||
{ regex: ">=", type: "GreaterThanOrEqualOperator" }, | ||
|
||
{ regex: "\\|>", type: "PipelineOperator" }, | ||
|
||
{ regex: "$", type: "AsyncOperator" }, | ||
{ regex: "$>", type: "JoinOperator" }, | ||
|
||
{ regex: ";", type: "EndOfStatement" }, | ||
|
||
{ regex: "\\r|\\n|\\t|\\v|\\s", type: "WhiteSpace" }, | ||
{ code: idCode }, | ||
{ regex: "0", code: getNumber('return AphidTokenType.Number;') }, | ||
{ regex: "0x", code: zeroXCode }, | ||
{ code: getNumber() }, | ||
getString('"'), | ||
getString("'"), | ||
{ regex: "//", code: singleLineCommentCode }, | ||
{ regex: "/\\*", code: commentCode } | ||
], | ||
keywords: | ||
[ | ||
"true", | ||
"false", | ||
"null", | ||
|
||
"if", | ||
"else", | ||
|
||
"ret", | ||
|
||
"for", | ||
"in", | ||
"break", | ||
|
||
"this", | ||
], | ||
keywordDefault: getKeywordHelper('Identifier'), | ||
keywordTail: getKeywordHelper('{Keyword}') | ||
} | ||
], | ||
ignore: [ "WhiteSpace", "Comment" ] | ||
}; | ||
|
Oops, something went wrong.