Java Prolog Parser

It is a hand-written prolog parser, it allows to parse prolog sources written in Edinburgh Prolog style

License

License

Categories

Categories

ORM Data
GroupId

GroupId

com.igormaznitsa
ArtifactId

ArtifactId

prologparser
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Java Prolog Parser
It is a hand-written prolog parser, it allows to parse prolog sources written in Edinburgh Prolog style
Project URL

Project URL

https://github.com/raydac/java-prolog-parser
Project Organization

Project Organization

Igor Maznitsa
Source Code Management

Source Code Management

https://github.com/raydac/java-prolog-parser

Download prologparser

How to add to project

<!-- https://jarcasting.com/artifacts/com.igormaznitsa/prologparser/ -->
<dependency>
    <groupId>com.igormaznitsa</groupId>
    <artifactId>prologparser</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.igormaznitsa/prologparser/
implementation 'com.igormaznitsa:prologparser:2.0.0'
// https://jarcasting.com/artifacts/com.igormaznitsa/prologparser/
implementation ("com.igormaznitsa:prologparser:2.0.0")
'com.igormaznitsa:prologparser:jar:2.0.0'
<dependency org="com.igormaznitsa" name="prologparser" rev="2.0.0">
  <artifact name="prologparser" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.igormaznitsa', module='prologparser', version='2.0.0')
)
libraryDependencies += "com.igormaznitsa" % "prologparser" % "2.0.0"
[com.igormaznitsa/prologparser "2.0.0"]

Dependencies

test (3)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.3.1
org.junit.jupiter : junit-jupiter-engine jar 5.3.1
org.mockito : mockito-core jar 2.23.0

Project Modules

There are no modules declared in this project.

License Apache 2.0 Maven central Java 8.0+ PayPal donation Yandex.Money donation

Preword

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.

Features

It supports

  • prolog operators
  • line and block commentaries
  • underline splitted numbers
  • curly blocks

Maven dependency

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.2</version>
</dependency>

How to use?

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);

Supported Prolog terms

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 '
  • special flag turns on whitespace support in single quote mode
  • double quote "
  • back tick

Bracketed empty-functor structures represented by structure with functor either {} or () (depends on bracket type).

Versions

Version
2.0.0
1.3.2
1.3.1