miho / VMF-Text

Powerful Grammar-based Language Modeling Framework
Apache License 2.0
10 stars 0 forks source link
abstract-syntax-tree antlr antlr4 code-generation java model-driven parser unparsing

VMF-Text Tweet

Build Status Build status Join the chat at https://gitter.im/VMF_/Lobby

VMF-Text is a novel framework for grammar-based language modeling on the Java Platform (it works with Java 8, 9, 10 and 11): give it a labeled ANTLR4 grammar and it will generate a rich and clean API (based on VMF) for (un)parsing and transforming custom textual languages. The complete API is derived from just a single ANTLR4 grammar file!

Using VMF-Text

Checkout the tutorial projects: https://github.com/miho/VMF-Text-Tutorials

VMF-Text comes with excellent Gradle support. Just add the plugin like so (click here to get the latest version):

plugins {
  id "eu.mihosoft.vmftext" version "0.1.2.7" // use latest version
}

(optionally) configure VMF-Text:

vmfText {
    vmfVersion   = '0.1.1'   // (runtime version)
    antlrVersion = '4.7.1' // (runtime version)
}

Now just add the labeled ANTLR4 grammar file to the VMF-Text source folder, e.g.:

src/main/vmf-text/my/pkg/ArrayLang.g4

Sample grammar for parsing strings of the form (1,2,3):

grammar ArrayLang;

array:  '(' values+=INT (',' values+=INT)* ')' EOF;

INT: SIGN? DIGIT+
   ;

fragment SIGN :'-' ;
fragment DIGIT : [0-9];

WS
    : [ \t\r\n]+ -> channel(HIDDEN)
    ;

/*<!vmf-text!>
TypeMap() {
  (INT    -> java.lang.Integer) = 'java.lang.Integer.parseInt(entry.getText())'
}
*/

Finally, call the vmfTextGenCode task to generate the implementation.

Building VMF-Text (Core)

Requirements

IDE

Open the VMF-Text/core Gradle project in your favourite IDE (tested with NetBeans 8.2 and IntelliJ 2018) and build it by calling the publishToMavenLocal task.

Command Line

Navigate to the Gradle project (i.e., path/to/VMF-Text/core) and enter the following command

Bash (Linux/macOS/Cygwin/other Unix shell)

bash gradlew publishToMavenLocal

Windows (CMD)

gradlew publishToMavenLocal

Building VMF-Text (Gradle Plugin)

Requirements

IDE

Open the VMF-Text/gradle-plugin Gradle project in your favourite IDE (tested with NetBeans 8.2 and IntelliJ 2018) and build it by calling the publishToMavenLocal task.

Command Line

Navigate to the Gradle project (i.e., path/to/VMF-Text/gradle-plugin) and enter the following command

Bash (Linux/macOS/Cygwin/other Unix shell)

bash gradlew publishToMavenLocal

Windows (CMD)

gradlew publishToMavenLocal 

Testing VMF-Text (Core & Plugin)

To execute the test suite, navigate to the test project (i.e., path/to/VMF-Text/test-suite) and enter the following command

Bash (Linux/macOS/Cygwin/other Unix shell)

bash gradlew test

Windows (CMD)

gradlew test

This will use the latest snapshot vmf-text and gradle-plugin to execute the tests defined in the test-suite project.

Viewing the Report

An HTML version of the test report is located in the build folder test-suite/build/reports/tests/test/index.html.

Test reports of the travis builds are available as well: [Test reports]