Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        public StringSelection TryParseComment(StringLocation loc)
        {
            var commentStart = loc.Select().ExtendIfAfterEqualsTo("/*");

            if (commentStart.IsEmpty)
            {
                return(commentStart);
            }
            var comment = commentStart.ExtendUntilIncluding("*/");

            return(comment);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 public StringSelection TryParseIdentifier(StringLocation loc)
 {
     return(loc.Select().ExtendCharsAsLongAs(ch => "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$".Contains(ch)));
 }
Exemplo n.º 7
0
 public StringSelection TryParseWhitespace(StringLocation loc)
 {
     return(loc.Select().ExtendCharsAsLongAs(ch => "\r\n ".Contains(ch)));
 }
Exemplo n.º 8
0
 public StringSelection TryParseArgAny(StringLocation loc)
 {
     return(loc.Select().ExtendIfAfterEqualsTo("..."));
 }
Exemplo n.º 9
0
 public StringSelection TryParseLambdaOperator(StringLocation loc)
 {
     return(loc.Select().ExtendIfAfterEqualsTo("=>"));
 }