meow
Meow is a simple JSON parsing library.
It implements a simplified version of Parsec.
This parser has no error hinting, all parsing results are wrapped by Maybe.
It returns the Just result
if the parsing succeeds and Nothing
if it fails.
Note: because meow use sealed interface to simulate ADT, so the minimal required version of Java is 17.
Defination
The parser prototype defined by Haskell as below
newtype Parser a = Parser {
runParser :: String -> Maybe (a, String)
}
Example
// get json parser
var parser = Grammar._json;
// parse number
parser.parse("123");
// result: Just JsonNumber 123
// parse string
parser.parse("\"hello world!\\n\"");
// result: Just JsonString "hello world!\n"
// parse array
parser.parse("[1, 2, 3]");
// result: Just JsonArray [1, 2, 3]
// parse object
parser.parse("{\"one\": 1, \"two\": 2, \"three\": 3}");
// result: Just JsonObject {one=JsonNumber 1, two=JsonNumber 2, three=JsonNumber 3}
// parse fail
parser.parse("\"hello");
// result: Nothing
For more available examples see here.