public ScriptToken(ScriptTokenType type, string value, int index, int length) { _type = type; _value = value; _index = index; _length = length; }
private void SkipBlock(ScriptTokenType start, ScriptTokenType stop) { if (_current.Type != start) { throw new InvalidOperationException("Expected block."); } var nesting = 0; while (true) { if (_current.Type == start) { nesting++; } if (_current.Type == stop) { nesting--; } if (nesting == 0) { break; } if (!Read()) { break; } } }
public BinaryOperatorExpression(ScriptTokenType op, Expression left, Expression right) : base(left.Start, right.End) { Operation = op; Left = left; Right = right; }
private static bool IsCastable(ScriptTokenType token) { return(token == ScriptTokenType.Identifier || token == ScriptTokenType.Number || token == ScriptTokenType.Null || token == ScriptTokenType.LeftParen || token == ScriptTokenType.SingleString || token == ScriptTokenType.String); }
/// <summary> /// Take a token from the stream. Throws an exception if the given type does not match the token type. /// </summary> public ScriptToken Take(ScriptTokenType type) { var token = Take(); if (token.Type != type) { throw new CompilerException(token, CompilerError.ExpectedButFound, type, token); } return(token); }
/// <summary> /// Check if the next token matches the given type. If they match, take the token. /// </summary> public bool MatchAndTake(ScriptTokenType type) { var isMatch = Match(type); if (isMatch) { Take(); } return(isMatch); }
private ScriptBlock ParseStatement(ScriptTokenType type) { switch (type) { case ScriptTokenType.If: case ScriptTokenType.While: { return(ParseConditionalScope()); } case ScriptTokenType.Switch: { return(ParseConditionalScope(requireBraces: true)); } case ScriptTokenType.Else: { return(ParseElseStatement()); } } throw new InvalidOperationException("Unknown statement type."); }
public IEnumerable <T> ParseSeparatedBy <T>(ScriptTokenType separator, Func <Parser, bool, T> parseFunc) where T : class { var first = parseFunc(this, true); if (first == null) { yield break; } yield return(first); while (MatchAndTake(separator)) { var next = parseFunc(this, false); if (next == null) { yield break; } yield return(next); } }
/// <summary> /// Check if the next token matches the given type. /// </summary> public bool Match(ScriptTokenType type, int distance = 0) { return(Peek(distance).Type == type); }
static void RegisterInfix(ScriptTokenType type, IInfixParselet parselet) { _infixParselets.Add(type, parselet); }
static void RegisterPrefix(ScriptTokenType type, IPrefixParselet parselet) { _prefixParselets.Add(type, parselet); }
static void RegisterStatement(ScriptTokenType type, IStatementParselet parselet) { _statementParselets.Add(type, parselet); }
static void RegisterDeclaration(ScriptTokenType type, IDeclarationParselet parselet) { _declarationParselets.Add(type, parselet); }