Guidelines for creating interpreted syntax in Java

I understand a lot of POS (Point of Sale) terminals in my work. They mainly talk with the endpoint of the system, which is written in Java, which will be transmitted from the back system.

For receipts, we will write a code at the endpoint that will generate the data that needs to be printed. These receipts can only accept 40 characters per line, so we will basically print each type of receipt that needs to be printed.

What I would like to do is basically come up with a kind of script syntax that I could use to create these receipts.

My idea is to have a GUI program where you can create a receipt, for example

Welcome To John Doe Services Your current balance is $(F4).Format(currency) 

Or something similar. With this, I could then interpret the syntax of $ (F4) .Format (currency) and actually pull the data and format it correctly.

I would like some advice where I should start to look at how to do this. I would like to write this in Java, but I'm not sure where to start. I would rather try to stay away from substring magic.

Thanks in advance.

EDIT: Sorry I should have mentioned, the software we are expanding was written in J ++, so I cannot use Java 5 or 6, the most recent Java I can use is 1.4

+4
source share
2 answers

Scripting for the Java platform is where you want to start, the Rhino JavaScript engine is already built-in during Java 6 runtime, so this is what you should use to simplify your configuration.

If you insist on some Specific Domain , the easiest way to start is with this ANTLR . ANTLR has some great books by Terrance Parr .

+5
source

I see two approaches. One of them is a scripting language or domain language, which is then applied to the receipt. JRuby is the obvious choice for this.

If you want to take a closer look at Java, then another approach is to use a template engine such as Velocity or FreeMarker.

+3
source

Source: https://habr.com/ru/post/1340330/


All Articles