-
Notifications
You must be signed in to change notification settings - Fork 27
Parser Improvements #48
Comments
Open question: does this belong in the Parser project? Or, in a separate Compiler project? |
@ctaggart @bhandfast @agbogomolov @takemyoxygen Starting to take a look at the current Parser, and I'm afraid adding the above functionality will involve either breaking the existing API in several ways, or mean these steps will require extending the API:
I'm not really in favor of adding to the public Parser.xxx functions, as the current API is fairly clean: there are only 3 functions - parse strings, streams, and files - each with a variation taking either an explicit parser or implicitly using the default parser (Parsers.pProto). This, IMHO, makes the API readily discoverable and easy to use. Requiring that the client call a "postProcess" function (or set of functions) does not make usage obvious. I could add a Or, I could redefine the Any opinions? |
@jhugard, I see the process as a sequence of two steps:
And then, results of the 2nd step can be used by code generator or the type provider. The question is, is that necessary to expose results of the first step as public API? Maybe it would be better to expose single high-level function |
Starting to iterate on this in branch |
@7sharp9 I don't remember. Since you are asking, I'm guessing not. I'll help clean up these projects you are using soon. |
I think I had it working on this branch: May have been holding the branch open to implement the other items on the list above, but you'll need to look over the code to be sure... |
The parser currently correctly turns
proto2
andproto3
into an AST, but does no further processing or semantic validation.Proposed additions:
import
statements Process import statements #109Process
import
statementsParser methods need to be enhanced with, e.g., a function parameter that can satisfy includes. For
Parse.fromFile
, this could be an include path or paths. How to provide this for strings and streams is an open question.Normalize Type Names
Convert various naming conventions into a single normalized form. Should support outputting in caller-selectable camelCase, PascalCase, snake_case, etc.
Flatten Type Names
Messages can contain inner message and enum definitions. These are publically visible and can be referenced from other types. It will probably be convenient to flatten these symbols and move them from an inner scope to the top level scope, while renaming the type using the fully-qualified scope name; e.g., "Outer.Inner".
In addition, Record types cannot contain inner types. Since .NET can handle "+" in a symbol name, the names could be normalized from "Outer.Inner" to "Outer+Inner" either in this step, or when doing code-gen for Records.
Validate Type Usage
Ensure every
message
used as a field type andenum
used as a constant are defined somewhere. Must handle use before definition (so cannot be single pass). Must also handle qualification with thepackage
name or unqualified using the current .proto file's package.Resolve Constants
An
enum
can be used as a constant in an Option definition. Consider either resolving these, or exposing the symbol table used during type usage validation so that client code can do the substitution.Capture Comments
Google's protobuf compiler can capture comments related to a symbol. This can be quite useful for generating documentation, such as in a type provider. It is also needed to create a full FileDescriptorSet (a binary protobuf representation of a set of .proto files).
The text was updated successfully, but these errors were encountered: