During my development of Java prolog engine (JProl) I had developed parser to parse sources written in Edinburgh style, I decided to extract the module into separated project and 1.0.0 version was published. In 2018 I had decided to make deep refactoring and 2.0.0 version was published. The Parser allows build custom prolog parsers with support of operators and some modern prolog features.
It supports
- prolog operators
- line and block commentaries
- underline splitted numbers
- curly blocks
It is a library without 3th side dependencies, it is published im the Maven central and can be added into project just with:
<dependency> <groupId>com.igormaznitsa</groupId> <artifactId>java-prolog-parser</artifactId> <version>2.0.1</version> </dependency> Parser implements stream which sequentially reads prolog terms from reader. By default PrologParser is abstract class but there is GenericPrologParser class provides minimalistic implementation.
Reader reader = new StringReader("hello(world). some({1,2,3}). power(X,Y,Z) :- Z is X ** Y."); PrologParser parser = new GenericPrologParser(reader, new DefaultParserContext(ParserContext.FLAG_CURLY_BRACKETS, Op.SWI)); parser.forEach(System.out::println); The parser supports
- atoms (class PrologAtom)
- numbers (classes PrologInt and PrologFloat), they are based on big numbers so that their size is not restricted
- lists (class PrologList)
- structures (class PrologStruct)
- variables (class PrologVar)
Supported quotations:
- single quote
' - double quote
" - back tick
Bracketed empty-functor structures represented by structure with functor either {} or () (depends on bracket type).