mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-10 18:21:20 +00:00
X#
This commit is contained in:
parent
80beff8cdd
commit
c7fbdbc2da
2 changed files with 16 additions and 9 deletions
|
|
@ -65,10 +65,7 @@ namespace Cosmos.Compiler.XSharp {
|
|||
var xTokens = xParser.Tokens;
|
||||
|
||||
var xPattern = xTokens.Select(c => c.Type).ToArray();
|
||||
string xCode;
|
||||
if (!mPatterns.TryGetValue(new TokenPattern(xPattern), out xCode)) {
|
||||
throw new Exception("Invalid token pattern in X# file.");
|
||||
}
|
||||
string xCode = mPatterns.GetCode(xPattern);
|
||||
mOutput.WriteLine(xCode, xTokens.Select(c => c.Value).ToArray());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ using System.Linq;
|
|||
using System.Text;
|
||||
|
||||
namespace Cosmos.Compiler.XSharp {
|
||||
public class TokenPatterns : Dictionary<TokenPattern, string> {
|
||||
public class TokenPatterns {
|
||||
protected Dictionary<TokenPattern, string> mList = new Dictionary<TokenPattern, string>();
|
||||
|
||||
public TokenPatterns() {
|
||||
Add(new TokenType[] { TokenType.LiteralAsm }, "new LiteralAssemblerCode(\"{0}\");");
|
||||
Add(new TokenType[] { TokenType.Comment }, "new Comment(\"{0}\");");
|
||||
|
|
@ -22,12 +24,20 @@ namespace Cosmos.Compiler.XSharp {
|
|||
Add(new TokenType[] { TokenType.OpCode }, "//new ;");
|
||||
}
|
||||
|
||||
public void Add(string aTokenTypes, string aCode) {
|
||||
Add(new TokenPattern(aTokenTypes), aCode);
|
||||
public string GetCode(TokenType[] aPattern) {
|
||||
string xResult;
|
||||
if (!mList.TryGetValue(new TokenPattern(aPattern), out xResult)) {
|
||||
throw new Exception("Token pattern not found.");
|
||||
}
|
||||
return xResult;
|
||||
}
|
||||
|
||||
public void Add(TokenType[] aTokenTypes, string aCode) {
|
||||
Add(new TokenPattern(aTokenTypes), aCode);
|
||||
public void Add(string aPattern, string aCode) {
|
||||
mList.Add(new TokenPattern(aPattern), aCode);
|
||||
}
|
||||
|
||||
public void Add(TokenType[] aPattern, string aCode) {
|
||||
mList.Add(new TokenPattern(aPattern), aCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue