sebastienros / parlot

Fast and lightweight parser creation tools
BSD 3-Clause "New" or "Revised" License
371 stars 44 forks source link

Implement associative parsers #116

Closed sebastienros closed 4 months ago

sebastienros commented 4 months ago

@gumbarros this PR is adding helpers to implement left/right associative expressions (and unary), you might want to use that. It might also be missing some things, so please provide feedback in this case.

gumbarros commented 4 months ago

Great idea, I'm refactoring the unary expressions with your branch new parsers.

I get the following exception with .Compile

--- EXCEPTION #1/1 [LoggerException]
Message = “Stack overflow exception occurred in test. Test run is aborted.”
ExceptionPath = Root
ClassName = JetBrains.Util.LoggerException
HResult = COR_E_APPLICATION=80131600
StackTraceString = “
  at JetBrains.Util.ILoggerEx.LogMessage(ILogger this, LoggingLevel level, String message) in LogMessage.il:line IL_002E mvid 6505
     at JetBrains.Util.ILoggerEx.Error(ILogger this, String message) in Error.il:line IL_0000 mvid 6505
     at JetBrains.ReSharper.UnitTestFramework.Execution.TestRunner.TestRunnerRunStrategy.AnalyseProcessCrash(ProcessExitedUnexpectedlyException ex, IUnitTestRun run) in AnalyseProcessCrash.il:line IL_0028 mvid FE8B
     at JetBrains.ReSharper.UnitTestFramework.Execution.TestRunner.TestRunnerRunStrategy.Run(IUnitTestRun run) in Run.il:line IL_01C8 mvid FE8B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s) in ExecutionContextCallback.il:line IL_0000 mvid 477B
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in RunInternal.il:line IL_0040 mvid 477B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread) in MoveNext.il:line IL_0000 mvid 477B or MoveNext.il:line IL_0040 mvid 477B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext() in MoveNext.il:line IL_0000 mvid 477B or MoveNext.il:line IL_0040 mvid 477B
     at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) in RunOrScheduleAction.il:line IL_003B mvid 477B
     at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in RunContinuations.il:line IL_0065 mvid 477B or RunContinuations.il:line IL_0090 mvid 477B
     at System.Threading.Tasks.Task.FinishSlow(Boolean userDelegateExecute) in FinishSlow.il:line IL_0003 mvid 477B
     at System.Threading.Tasks.Task.TrySetException(Object exceptionObject) in TrySetException.il:line IL_0022 mvid 477B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetException(Exception exception, Task`1& taskField) in SetException.il:line IL_0025 mvid 477B
     at JetBrains.ReSharper.UnitTestFramework.Execution.TestRunner.TestRunnerAgentManager.TestRunnerExecutionAgent.RunTests(CancellationToken cancelCt, CancellationToken abortCt) in RunTests.il:line IL_00AE mvid FE8B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s) in ExecutionContextCallback.il:line IL_0000 mvid 477B
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in RunInternal.il:line IL_0040 mvid 477B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread) in MoveNext.il:line IL_0000 mvid 477B or MoveNext.il:line IL_0040 mvid 477B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext() in MoveNext.il:line IL_0000 mvid 477B or MoveNext.il:line IL_0040 mvid 477B
     at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) in RunOrScheduleAction.il:line IL_003B mvid 477B
     at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in RunContinuations.il:line IL_0065 mvid 477B or RunContinuations.il:line IL_0090 mvid 477B
     at System.Threading.Tasks.Task.FinishSlow(Boolean userDelegateExecute) in FinishSlow.il:line IL_0003 mvid 477B
     at System.Threading.Tasks.Task.TrySetException(Object exceptionObject) in TrySetException.il:line IL_0022 mvid 477B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetException(Exception exception, Task`1& taskField) in SetException.il:line IL_0025 mvid 477B
     at JetBrains.ReSharper.UnitTestFramework.Common.Extensions.TaskExtensions.CancelIf(Task task, CancellationToken ct, TaskCreationOptions options) in CancelIf.il:line IL_0126 mvid FE8B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s) in ExecutionContextCallback.il:line IL_0000 mvid 477B
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in RunInternal.il:line IL_0040 mvid 477B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread) in MoveNext.il:line IL_0000 mvid 477B or MoveNext.il:line IL_0040 mvid 477B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext() in MoveNext.il:line IL_0000 mvid 477B or MoveNext.il:line IL_0040 mvid 477B
     at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) in RunOrScheduleAction.il:line IL_003B mvid 477B
     at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in RunContinuations.il:line IL_0065 mvid 477B or RunContinuations.il:line IL_0090 mvid 477B
     at System.Threading.Tasks.Task`1.TrySetResult(TResult result) in TrySetResult.il:line IL_004B mvid 477B
     at System.Threading.Tasks.Task.TwoTaskWhenAnyPromise`1.Invoke(Task completingTask) in Invoke.il:line IL_0088 mvid 477B
     at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in RunContinuations.il:line IL_0065 mvid 477B or RunContinuations.il:line IL_0090 mvid 477B
     at System.Threading.Tasks.Task.FinishSlow(Boolean userDelegateExecute) in FinishSlow.il:line IL_0003 mvid 477B
     at System.Threading.Tasks.Task.TrySetException(Object exceptionObject) in TrySetException.il:line IL_0022 mvid 477B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetException(Exception exception, Task`1& taskField) in SetException.il:line IL_0025 mvid 477B
     at JetBrains.ReSharper.UnitTestFramework.Common.Extensions.TaskExtensions.ThrowIf[TException](Task task, Task signallingTask, Func`1 exceptionFactory) in ThrowIf.il:line IL_00A9 mvid FE8B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s) in ExecutionContextCallback.il:line IL_0000 mvid 477B
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in RunInternal.il:line IL_0040 mvid 477B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread) in MoveNext.il:line IL_0000 mvid 477B or MoveNext.il:line IL_0040 mvid 477B
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext() in MoveNext.il:line IL_0000 mvid 477B or MoveNext.il:line IL_0040 mvid 477B
     at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) in RunOrScheduleAction.il:line IL_003B mvid 477B
     at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in RunContinuations.il:line IL_0065 mvid 477B or RunContinuations.il:line IL_0090 mvid 477B
     ...

Without .Compile is working fine probably, I'm just fixing the logic on my parser before committing to my branch

sebastienros commented 4 months ago

@gumbarros I can't see Parlot in the stacktrace, could you paste the part where it's involved?

gumbarros commented 4 months ago

@gumbarros I can't see Parlot in the stacktrace, could you paste the part where it's involved?

Sorry, I think it was a bug in my IDE, it's working normally now with .Compile. But I swear it was not working with just .Compile()