This commit is contained in:
kudzu_cp 2012-07-08 21:21:27 +00:00
parent 96ea92e02a
commit 9eeaffe4aa
2 changed files with 21 additions and 14 deletions

View file

@ -70,10 +70,15 @@ namespace Cosmos.Compiler.XSharp {
if (EmitXSharpCodeComments && !aLine.StartsWith("#")) {
mOutput.WriteLine("\t\t\tnew Comment(\"X#: " + aLine + "\");");
}
var xCode = mPatterns.GetCode(aLine);
foreach(var xLine in xCode) {
if (xCode == null) {
throw new Exception("Parsing error: " + aLine);
}
foreach (var xLine in xCode) {
mOutput.WriteLine("\t\t\t" + xLine);
}
mOutput.WriteLine();
}

View file

@ -464,28 +464,30 @@ namespace Cosmos.Compiler.XSharp {
});
}
public List<string> GetCode(string aLine) {
var xParser = new Parser(aLine, false, false);
var xTokens = xParser.Tokens;
var xResult = new List<string>();
int xHash = xTokens.GetPatternHashCode();
protected Pattern FindMatch(TokenList aTokens) {
int xHash = aTokens.GetPatternHashCode();
// Get a list of matching hashes, but then we have to
// search for exact pattern match because it is possible
// to have duplicate hashes. Hashes just provide us a quick way
// to reduce the search.
var xPatterns = mPatterns.Where(q => q.Hash == xHash);
Pattern xPattern = null;
foreach (var x in xPatterns) {
if (x.Tokens.PatternMatches(xTokens)) {
xPattern = x;
break;
foreach (var xPattern in mPatterns.Where(q => q.Hash == xHash)) {
if (xPattern.Tokens.PatternMatches(aTokens)) {
return xPattern;
}
}
return null;
}
public List<string> GetCode(string aLine) {
var xParser = new Parser(aLine, false, false);
var xTokens = xParser.Tokens;
var xPattern = FindMatch(xTokens);
if (xPattern == null) {
throw new Exception("Token pattern not found: " + aLine);
return null;
}
var xResult = new List<string>();
xPattern.Code(xTokens, ref xResult);
for(int i = 0; i < xResult.Count; i++) {