parser.h

parser.h

#include <google/protobuf/compiler/parser.h>
namespace google::protobuf::compiler

Implements parsing of .proto files to FileDescriptorProtos.

Classes in this file

Implements parsing of protocol definitions (such as .proto files).
A table mapping (descriptor, ErrorLocation) pairs -- as reported by  DescriptorPool when validating descriptors -- to line and column numbers within the original source code.

class Parser

#include <google/protobuf/compiler/parser.h>
namespace google::protobuf::compiler

Implements parsing of protocol definitions (such as .proto files).

Note that most users will be more interested in the Importer class. Parser is a lower-level class which simply converts a single .proto file to aFileDescriptorProto. It does not resolve import directives or perform many other kinds of validation needed to construct a complete FileDescriptor.

Members

Parser()
~Parser()
bool
Parse(io::Tokenizer * input, FileDescriptorProto * file)
Parse the entire input and construct a  FileDescriptorProto representing it.  more...
void
RecordSourceLocationsTo(SourceLocationTable * location_table)
DEPRECATED: New code should use the  SourceCodeInfo embedded in the  FileDescriptorProtomore...
void
RecordErrorsTo(io::ErrorCollector * error_collector)
Requests that errors be recorded to the given ErrorCollector while parsing.  more...
const string &
GetSyntaxIdentifier()
Returns the identifier used in the "syntax = " declaration, if one was seen during the last call to  Parse(), or the empty string otherwise.
void
SetRequireSyntaxIdentifier(bool value)
If set true, input files will be required to begin with a syntax identifier.  more...
void
SetStopAfterSyntaxIdentifier(bool value)
Call SetStopAfterSyntaxIdentifier(true) to tell the parser to stop parsing as soon as it has seen the syntax identifier, or lack thereof.  more...

bool Parser::Parse(
        io::Tokenizer * input,
        FileDescriptorProto * file)

Parse the entire input and construct a FileDescriptorProto representing it.

Returns true if no errors occurred, false otherwise.


void Parser::RecordSourceLocationsTo(
        SourceLocationTable * location_table)

DEPRECATED: New code should use the SourceCodeInfo embedded in the FileDescriptorProto.

Requests that locations of certain definitions be recorded to the given SourceLocationTable while parsing. This can be used to look up exact line and column numbers for errors reported by DescriptorPool during validation. Set to NULL (the default) to discard source location information.


void Parser::RecordErrorsTo(
        io::ErrorCollector * error_collector)

Requests that errors be recorded to the given ErrorCollector while parsing.

Set to NULL (the default) to discard error messages.


void Parser::SetRequireSyntaxIdentifier(
        bool value)

If set true, input files will be required to begin with a syntax identifier.

Otherwise, files may omit this. If a syntax identifier is provided, it must be 'syntax = "proto2";' and must appear at the top of this file regardless of whether or not it was required.


void Parser::SetStopAfterSyntaxIdentifier(
        bool value)

Call SetStopAfterSyntaxIdentifier(true) to tell the parser to stop parsing as soon as it has seen the syntax identifier, or lack thereof.

This is useful for quickly identifying the syntax of the file without parsing the whole thing. If this is enabled, no error will be recorded if the syntax identifier is something other than "proto2" (since presumably the caller intends to deal with that), but other kinds of errors (e.g. parse errors) will still be reported. When this is enabled, you may pass a NULL FileDescriptorProto to Parse().

class SourceLocationTable

#include <google/protobuf/compiler/parser.h>
namespace google::protobuf::compiler

A table mapping (descriptor, ErrorLocation) pairs -- as reported by DescriptorPool when validating descriptors -- to line and column numbers within the original source code.

This is semi-obsolete: FileDescriptorProto.source_code_info now contains far more complete information about source locations. However, as of this writing you still need to use SourceLocationTable when integrating with DescriptorPool.

Members

SourceLocationTable()
~SourceLocationTable()
bool
Find(const Message * descriptor, DescriptorPool::ErrorCollector::ErrorLocation location, int * line, int * column) const
Finds the precise location of the given error and fills in *line and column with the line and column numbers.  more...
void
Add(const Message * descriptor, DescriptorPool::ErrorCollector::ErrorLocation location, int line, int column)
Adds a location to the table.
void
Clear()
Clears the contents of the table.

bool SourceLocationTable::Find(
        const Message * descriptor,
        DescriptorPool::ErrorCollector::ErrorLocation location,
        int * line,
        int * column) const

Finds the precise location of the given error and fills in *line and column with the line and column numbers.

If not found, sets *line to -1 and *column to 0 (since line = -1 is used to mean "error has no exact location" in the ErrorCollector interface). Returns true if found, false otherwise.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值