public static LexmeType MatchingCloseLexme(LexmeType type) { //for now we are just assuming one ending type for each starting type, ignore the array if (PairedLexmes.ContainsKey(type)) { return(PairedLexmes[type][0]); } return(LexmeType.none); }
public static bool ValidMatchingCloseLexme(LexmeType start, LexmeType end) { if (!RequiresClosing(start)) { return(true); } if (end == MatchingCloseLexme(start)) { return(true); } return(false); }
/// <summary> /// /// </summary> /// <param name="sToken"></param> /// <param name="lineNumber"></param> /// <param name="pairState">A mini state machine used to see how to process lexmes when /// we are waiting for closing pairs of lexmes</param> /// <returns></returns> private LexmeType IdentifyType(Scanner.Token sToken, int lineNumber, GreedyLexmePair greedy) //LexmeType pairState) { LexmeType type = LexmeType.none; string data = sToken.Data.ToString(); //switch statements... ruining good code since 1967. (good thing this isn't good code ;) switch (sToken.Type) { case Stellarmass.LPC.Scanner.TokenType.Whitespace: { type = LexmeType.Whitespace; break; } case Stellarmass.LPC.Scanner.TokenType.NewLine: { type = LexmeType.NewLine; //converting from '\n' back to a standard type for this environment //sToken.Data = new StringBuilder(Environment.NewLine); break; } case Stellarmass.LPC.Scanner.TokenType.Number: { type = LexmeType.NumberLiteral; break; } case Stellarmass.LPC.Scanner.TokenType.Word: { if (LPC.LPCKeywords.IsInstruction(data)) { type = LexmeType.Instruction; } else if (LPC.LPCKeywords.IsDataType(data)) { type = LexmeType.DataType; } else if (LPC.LPCKeywords.IsKeyword(data)) { type = LexmeType.Keyword; } else { type = LexmeType.Identifier; } break; } case Stellarmass.LPC.Scanner.TokenType.Symbol: { if (LPC.LPCKeywords.IsOperator(data)) { type = LexmeType.Operator; if (data == "(") { type = LexmeType.OpenParen; } if (data == ")") { type = LexmeType.CloseParen; } if (data == "{") { type = LexmeType.OpenBrace; } if (data == "}") { type = LexmeType.CloseBrace; } if (data == "[") { type = LexmeType.OpenBracket; } if (data == "]") { type = LexmeType.CloseBracket; } if (data == "<") { type = LexmeType.OpenChevron; } if (data == ">") { type = LexmeType.CloseChevron; } } else if (LPC.LPCKeywords.IsSymbol(data)) { switch (data) { //special cases for apostrophes, slashes, and backslashes case "\'": { type = LexmeType.SingleQuote; break; } case "\\'": { type = LexmeType.SingleQuote; break; } case "\\": { type = LexmeType.EscapeCharacter; break; } case "\"": { type = LexmeType.Quote; break; } case "#": { type = LexmeType.PreprocessLine; break; } default: { type = LexmeType.Symbol; break; } } } else if (LPC.LPCKeywords.IsCommentMark(data)) { switch (data) { case "/*": { type = LexmeType.OpenComment; break; } case "*/": { type = LexmeType.CloseComment; break; } case "//": { type = LexmeType.CommentLine; break; } default: { if (greedy.Active) { type = LexmeType.Grouped; } else { throw new LexerException(string.Format(LexerException.UnknownTokenParsed, (string)data)); } break; } } } else { switch (data) { //special cases for apostrophes, slashes, and backslashes case "\'": { type = LexmeType.SingleQuote; break; } case "\\'": { type = LexmeType.SingleQuote; break; } case "\\": { type = LexmeType.EscapeCharacter; break; } default: { if (greedy.Active) { type = LexmeType.Grouped; } else { throw new LexerException(string.Format(LexerException.UnknownTokenParsed, (string)data)); } break; } } } break; } default: { if (greedy.Active) { type = LexmeType.Grouped; } else { throw new LexerException(string.Format(LexerException.UnknownTokenParsed, (string)data)); } break; } } return(type); }
public static bool RequiresClosing(LexmeType type) { return(PairedLexmes.ContainsKey(type)); }