public StringSelection TryParseOperator(StringLocation loc) { var ch = loc.Select(1); if (!ch.IsValid) { return(loc.Select()); } if (":?;()[],{}=.><".Contains(ch.Text)) { return(ch); } return(loc.Select()); }
public StringSelection TryParseComment(StringLocation loc) { var commentStart = loc.Select().ExtendIfAfterEqualsTo("/*"); if (commentStart.IsEmpty) { return(commentStart); } var comment = commentStart.ExtendUntilIncluding("*/"); return(comment); }
public StringSelection TryParseComment2(StringLocation loc) { var commentStart = loc.Select().ExtendIfAfterEqualsTo("//"); if (commentStart.IsEmpty) { return(commentStart); } var comment = commentStart.ExtendCharsUntil(ch => "\r\n".Contains(ch)); return(comment); }
public StringSelection TryParseStringLiteral(StringLocation loc) { var s = loc.Select().ExtendIfAfterEqualsTo("\""); if (s.IsEmpty) { return(s); } s = s.ExtendCharsUntil(ch => ch == '\"'); s = s.ExtendBy(1); return(s); }
public static List <Token> Tokenize(string code) { var tokenTypes = TsTokenTypes.TypeScript; var loc2 = new StringLocation(code, 0); var tokens = new List <Token>(); while (!loc2.IsAtEnd) { var token = NextToken(loc2, tokenTypes); if (token == null) { throw new Exception("Cannot parse: {" + loc2.Select(30).Text + "}"); } tokens.Add(token); loc2 = token.Selection.End; } tokens = tokens.Where(t => t.IsNot(tokenTypes.Whitespace)).ToList(); return(tokens); }
public StringSelection TryParseIdentifier(StringLocation loc) { return(loc.Select().ExtendCharsAsLongAs(ch => "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$".Contains(ch))); }
public StringSelection TryParseWhitespace(StringLocation loc) { return(loc.Select().ExtendCharsAsLongAs(ch => "\r\n ".Contains(ch))); }
public StringSelection TryParseArgAny(StringLocation loc) { return(loc.Select().ExtendIfAfterEqualsTo("...")); }
public StringSelection TryParseLambdaOperator(StringLocation loc) { return(loc.Select().ExtendIfAfterEqualsTo("=>")); }