blob: c258cd2dcf2d28959070fef0f715c2a4955fe911 [file] [log] [blame]
// Copyright 2017-2020 The Verible Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Common defines and tiny helper functions for Bison-based parsers.
#include "common/parser/bison_parser_common.h"
#include "common/parser/parser_param.h"
#include "common/text/concrete_syntax_leaf.h"
#include "common/text/concrete_syntax_tree.h"
#include "common/text/token_info.h"
#include "common/util/logging.h" // for operator<<, etc
namespace verible {
// Lexer interface function, called by Bison-generated parser to get a next
// token. This no longer calls yylex(), but insteads pulls a token from a token
// stream. 'value' points to yylval in yyparse(), which can be accessed as $1,
// $2, ... in the yacc grammar semantic actions.
int LexAdapter(SymbolPtr* value, ParserParam* param) {
const auto& last_token = param->FetchToken();
value->reset(new SyntaxTreeLeaf(last_token));
return last_token.token_enum();
}
// Error-reporting function.
// Called by Bison-generated parser when a recognition error occurs.
void ParseError(const char* function_name, const char* message) {
VLOG(1) << function_name << " error: " << message;
// Bison's default and 'verbose' error messages are uninformative.
// TODO(fangism): print information about rejected token,
// by examining parser stacks (have to pass in stack information).
}
} // namespace verible