Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Java based Edinburgh Prolog parser

NotificationsYou must be signed in to change notification settings

raydac/java-prolog-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License Apache 2.0Maven centralJava 11.0+PayPal donationYooMoney donation

Pre-word

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.

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

How to build?

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.

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.

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

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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp