public override bool TryMatchCurrent(LexerBuilder lexer) { if (lexer.Current == '/') { lexer.PeekNext(); if (lexer.Current == '/') { // line comment. read to end of line or file. do { lexer.Commit(); lexer.PeekNext(); }while (!lexer.EndOrNewLine); return(true); } else if (lexer.Current == '*') { // block comment, read until end of file or closing '*/' lexer.PeekNext(); do { lexer.PeekNext(); lexer.Commit(); }while (!lexer.EndOfInput && !(lexer.Current == '/' && lexer.Previous == '*')); return(true); } } return(false); }
public override bool TryMatchCurrent(LexerBuilder lexer) { var prev = lexer.Previous; var first = lexer.Current; // check for keywords if (lexer.IsDelimiter(prev, true) && char.IsLetter(first)) { // can be a keyword... var sb = new StringBuilder(); sb.Append(lexer.Current); while (!lexer.EndOfInput && char.IsLetter(lexer.PeekNext())) { sb.Append(lexer.Current); } if (keywords.Contains(sb.ToString())) { if (!lexer.EndOfInput) { lexer.RollbackBy(1); } lexer.Commit(); return(true); } return(false); } else { return(false); } }
public override bool TryMatchCurrent(LexerBuilder lexer) { // previous character must be delimiter, whitespace, or alphanumeric. if (!lexer.IsDelimiter(lexer.Previous, true, true)) { return(false); } if (IsSymbol(lexer.Current)) { do { lexer.Commit(); lexer.PeekNext(); }while (IsSymbol(lexer.Current)); return(true); } return(false); }
public override bool TryMatchCurrent(LexerBuilder lexer) { // previous character must be whitespace or delimiter if (!lexer.IsDelimiter(lexer.Previous, true)) { return(false); } if (!IsNumeric(lexer.Current)) { return(false); } while (!lexer.EndOfInput) { lexer.Commit(); if (!IsNumeric(lexer.PeekNext())) { break; } } return(true); }
public override bool TryMatchCurrent(LexerBuilder lexer) { if (lexer.Current == '"') { if (lexer.Previous == '@') { // verbatim string, continue until un-escaped quote. while (!lexer.EndOfInput) { lexer.Commit(); if (lexer.PeekNext() == '"') { lexer.Commit(); // possibly the end, check for escaped quotes. // commit the character and flip the escape bool for each quote. bool escaped = false; while (lexer.PeekNext() == '"') { lexer.Commit(); escaped = !escaped; } // if the last quote wasnt escaped, that was the end of the string. if (!escaped) { break; } } } } else { // normal string // continue until a quote which is not escaped, or end of input while (!lexer.EndOfInput) { lexer.Commit(); lexer.PeekNext(); if ((lexer.Current == '"') && lexer.Previous != '\\') { lexer.Commit(); break; } } } return(true); } else if (lexer.Current == '\'') { // char while (!lexer.EndOfInput) { lexer.Commit(); lexer.PeekNext(); if ((lexer.Current == '\'') && lexer.Previous != '\\') { lexer.Commit(); break; } } return(true); } else { return(false); } }