Git Product home page Git Product logo

java-prolog-parser's Introduction

License Apache 2.0 Maven central Java 8.0+ PayPal donation YooMoney donation

Pre-word

During my 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.

Features

It supports

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

Maven dependency

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

How to build?

Just use maven command mvn install to get result JAR. The JAR will be Java 1.8 compatible but it requires Java 11+ for build for involved maven plugins.

How to use?

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.

Reader reader = new StringReader("hello(world). some({1,2,3}). power(X,Y,Z) :- Z is X ** Y.");
ParserContext context = DefaultParserContext.of(ParserContext.FLAG_CURLY_BRACKETS, Op.SWI);
PrologParser parser = new GenericPrologParser(reader, context);
parser.forEach(System.out::println);

Supported Prolog terms

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

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.