private void parseGrammarDefinitionLine(GrammarInterpreter grammarInterpreter, string textLine) { string grammarName = textLine.TrimStart(GRAMMARSTART.ToCharArray()).Trim(); if (!grammarName.Equals(BASEGRAMMARNAME)) { grammarInterpreter.addParentInterpreter(loadGrammarFile(grammarName)); } }
/* * private void parseExtensionLine(GrammarInterpreter grammarInterpreter, string secondLine) * { * string extensionLine = secondLine.TrimStart(INCLUDESTART.ToCharArray()).Trim(); * string[] extensionNames = extensionLine.Split(','); * string grammarExtensionName = ""; * foreach (string extensionName in extensionNames) * { * grammarExtensionName = extensionName.Trim(); * // load grammar extension * List<string> extensionLines = loadGrammarFile(EXTENSIONDIRECTORY, grammarExtensionName, EXTENSIONENDING, grammarInterpreter.GrammarErrors); * loadGrammar(grammarInterpreter, grammarExtensionName, extensionLines); * } * } * * * private bool IsExtensionDefinitionLine(string secondLine) * { * if (secondLine.StartsWith(INCLUDESTART)) * { * return true; * } * else * { * return false; * } * } */ private void parseTokenSplitterLine(GrammarInterpreter grammarInterpreter, string textLine) { string tokenSplitterLine = textLine.TrimStart(TOKENSPLITTERSTART.ToCharArray()).Trim(); switch (tokenSplitterLine) { case "None": grammarInterpreter.TokenSplitter = TokenSplitterType.None; break; case "Space": grammarInterpreter.TokenSplitter = TokenSplitterType.Space; break; default: grammarInterpreter.TokenSplitter = TokenSplitterType.Regex; grammarInterpreter.RegexTokenSplitter = tokenSplitterLine; break; } }
public void addParentInterpreter(GrammarInterpreter grammarInterpreter) { _parent = grammarInterpreter; }
private GrammarInterpreter loadGrammar(GrammarInterpreter grammarInterpreter, string grammarName, List <string> lineList) { if (lineList == null) { throw new ArgumentNullException("lineList must exist", "lineList"); } grammarInterpreter.GrammarName = grammarName; int lineNumber = 1; // read first line string firstLine = ""; if (lineList.Count >= lineNumber) { firstLine = lineList[lineNumber - 1]; if (IsGrammarDefinitionLine(firstLine)) { // Create parent grammar interpreter parseGrammarDefinitionLine(grammarInterpreter, firstLine); } else { grammarInterpreter.addError(new GrammarError(grammarName, lineNumber, "Expected grammar definition line")); } lineNumber += 1; } // read second line string secondLine = ""; if (lineList.Count >= lineNumber) { secondLine = lineList[lineNumber - 1]; if (IsTokenSplitterDefinitionLine(secondLine)) { lineNumber += 1; // Add extensions if needed parseTokenSplitterLine(grammarInterpreter, secondLine); } else if (IsEmptyLine(secondLine)) { // Do nothing } else { grammarInterpreter.addError(new GrammarError(grammarName, lineNumber, "Expected empty line or token splitter line")); } } // read second or third line string secondOrThirdLine = ""; if (lineList.Count >= lineNumber) { secondOrThirdLine = lineList[lineNumber - 1]; if (IsEmptyLine(secondOrThirdLine)) { // do nothing } else { grammarInterpreter.addError(new GrammarError(grammarName, lineNumber, "Expected empty line")); } lineNumber += 1; } grammarInterpreter.addGrammar(grammarName, lineNumber, lineList); return(grammarInterpreter); }
private GrammarInterpreter loadGrammar(string grammarName, List <string> lineList, List <GrammarError> grammarErrors) { GrammarInterpreter grammarInterpreter = new GrammarInterpreter(grammarErrors); return(loadGrammar(grammarInterpreter, grammarName, lineList)); }