Build parsers in Java

Overview

jparsec

Builds mini parsers in pure Java.

Latest version: 3.0 (requires Java 8+)

News

2016-12-05

  • Removed references to Codehaus in copyright and package layout
  • Support for Java 8 now complete
  • Support for OSGi is merged in master, thanks to Alex Michael Berry and this PR

How to Use?

jparsec is available in maven-central. Snapshot Javadoc

Maven

Add the following fragment to your <dependencies> section:

If using Java 7-:

  <dependency>
    <groupId>org.jparsec</groupId>
    <artifactId>jparsec</artifactId>
    <version>2.3</version>
  </dependency>

If using Java 8+:

  <dependency>
    <groupId>org.jparsec</groupId>
    <artifactId>jparsec</artifactId>
    <version>3.1</version>
  </dependency>

Tell me more

Jparsec is a recursive-descent parser combinator framework written for Java. It's an implementation of Haskell Parsec on the Java platform.

Feature highlights

  • Operator precedence grammar,
  • Accurate error location and customizable error message,
  • Rich set of pre-defined reusable combinator functions,
  • Declarative API that resembles BNF.

Documentation

Look at the wiki for documentation on implementing parsers with jparsec.

Talking about jparsec

  • 2014-01-16 - Nantes JUG: Quickie on jparsec for local JUG
  • 2013-09-23 - JUGSummerCamp 2013: Directory parsing-made-easy contains material for the talk (slides + sample code)
