public static Tokens.CodeBlock Parse(string value) { var lexer = new Lexer(value); return _Parse(lexer); }
private static Tokens.CodeBlock _Parse(Lexer lexer) { var tokens = new List<IToken>(); while (lexer.HaveTokens) { var token = lexer.Parse(); if (token == null || token.Length == 0) throw new LexerException("Failed to read token"); BigInteger result; if (token[0] == '\'') tokens.Add(new Tokens.Symbol(token.Substring(1))); else if (token[0] == '`') tokens.Add(new Tokens.Number(token[1])); else if (BigInteger.TryParse(token, out result)) tokens.Add(new Tokens.Number(result)); else if (token == "}") break; else if (token == "{") tokens.Add(_Parse(lexer)); else if (token[0] == '"') { tokens.Add(new Tokens.PackedBlock(Encoding.UTF8.GetBytes(token.Substring(1)).Select(a => new Tokens.Number(a)))); } else tokens.Add(new Tokens.Method(token)); } return new Tokens.CodeBlock(tokens); }