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

Complete JSON parser implementation #13

Open
marc0der opened this issue Apr 14, 2020 · 2 comments
Open

Complete JSON parser implementation #13

marc0der opened this issue Apr 14, 2020 · 2 comments

Comments

@marc0der
Copy link
Collaborator

marc0der commented Apr 14, 2020

This issue is a placeholder for a task that still needs to be completed for chapter 9 on parser combinator library design. The chapter focuses heavily on algebraic design with deferred implementation of the algebra.

All code samples and exercises for the chapter compile, although the focal point of the chapter is to implement a working JSON parser. Due to time constraints in delivering subsequent chapters, this implementation was deferred.

The correct way to get this parser operational is by using tests to prove the implementation of all primitives and combinators. It would be best to start with the primitives, then build up towards increasingly complex combinators. Finally, tests should be put in place that test the parser in its entirety.

Also worth mentioning that this is a port of the original parser that appears in the solutions of the original FP in Scala red book. The Scala implementation is fully operational and can be used as a reference for the Kotlin version.

@suniala
Copy link

suniala commented Feb 14, 2022

Any update on this issue?

I get the point of figuring out the algebra before doing an actual implementation but I still feel that an algebra is only useful if I'm able to implement it. Therefore I felt like I didn't get as much out of this chapter as I could have if it had had tests and a working implementation for the json parser.

A complete implementation of the json parser seems to be available but it does not work. Running the main function at

produces a StringIndexOutOfBoundsException. The fix at firstNonMatchingIndex is quite obvious but after that I still get StringIndexOutOfBoundsException but from another place.

@suniala
Copy link

suniala commented Feb 14, 2022

To correct myself: I wrote about the "json parser" but the code I linked does not run the json parser. If I run the actual json parser...

fun main() {
    println(Example.run(JSONParser.jsonParser, "{\"asdf\": true}"))
}

...I get a StackOverflowError.

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

2 participants