Comments
  • Add Logging Capabilities

    Add Logging Capabilities

    In working with JParsec, as the parsing got more complicated with more possible branches, it is becoming difficult to debug issues; whilst I am using test driven development, I am at a position where each piece is working in isolation, and they are working together in most but not all configurations. As it currently stands, it is hard to 'follow' the path that the parsing took through some text, and see exactly what it is doing. It would be nice if there was logging capabilities available where a logger could be enabled and print to somewhere a trace of what the parser is doing as it is doing it. Thus, when it fails, I could see under what branches and conditions it failed and pinpoint, of all the parsers in the application, which one is misbehaving and under what circumstances.

    enhancement 
    opened by ErikaRedmark 32
  • Release v2.2 unauthorized on sonatype

    Release v2.2 unauthorized on sonatype

    When I ran mvn release:perform, I got an Unauthorized error:

    Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project jparsec-root: Failed to deploy artifacts: Could not transfer artifact org.jparsec:jparsec-root:pom:2.2-20141211.025232-1 from/to sonatype (https://oss.sonatype.org/content/repositories/snapshots/): Failed to transfer file: https://oss.sonatype.org/content/repositories/snapshots/org/jparsec/jparsec-root/2.2-SNAPSHOT/jparsec-root-2.2-20141211.025232-1.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]

    Not sure if it's because I don't have ownership of the "org.jparsec" repo.

    @abailly When you get a chance, could you see if you can push forward the release? mvn release:prepare was fine.

    Thanks!!

    opened by fluentfuture 26
  • Provide ability to reference underlying source from a returned JParsec object

    Provide ability to reference underlying source from a returned JParsec object

    I would like to produce an annotated version of an input source file. To be able to do this one needs the ability to reference the original source, either as a "image" ie String or through pointers to the original source, perhaps using two Location objects,begin and end. It should include any white spaces too.

    Does this sound reasonable?

    enhancement 
    opened by jasons2000 20
  • A parser that terminates parse on failure

    A parser that terminates parse on failure

    I'm missing a parser modifier that I know from using the C++ Spirit V3 framework:

    A parser that immediately terminates the parse when its contained parser fails. It may be used to assert that the rest of an alternative matches after the begin has been matched.

    As one does not have access to jparsec internals, it's impossible to implement this a clean way. So propose to add something like Parser<T> assertMatch() to Parser. Of course the actual name is up to bikeshedding.

    BTW, this is a hack I wrote. It seems to work ...

    package org.jparsec;
    
    import org.jparsec.ParseContext;
    import org.jparsec.Parser;
    import org.jparsec.error.ParserException;
    
    public class Extension {
      
      public static <T> Parser<T> assertMatch(Parser<T> parser) {
        return new Parser<T>() {
          @Override boolean apply(ParseContext ctxt) {
            if (!parser.apply(ctxt)) {
              @SuppressWarnings("deprecation")
              ParserException exception =  new ParserException(
                  ctxt.renderError(), ctxt.module, ctxt.locator.locate(ctxt.errorIndex()));
              exception.setParseTree(ctxt.buildErrorParseTree());
              throw exception;
            }  
            return true;
          }
          @Override public String toString() {
            return parser.toString();
          }
        };  
      }
    }
    
    opened by bonastos 19
  • Provide a parse tree view to solve issue #12

    Provide a parse tree view to solve issue #12

    Add a tryParseTree() method to Parser. The code has been tested against a relatively complex project of mine. The result is satisfactory to me. You can review the test cases to see the result.

    opened by winteryoung 17
  • Add a LOCATION conveniance parser

    Add a LOCATION conveniance parser

    I propose to add a static parser named LOCATION to Parsers, similar to the INDEX parser.

    This does not add any new functionality to jparsec, But it would, IMHO, enhance the usability.

    The location information can be recomputed using the source string and the index returned by the INDEX parser. But doing so is not really trivial. I mention SourceLocator as an example.

    Also , from my own experience, I was a little frustrated when I realized that the functionality must exist within jparsec and there's no way to access it. So I looked into the source, found SourceLocator and copied it. But it still feels dirty to have to do it,

    I think any user who's interested in line/offset information would appreciate having a LOCATION parser instead of doing the work himself..

    There are alternatives how to help the user with location information,

    • Make SourceLoacator public. A user won't have to reinvent the wheel. To me this option is a mismatch with the jparsec philosophy to provide functionality as a parser.
    • Make ParseContext public. A user can just write his own location parser. This option opens many cans of worms that should maybe better be left unopened ...
    opened by bonastos 10
  • A simple example is needed

    A simple example is needed

    I am neither a Haskell programmer or a compiler writer and found learning jparsec to be a challenge. The examples jump from a basic calculator to complex things like BNF and SQL. There needs to be an in-between sample. So I wrote one and it is at https://github.com/ianrae/simplejparsec. I probably have some terminology wrong. Comments are welcome.

    opened by ianrae 8
  • Listeners on Parser.map()

    Listeners on Parser.map()

    Hello,

    I implemented a way to add runtime listeners to a parse. The listener il called when Parse.map() is called. For instance, it permits the implementation of "Locatable", as we discussed some time ago, in a non-intrusive way. I call it Parameters because I see it as a value holder for some other features. I intend to use I soon for the implementation of some conditionnal parsing.

    opened by scolomer 8
  • Java TypeParser

    Java TypeParser

    In https://github.com/google/guava/issues/1645#issuecomment-61354869, a Guava TypeToken parser seemed to be a generally useful feature.

    The idea of adding it to core Guava has been shot down because it's a niche library to Guava.

    Though I think it would be a nice application of jparsec. For a parser framework, some useful concrete parsers would be very relevant.

    Core jparsec so far is dependency free. But these sub projects can probably pick their own dependencies.

    I'm a little unsure how best we can organize these jparsec-* sub projects. Would they just be a separate project or we can somehow keep it under the same tree, just built and packaged differently?

    Thoughts?

    opened by fluentfuture 8
  • Register JParsec at Coveralls

    Register JParsec at Coveralls

    Hi @abailly and @fluentfuture, I would like to have continuous feedback on code coverage when I'm contributing to jparsec. I've seen Coveralls is offering this service with a smooth integration with Travis. So, if you think it might be a good idea to have code coverage, can you please register jparsec at Coveralls ? I would have done it myself but I'm no longer in the collaborators list after the repo has been moved to the jparsec organization. I'll then take care of the rest in a PR. Thanks.

    opened by gssiyankai 7
  • Parser.withSource() parser

    Parser.withSource() parser

    Parser<T>.withSource() parser applies this parser and returns its result along with matches string.

    .token() parser could be used instead of .withSource(), however sometimes WithSource is more convenient, because global string object has to be stored somewhere to resolve token into string.

    Also, WithSource class is type-parameterized, unlike Token.

    opened by stepancheg 7
  • Java parser failed on assign BinaryOpExpression to a variable.

    Java parser failed on assign BinaryOpExpression to a variable.

    Parse statement with code int i=1+1; fails with message: #75

    org.jparsec.error.ParserException: line 1, column 7:
    { or IDENTIFIER expected, 1 encountered.
    

    How make operators and = assignments work together?

    opened by qzchenwl 0
  • Java parser failed on assign binaryop expression to a variable.

    Java parser failed on assign binaryop expression to a variable.

    Parse statement with code int i=1+1; fails with message:

    org.jparsec.error.ParserException: line 1, column 7:
    { or IDENTIFIER expected, 1 encountered.
    
    opened by qzchenwl 0
  • Improve MAVEN build Performance

    Improve MAVEN build Performance

    According to Maven parallel test, we can run tests in parallel.

    ===================== If there are any inappropriate modifications in this PR, please give me a reply and I will change them.

    opened by ChenZhangg 0
  • Bump junit from 4.8.1 to 4.13.1

    Bump junit from 4.8.1 to 4.13.1

    Bumps junit from 4.8.1 to 4.13.1.

    Release notes

    Sourced from junit's releases.

    JUnit 4.13.1

    Please refer to the release notes for details.

    JUnit 4.13

    Please refer to the release notes for details.

    JUnit 4.13 RC 2

    Please refer to the release notes for details.

    JUnit 4.13 RC 1

    Please refer to the release notes for details.

    JUnit 4.13 Beta 3

    Please refer to the release notes for details.

    JUnit 4.13 Beta 2

    Please refer to the release notes for details.

    JUnit 4.13 Beta 1

    Please refer to the release notes for details.

    JUnit 4.12

    Please refer to the release notes for details.

    JUnit 4.12 Beta 3

    Please refer to the release notes for details.

    JUnit 4.12 Beta 2

    No release notes provided.

    JUnit 4.12 Beta 1

    No release notes provided.

    JUnit 4.11

    No release notes provided.

    Changelog

    Sourced from junit's changelog.

    Summary of changes in version 4.13.1

    Rules

    Security fix: TemporaryFolder now limits access to temporary folders on Java 1.7 or later

    A local information disclosure vulnerability in TemporaryFolder has been fixed. See the published security advisory for details.

    Test Runners

    [Pull request #1669:](junit-team/junit#1669) Make FrameworkField constructor public

    Prior to this change, custom runners could make FrameworkMethod instances, but not FrameworkField instances. This small change allows for both now, because FrameworkField's constructor has been promoted from package-private to public.

    Commits
    • 1b683f4 [maven-release-plugin] prepare release r4.13.1
    • ce6ce3a Draft 4.13.1 release notes
    • c29dd82 Change version to 4.13.1-SNAPSHOT
    • 1d17486 Add a link to assertThrows in exception testing
    • 543905d Use separate line for annotation in Javadoc
    • 510e906 Add sub headlines to class Javadoc
    • 610155b Merge pull request from GHSA-269g-pwp5-87pp
    • b6cfd1e Explicitly wrap float parameter for consistency (#1671)
    • a5d205c Fix GitHub link in FAQ (#1672)
    • 3a5c6b4 Deprecated since jdk9 replacing constructor instance of Double and Float (#1660)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies java 
    opened by dependabot[bot] 0
  • Bump junit from 4.11 to 4.13.1 in /jparsec-workshop

    Bump junit from 4.11 to 4.13.1 in /jparsec-workshop

    Bumps junit from 4.11 to 4.13.1.

    Release notes

    Sourced from junit's releases.

    JUnit 4.13.1

    Please refer to the release notes for details.

    JUnit 4.13

    Please refer to the release notes for details.

    JUnit 4.13 RC 2

    Please refer to the release notes for details.

    JUnit 4.13 RC 1

    Please refer to the release notes for details.

    JUnit 4.13 Beta 3

    Please refer to the release notes for details.

    JUnit 4.13 Beta 2

    Please refer to the release notes for details.

    JUnit 4.13 Beta 1

    Please refer to the release notes for details.

    JUnit 4.12

    Please refer to the release notes for details.

    JUnit 4.12 Beta 3

    Please refer to the release notes for details.

    JUnit 4.12 Beta 2

    No release notes provided.

    JUnit 4.12 Beta 1

    No release notes provided.

    Commits
    • 1b683f4 [maven-release-plugin] prepare release r4.13.1
    • ce6ce3a Draft 4.13.1 release notes
    • c29dd82 Change version to 4.13.1-SNAPSHOT
    • 1d17486 Add a link to assertThrows in exception testing
    • 543905d Use separate line for annotation in Javadoc
    • 510e906 Add sub headlines to class Javadoc
    • 610155b Merge pull request from GHSA-269g-pwp5-87pp
    • b6cfd1e Explicitly wrap float parameter for consistency (#1671)
    • a5d205c Fix GitHub link in FAQ (#1672)
    • 3a5c6b4 Deprecated since jdk9 replacing constructor instance of Double and Float (#1660)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies java 
    opened by dependabot[bot] 0
Releases(jparsec-root-3.1)
Owner
null
Java 1-15 Parser and Abstract Syntax Tree for Java, including preview features to Java 13

JavaParser This project contains a set of libraries implementing a Java 1.0 - Java 14 Parser with advanced analysis functionalities. This includes pre

JavaParser 4.5k Jan 9, 2023
A Java API for generating .java source files.

JavaPoet JavaPoet is a Java API for generating .java source files. Source file generation can be useful when doing things such as annotation processin

Square 10k Jan 5, 2023
Numerical-methods-using-java - Source Code for 'Numerical Methods Using Java' by Haksun Li

Apress Source Code This repository accompanies Numerical Methods Using Java by Haksun Li (Apress, 2022). Download the files as a zip using the green b

Apress 5 Nov 20, 2022
A collection of source code generators for Java.

Auto A collection of source code generators for Java. Auto‽ Java is full of code that is mechanical, repetitive, typically untested and sometimes the

Google 10k Jan 9, 2023
Java 8 annotation processor and framework for deriving algebraic data types constructors, pattern-matching, folds, optics and typeclasses.

Derive4J: Java 8 annotation processor for deriving algebraic data types constructors, pattern matching and more! tl;dr Show me how to write, say, the

null 543 Nov 23, 2022
Catch common Java mistakes as compile-time errors

Error Prone Error Prone is a static analysis tool for Java that catches common programming mistakes at compile-time. public class ShortSet { public

Google 6.3k Dec 31, 2022
Elegant parsing in Java and Scala - lightweight, easy-to-use, powerful.

Please see https://repo1.maven.org/maven2/org/parboiled/ for download access to the artifacts https://github.com/sirthias/parboiled/wiki for all docum

Mathias 1.2k Dec 21, 2022
Compiler of Java bytecode to JavaScript

TeaVM See documentation at the project web site. Useful links: Getting started Gallery Flavour source code repository Site source code repository Disc

Alexey Andreev 2.1k Jan 3, 2023
Kodlama.io'da verilen ödev gereği Engin Demiroğ'un düzenlediği C# ile birlikte gerçek hayatta interface ve abstract konulu yayının Java uyarlaması yapılmıştır.

GercekHayattaInterfaceVeAbstract Kodlama.io'da verilen ödev gereği Engin Demiroğ'un düzenlediği C# ile birlikte gerçek hayatta interface ve abstract k

Baran Emre Türkmen 7 May 11, 2021
Chamomile is a Java Virtual Machine class file assembler and disassembler.

Chamomile is a Java Virtual Machine class file assembler and disassembler. Installation Maven <repositories> <repository> <id>jitpack.io</

null 15 May 24, 2022
Build parsers in Java

jparsec Builds mini parsers in pure Java. Latest version: 3.0 (requires Java 8+) News 2016-12-05 Removed references to Codehaus in copyright and packa

null 324 Dec 31, 2022
JavaCC - a parser generator for building parsers from grammars. It can generate code in Java, C++ and C#.

JavaCC Java Compiler Compiler (JavaCC) is the most popular parser generator for use with Java applications. A parser generator is a tool that reads a

null 971 Dec 27, 2022
Write parsers for arbitrary text inputs, entirely in Java, with no preprocessing phase

Read me first The license of this project is Apache 2.0. Requires Java 7 or later. The latest versions are: development: 2.1.0-beta.3; requires Java 8

Francis Galiegue 62 Oct 13, 2022
Nokogiri (鋸) is a Rubygem providing HTML, XML, SAX, and Reader parsers with XPath and CSS selector support.

Nokogiri Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby. It provides a sensible, easy-to-understand API for reading, writ

Sparkle Motion 6k Jan 8, 2023
Inria 1.4k Dec 29, 2022
A tool to help eliminate NullPointerExceptions (NPEs) in your Java code with low build-time overhead

NullAway: Fast Annotation-Based Null Checking for Java NullAway is a tool to help eliminate NullPointerExceptions (NPEs) in your Java code. To use Nul

Uber Open Source 3.2k Dec 29, 2022
🏗 Build container images for your Java applications.

Jib ☑️ Jib User Survey What do you like best about Jib? What needs to be improved? Please tell us by taking a one-minute survey. Your responses will h

null 12.4k Jan 9, 2023
Jlink.online - Build optimized Java runtimes in your browser!

jlink.online is a HTTP microservice that builds optimized/minimized Java runtimes on the fly. This project is currently experimental and subject to ch

Tyler Cook 1 Dec 2, 2020
An advanced and highly optimized Java library to build framework

An advanced and highly optimized Java library to build frameworks: it's useful for scanning class paths, generating classes at runtime, facilitating the use of reflection, scanning the filesystem, executing stringified source code and much more...

Burningwave 119 Dec 21, 2022