Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -public flag that will publicly expose a rule for parsing. #42

Closed
otac0n opened this issue Jan 19, 2014 · 5 comments
Closed

Add -public flag that will publicly expose a rule for parsing. #42

otac0n opened this issue Jan 19, 2014 · 5 comments

Comments

@otac0n
Copy link
Owner

otac0n commented Jan 19, 2014

Example:

program = _ expression<0,,_ ';' _> _ EOF

Expression -public = _ e:expression _ { e }

expression = '' [a-z]+

Here, program would still be the start rule and a method called ParseExpression would be exposed.

A warning will be emitted if the -public flag is added to a rule whose name starts with a lower case letter.

@otac0n
Copy link
Owner Author

otac0n commented Jan 20, 2014

This is a bit half-baked.

For example, what exactly should the method signatures be?
Maybe some combination of these:

IParseResult<T> ParseExpression(ref Cursor cursor);
IParseResult<T> ParseExpression(string subject, string fileName = null);
IParseResult<T> ParseExpression(string subject, string fileName = null, int offset = 0);
T ParseExpression(string subject, string fileName = null);
T ParseExpression(string subject, string fileName = null, int offset = 0);
T ParseExpression(string subject, string fileName, out IList<LexicalElement> lexicalElements);
T ParseExpression(string subject, string fileName, int offset, out IList<LexicalElement> lexicalElements);

Obviously, not all are possible. Do we need to satisfy all of these contracts? What are our actual use cases?

@otac0n
Copy link
Owner Author

otac0n commented Jan 20, 2014

One known use case: #25 Composite Grammars.

This would require an interface such as IParseResult<T> ParseExpression(ref Cursor cursor) in order to pass control on to the next parser.

@otac0n
Copy link
Owner Author

otac0n commented Jan 20, 2014

Another possible use case: #32 Higher-order Rules

Higher order rules will need a delegate-passing interface and will benefit most from the same interface as Composite Grammars, IParseResult<T> ParseExpression(ref Cursor cursor).

@david-pfx
Copy link

I would use -public to gain access to a rule to use for restarting the parse. The signature need not change. At present I do this via the partial class.

@otac0n
Copy link
Owner Author

otac0n commented May 16, 2016

This is now complete in the develop branch.

I also included an export flag.

The difference is that the public flag implies a contract like the existing Parse method, whereas the export flag implies a signature that is compatible with #parse{} code blocks.

@otac0n otac0n closed this as completed May 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants