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

OperatorPrecedenceParser Reply Status is OK when parser with InfixOperator parses a single term #107

Open
JCKortlang opened this issue Apr 1, 2024 · 1 comment

Comments

@JCKortlang
Copy link

//Given
let sanityExpr, sanityExprImpl = createParserForwardedToRef()
let sanityParser = OperatorPrecedenceParser<String, unit, unit>()
sanityParser.AddOperator(InfixOperator("+", spaces, 100, Associativity.Left, fun s1 s2 -> s1 + s2))
let sanityTerm = (choice [
    attempt (pWordCI "hello");
    attempt (pWordCI "world")
])
sanityParser.TermParser <- sanityTerm
sanityExprImpl.Value <- sanityParser

let runParser p s =
    match run p s with
    | Failure(errorString, _, _) ->
        InvalidOperationException(errorString) |> raise
    | Success(result, _, _) -> result
[<Test>]
let ``Infix operator precedence parser should fail when operator and second term is absent`` () =
    //Expect parser to fail.
    //Operator = "+"
    //Term = ["hello";"world"] i.e. "hello+world" -> "helloworld"
    //Expect parser to throw
    let result = runParser sanityParser "hello"
    //Should not pass
    result |> should equal "hello"

Example reply

Reply(Ok, "hello", [Expected("infix operator")])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant