- Notifications
You must be signed in to change notification settings - Fork2
raydac/java-prolog-parser
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Duringmy experiments in Prolog with Java, I developed some parser to process Prolog sources written in Edinburgh style. I decided that it is useful stuff, and it would be good to be prepared as separated independent module published in Maven central. In 2018 deep refactoring made the parser better and stronger.
It supports
- prolog operators
- line and block commentaries
- underline split numbers
- curly blocks
The parser is a pure Java library without any 3-th side dependency, it is published im the Maven central and can be injected into project just by adding:
<dependency> <groupId>com.igormaznitsa</groupId> <artifactId>java-prolog-parser</artifactId> <version>2.2.0</version></dependency>
Just use maven commandmvn install
to get result JAR. The JAR will be Java 1.8 compatible but it requires Java 11+ forbuild for involved maven plugins.
Parser implements stream which sequentially reads prolog terms provided by reader. By default, PrologParser is abstract class but there is pre-defined implementation GenericPrologParser for common cases.
Readerreader =newStringReader("hello(world). some({1,2,3}). power(X,Y,Z) :- Z is X ** Y.");ParserContextcontext =DefaultParserContext.of(ParserContext.FLAG_CURLY_BRACKETS,Op.SWI);PrologParserparser =newGenericPrologParser(reader,context);parser.forEach(System.out::println);
Supported tokens:
- atoms (class PrologAtom)
- numbers (classes PrologInt and PrologFloat), they are based on java big number classes so that their size is limited mainly only by heap
- lists (class PrologList)
- structures (class PrologStruct)
- variables (class PrologVar)
Supported quotations:
- single quote
'
- special flag turns on whitespace support in single quote mode
- double quote
"
- back tick
Since 2.2.0 it is possible get line and block comments as atoms marked by special quotations.
Bracketed empty-functor structures represented by structure with functor either{}
or()
(depends on bracket type).
About
Java based Edinburgh Prolog parser
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.