public RantCompiler(string sourceName, string source) { Module = new RantModule(sourceName); _sourceName = sourceName; _reader = new TokenReader(sourceName, RantLexer.GenerateTokens(sourceName, _source = source.ToStringe())); }
/// <summary> /// Reads and returns the next non-whitespace token if its type matches the specified type. /// If it does not match, a RantCompilerException is thrown with the expected token name. /// </summary> /// <param name="type">The token type to read.</param> /// <param name="expectedTokenName">A display name describing what the token is for.</param> /// <returns></returns> public Token ReadLoose(R type, string expectedTokenName = null) { if (End) { _compiler.SyntaxError(Token.None, true, "err-compiler-missing-token-eof", expectedTokenName != null ? GetString(expectedTokenName) : RantLexer.GetSymbolForType(type)); return(Token.None); } SkipSpace(); if (_tokens[Position].Type != type) { _compiler.SyntaxError(_tokens[Position], false, "err-compiler-missing-token", expectedTokenName != null ? GetString(expectedTokenName) : RantLexer.GetSymbolForType(type)); return(Token.None); } var t = _tokens[Position++]; SkipSpace(); return(t); }
public RantCompiler(string sourceName, string source) { _sourceName = sourceName; Source = source; _reader = new TokenReader(sourceName, RantLexer.Lex(this, source), this); }