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

Higher-order rules. #32

Open
otac0n opened this issue Apr 27, 2013 · 7 comments
Open

Higher-order rules. #32

otac0n opened this issue Apr 27, 2013 · 7 comments

Comments

@otac0n
Copy link
Owner

otac0n commented Apr 27, 2013

Come up with a syntax for higher-order rules.

They will most likely be implemented as delegate passing and generics in C#.

@otac0n
Copy link
Owner Author

otac0n commented Jan 30, 2014

Possible syntax option:

parensAround@T = '(' t:T ')' { t }

parenthticalName = parensAround@name

name = [a-z]i [a-z0-9]i*

Need to figure out type constraints.

@otac0n
Copy link
Owner Author

otac0n commented Jan 30, 2014

This must be legal:

start = c

a@T = T

b@T = T

c = a@b@someOtherRule

(using the above syntax)

Also, it must be equivalent to start = someOtherRule, including return types.

This must be legal:

start = b

a@T1,T2 <object> = a:T1 b:T2 { new { a, b } }

b = a@name,number

Also, there must not be any syntactic ambiguities, nor any restriction on depth or breadth of rule relationships.

@otac0n
Copy link
Owner Author

otac0n commented Jan 30, 2014

since a@b@T1,T2 would be ambiguous between a@(b@(T1, T2)) and a@(b@(T1),T2), the bare @ syntax is insufficient.

@otac0n
Copy link
Owner Author

otac0n commented Jan 30, 2014

Some possible syntax options:

  1. a<@T1, T2> = b<@T1,T2> (used by types and repetition)
  2. a(@T1, T2) = b(@T1,T2) (used by expressions)
  3. a[@T1, T2] = b[@T1,T2] (used by classes)
  4. a{@T1, T2} = b{@T1,T2} (used by code)

Really, any left-right Unicode characters would work, but we need to only use what can be typed on a keyboard.

Of the above options, I like No.1 the best, since higher-order rules are very similar to and will work closely with C#'s generic type system.

@otac0n
Copy link
Owner Author

otac0n commented Jan 30, 2014

The syntax will need to be able to express these:

delegate ParseResult<T> Parser<T>(ref Cursor cursor);

private ParseResult<Range<T>> range<T>(ref Cursor cursor, Parser<T> _pT) where T : IComparable<T>
{
    ...
}

private ParseResult<IList<TBase>> listOfEither<T1, T2, TBase>(ref Cursor cursor, Parser<T1> _pT1, Parser<T2> _pT2) where T1 : TBase, T2 : TBase
{
    ...
}

@otac0n
Copy link
Owner Author

otac0n commented Feb 1, 2014

Rule Syntax take 2:

list@(Item, Seperator) = Item<0,,_ Seperator _>

numberList = list@(number, ',')

Also, the parens can be elided for a rule name:

foo@T = T

bar@T = T

baz = foo@bar@number

@otac0n
Copy link
Owner Author

otac0n commented Apr 29, 2014

I think I will move forward with this simple syntax, and see where it falls down.

Of course, sometimes you need to pass in a type and sometimes you need to pass in a rule. We'll probably have to hash out a more complex syntax for dealing with both of these cases.

@otac0n otac0n removed this from the 3.2 milestone Oct 4, 2014
@otac0n otac0n removed their assignment Sep 4, 2015
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

1 participant