GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mfriesen/BNFParserJava

BranchesTags
Open more actions menu

Latest commit

 

History

81 Commits
81 Commits

Folders and files

NameName
Last commit message
Last commit date
.settings
.settings
 
 
src
src
 
 
.checkstyle
.checkstyle
 
 
.classpath
.classpath
 
 
.gitignore
.gitignore
 
 
.project
.project
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
checkstyle-import-control.xml
checkstyle-import-control.xml
 
 
checkstyle-suppressions.xml
checkstyle-suppressions.xml
 
 
checkstyle.xml
checkstyle.xml
 
 
pom.xml
pom.xml
 
 

Repository files navigation

BNFParserJava

BNFParserJava is a Backus-Naur Form Framework for JAVA written by Mike Friesen in Java and released under the Apache 2 Open Source License.

An Objective-C version is also available.

BNFParserJava was inspired by the framework ParseKit by Todd Ditchendorf.

The BNFParserJava Framework offers 3 basic services of general interest to developers:

  1. String Tokenization via the BNFTokenizerFactory and BNFToken classes

  2. Property Key/Value mapper via PropertyParser

  3. Text Parsing via Grammars via BNFParser see grammar syntax

1. String Tokenization

The string tokenizer breaks down any string into a series of letter/number/symbols for easy processing.

How do I use it?

String text = "The cow jumped over the moon!";
BNFTokenizerFactory factory = new BNFTokenizerFactoryImpl();
BNFToken token = factory.tokens(text);
while (token != null) {
  System.out.println("TOKEN " + token.getStringValue());
  token = token.getNextToken();
}

2. PropertyParser

Uses the string tokenizer to parse a string and create key/value mapping based on the '=' symbol.

How do I use it?

String text = "sample key = sample value";
PropertyParser parser = new PropertyParser();
Map<String, String> keyValueMap = parser.parse(text);
Assert.assertNotNull(keyValueMap.get("sample key"));

3. Text Parsing via Grammars

BNFParser currently only ships with a JSON grammar so the example are based on that.

How do I use it?

// Create String Tokens
String text = "{ \"key\":\"value\"}";
BNFTokenizerFactory tokenizerFactory = new BNFTokenizerFactoryImpl();
BNFToken token = tokenizerFactory.tokens(text);

// Create Backus-Naur Form State Definitions
BNFSequenceFactory factory = new BNFSequenceFactoryImpl();
Map<String, List<BNFSequence>> map = sdf.json();

// Run Tokens through Parser
BNFParser parser = new BNFParserImpl(map);
BNFParseResult result = parser.parse(token);

// Verify results

// verify text passes grammar:
Assert.assertTrue(result.isSuccess()); // verify text passes grammar

// the "first" token, same as the token returned from the tokenizer factory:
Assert.assertNotNull(result.getTop());

// the "first" error token, this token and any afterwards are considered to not have passed the grammar:
Assert.assertNull(result.getError());

Bugs and Feedback

For bugs, questions and discussions please use the Github Issues.

Contributing

We love contributions! If you'd like to contribute please submit a pull request via Github.

LICENSE

This library is distributed under the Apache 2 Open Source License.

About

No description, website, or topics provided.

Resources

Readme
Apache-2.0 license
Activity

Stars

5 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.