Edinburgh Prolog parser

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

License

License

Categories

Categories

Java Languages ORM Data
GroupId

GroupId

com.igormaznitsa
ArtifactId

ArtifactId

java-prolog-parser
Last Version

Last Version

2.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

Edinburgh 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 java-prolog-parser

How to add to project

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

Dependencies

test (3)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.5.1
org.junit.jupiter : junit-jupiter-engine jar 5.5.1
org.mockito : mockito-core jar 3.0.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.2
2.0.1