expr ElementExpression(_:E, e) } | ". " ~ "length" ^^^ LengthExp..." />
I would do it like this: type E = Expression def postfixExp = primaryExp ~ rep( "" ~> expr ElementExpression(_:E, e) } | ". " ~ "length" ^^^ LengthExpression | ". " ~> ident ~ ("(" ~> repsep(expr, ",") CallMethodExpression(_:E, f, args) } ) ^^ flatten2 { (e, ls) => collapse(ls)(e) } def expr: ParserE = ... def collapse(ls: ListE=>E)(e: E) = { ls.
FoldLeft(e) { (e, f) => f(e) } } Shortened expressions to expr for brevity as well as added the type alias E for the same reason The trick that I'm using here to avoid the ugly case analysis is to return a function value from within the inner production. This function takes an Expression (which will be the primary ) and then returns a new Expression based on the first. This unifies the two cases of dot-dispatch and bracketed expressions.
Finally, the collapse method is used to merge the linear List of function values into a proper AST, starting with the specified primary expression Note that LengthExpression is just returned as a value (using ) from its respective production. This works because the companion objects for case classes (assuming that LengthExpression is indeed a case class) extend the corresponding function value delegating to their constructor. Thus, the function represented by LengthExpression takes a single Expression and returns a new instance of LengthExpression precisely satisfying our needs for the higher-order tree construction.
I would do it like this: type E = Expression def postfixExp = primaryExp ~ rep( "" ~> expr ElementExpression(_:E, e) } | ". " ~ "length" ^^^ LengthExpression | ". " ~> ident ~ ("(" ~> repsep(expr, ",") CallMethodExpression(_:E, f, args) } ) ^^ flatten2 { (e, ls) => collapse(ls)(e) } def expr: ParserE = ... def collapse(ls: ListE=>E)(e: E) = { ls.
FoldLeft(e) { (e, f) => f(e) } } Shortened expressions to expr for brevity as well as added the type alias E for the same reason. The trick that I'm using here to avoid the ugly case analysis is to return a function value from within the inner production. This function takes an Expression (which will be the primary) and then returns a new Expression based on the first.
This unifies the two cases of dot-dispatch and bracketed expressions. Finally, the collapse method is used to merge the linear List of function values into a proper AST, starting with the specified primary expression. Note that LengthExpression is just returned as a value (using ^^^) from its respective production.
This works because the companion objects for case classes (assuming that LengthExpression is indeed a case class) extend the corresponding function value delegating to their constructor. Thus, the function represented by LengthExpression takes a single Expression and returns a new instance of LengthExpression, precisely satisfying our needs for the higher-order tree construction.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.