1.0.0 • Published 4 years ago

pw-grammar v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Prep-Wizard Grammar

Usage:

// Input is something like the following:
const input =  `^XA
^CF50,30^FO20,20^FD{{PRODUCT_NAME}}^FS
^FO0,50^GB700,1,3^FS
^FO250,50^GB1,200,3^FS
^CF50,20
^FO260,66^FR^FDPRODUCTION^FS
^FO250,90^GB700,1,3^FS
^FO260,100^FDEXP^FS
^FO260,127^FDDate^FS
^FO250,150^GB700,1,3^FS
^FO260,160^FDAM^FS
^FO260,185^FDPM^FS
^FO20,66^FD{{EMPLOYEE_NAME(upper: true, prefix: "Emp:")}}^FS
^FO20,88^FD{{PREP_RECEIVED_DATE_BASIC(format: "L", upper: true, prefix: "Rec:")}}^FS
^FO20,110^FD{{PREP_DATE(format: "ddd - LT", prefix: "Prep:")}}^FS
^FO20,140^FR^FD{{USE_BY_DATE_BASIC(format: "ddd - LT", prefix: "UseBy:")}}^FS
^CF20,25
^FO20,168^FR^FD{{USE_BY_DATE_BASIC(format: "L")}}^FS
^XZ`;

let output: string;
let lexer = new Lexer(input);
let parser = new Parser(lexer);

// This will tokenize everything and validate that the grammar is correct
// If anything goes wrong, this will throw.
try {
	parser.program();
}
catch(error) {
	// Handle the error.
}

// Example of emitting what you need
let emitter = new Emitter(parser)
                  .setEmployeeName("Eli")
                  .setProductName("Anchovies")
                  .setPrepReceivedDateBasic("...")
                  .setUseByDateBasic("...")
                  .setPrepDate("...");
					
// This will replace the product names, employee names, etc. with
// what you specified when creating the Emitter. If anything is
// not set that should be, this will throw.
try {
	output = emitter.emit();
}
catch(error) {
	// Handle the error.
}
1.0.0

4 years ago