public Token(TokenDescriptor descriptor, int line, int column, string value) { Descriptor = descriptor; Line = line; Column = column; Value = value; }
public ParsingState <T> WhenNextTokenIs(TokenDescriptor descriptor, Action <ParsingState <T> > action) { // Ignore white spaces InvokeIfMatching(descriptor, action); return(this); }
private bool IsDeclModifier(TokenDescriptor tokenDescriptor) { return(tokenDescriptor.Kind == TokenKind.Keyword && (tokenDescriptor == TokenDescriptor.InternalKeyword || tokenDescriptor == TokenDescriptor.PublicKeyword || tokenDescriptor == TokenDescriptor.ProtectedKeyword || tokenDescriptor == TokenDescriptor.PrivateKeyword || tokenDescriptor == TokenDescriptor.AbstractKeyword )); }
public ParsingState <T> Expect(TokenDescriptor descriptor, Action <ParsingState <T> >?action = null) { if (InvokeIfMatching(descriptor, action)) { return(this); } var actualToken = _lexer.PeekToken(); throw new CaliParseException($"Expected '{descriptor.ReportableName}' but found '{actualToken.Value}'", 0, 0); }
private bool InvokeIfMatching(TokenDescriptor descriptor, Action <ParsingState <T> >?action) { // Ignore white spaces while (_lexer.PeekToken().Descriptor == TokenDescriptor.Space) { _lexer.NextToken(); } if (_lexer.PeekToken().Descriptor == descriptor) { action?.Invoke(this); return(true); } return(false); }
public ParsingState <T> Expect(TokenDescriptor descriptor, Action <T, Token> action) { // Ignore white spaces while (_lexer.PeekToken().Descriptor == TokenDescriptor.Space) { _lexer.NextToken(); } if (_lexer.PeekToken().Descriptor == descriptor) { action(Syntax, _lexer.NextToken()); } else { throw new CaliParseException( $"Expecting '{descriptor.ReportableName}' but found '{_lexer.PeekToken().Value}'", _lexer.PeekToken()); } return(this); }
internal TokenState(Lexer lexer, TokenDescriptor descriptor) { _lexer = lexer; Descriptor = descriptor; }