Headline

ANTLR-based object-text mapping for Java

Characteristics

An Technology:ANTLR-based parser for a concrete syntax of companies is provided. The underlying grammar is LL(1). The parser translates text into company objects. To this end, a straightforward object model for companies is used. (In fact, the object model is very similar to the one of Contribution:javaComposition. The mapping is described by the semantic actions within the Technology:ANTLR-based parser description. Pretty printing is also supported in the manner that objects can be exported in the concrete syntax. Pretty printing provides an implementation of Feature:Unparsing. Basic operations are implemented on top of the object model in basic OO programming style.

Illustration

The data model is implemented as POJOs. For example Feature:Company looks like this:

Fragment not found

A Parser for Feature:Company will be generated by Technology:ANTLR using src/main/antlr/Company.g.

A Company if defined by:

company returns [Company c]:
  { $c = new Company(); }
  'company' STRING
  { $c.setName($STRING.text); }
  '{' 
  ( topdept=department
    { $c.getDepts().add($topdept.d); }
  )* 
  '}'
  ;

Feature:Parsing is implemented using the generated Parser:

Fragment not found

Feature:Unparsing pretty prints the company:

Fragment not found

Feature:Total and Feature:Cut are implemented using POJO methods:

Fragment not found

Fragment not found

Test cases are implemented for all Namespace:Features. There are also a valid and an invalid input:

Fragment not found

Fragment not found

Relationships

This contribution shows Object-Text mapping using Technology:ANTLR and Language:Java.

For plain syntax checking with Technology:ANTLR see Contribution:antlrAcceptor.

For a basic example of lexing/tokenization with Technology:ANTLR see Contribution:antlrLexer.

For an implementation of Feature:Parsing using semantic actions with Technology:ANTLR see Contribution:antlrParser

For walking a parsed Feature:Company-tree with Technology:ANTLR see Contribution:antlrTrees.

Architecture

The contribution follows a standardized structure:

  • inputs contains input files for tests
  • src/main/antlr contains grammar files for Technology:ANTLR.
  • src/main/java contains the following packages:
  • src/test/java contains the following packages:

Usage

This contribution uses Technology:Gradle for building. Technology:Eclipse is supported.

See https://github.com/101companies/101simplejava/blob/master/README.md


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    User edits

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.