public override Token Match(Lexer lexer) { var rem = lexer.RemainingInput; if (lexer.CanRead) { string value = null; var match = singleCharRe.Match(rem); if (match.Success) { value = match.Value; } else if ((match = escapeCharRe.Match(rem)).Success) { value = match.Value; } else if ((match = hexEscapeRe.Match(rem)).Success) { value = match.Value; } else if ((match = unicEscapeRe.Match(rem)).Success) { value = match.Value; } if (null != value) { var tok = new Token() { Line = lexer.Line, Col = lexer.Col }; tok.Sym = Sym.CharLiteral; tok.Value = value.Substring(1, value.Length - 2); ; lexer.Advance(value.Length); return tok; } } return null; }
//TODO: 'Verbatim' string handling (e.g. @"...") public override Token Match(Lexer lexer) { if (lexer.CanRead) { var match = simpleLit.Match(lexer.RemainingInput); if (match.Success) { var tok = new Token() { Line = lexer.Line, Col = lexer.Col }; tok.Sym = Sym.StringLiteral; tok.Value = match.Value.Substring(1, match.Value.Length - 2); lexer.Advance(match.Value.Length); return tok; } } return null; }
public override Token Match(Lexer lexer) { var tok = new Token() { Line = lexer.Line, Col = lexer.Col }; string rem = lexer.RemainingInput; bool isMatch = false; Match match = hexIntLit.Match(rem); if (match.Success) { tok.Value = match.Value; tok.Sym = Sym.HexIntLiteral; isMatch = true; } foreach (var re in realRes) { match = re.Match(rem); if (match.Success) { tok.Value = match.Value; tok.Sym = Sym.RealLiteral; isMatch = true; break; } } if (!isMatch) { match = decIntLit.Match(rem); if (match.Success) { tok.Value = match.Value; tok.Sym = Sym.IntLiteral; isMatch = true; } } if (isMatch) { lexer.Advance(tok.Value.Length); return tok; } return null; }