You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I call Positioned after ChainOperator, it will only work for the top-level node and may overwrite the position of the operand when there is no operation in the input.
For example (see the end for the full example code):
staticreadonlyParser<Node>parserExpression=Parse.ChainOperator(parserOperator,parserInt,(op,lhs,rhs)=>newBinaryExpression(op,lhs,rhs)).Positioned();// only work for top-level
usingSprache;usingSystem;namespaceSphracheTest{staticclassProgram{staticreadonlyParser<Node>parserInt=(fromninParse.NumberselectnewLiteral<int>(int.Parse(n))).Positioned().Token();staticreadonlyParser<BinaryOperator>parserOperatorPlus=Parse.Char('+').Return(BinaryOperator.Plus);staticreadonlyParser<BinaryOperator>parserOperatorSubtract=Parse.Char('-').Return(BinaryOperator.Subtract);staticreadonlyParser<BinaryOperator>parserOperator=parserOperatorPlus.XOr(parserOperatorSubtract).Token();staticreadonlyParser<Node>parserExpression=Parse.ChainOperator(parserOperator,parserInt,(op,lhs,rhs)=>newBinaryExpression(op,lhs,rhs)).Positioned();// only work for top-levelstaticvoidMain(string[]args){Console.WriteLine(parserExpression.Parse(Console.ReadLine()).ToTreeForm());}}}
The text was updated successfully, but these errors were encountered:
If I call
Positioned
afterChainOperator
, it will only work for the top-level node and may overwrite the position of the operand when there is no operation in the input.For example (see the end for the full example code):
input:
1 + 2 - 3 + 4
expected output:
actual output:
input:
1
(1 surrounded by space characters)expected output::
actual output:
Is there a proper way to obtain the position information of the intermediate node?
Full example code
node.cs
literal.cs
binaryexpression.cs
nodeextension.cs
program.cs
The text was updated successfully, but these errors were encountered: