Skip to content

tajmone/lemon-slicer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lemon Slicer

A standalone binary de-amalgamator to split the Lemon parser generator into multiple source files.

Created by Tristano Ajmone on August 12, 2019. MIT License.

Lemon Slicer v1.0.0 | PureBasic 5.70 LTS

Table of Contents


Project Files

TLTR: What Does It Do?

Lemon Slicer takes the source files "lemon.c" and "lempar.c" from the current folder, copies them into the "/sliced/" destination folder, and splits the amalgamated contents of "lemon.c" across the following files:

  • action.c
  • build.c
  • build.h
  • configlist.c
  • configlist.h
  • error.c
  • error.h
  • lemon.c
  • main.c
  • msort.c
  • option.c
  • option.h
  • parse.c
  • parse.h
  • plink.c
  • plink.h
  • report.c
  • report.h
  • set.c
  • set.h
  • struct.h
  • table.c
  • table.h

Finally, it injects at the end of the left-over contents of the "lemon.c" file all the required #include directives to ensure that the split contents are loaded back in the correct order, so that the Lemon parser remains buildable by compiling "lemon.c".

The "lempar.c" template file is copied over to the destination folder untouched, for it's not an amalgamated file.

What Is All This About?

Lemon Slicer was created as a maintainance tool for the Lemon Grove project, which hosts the source files of the Lemon parser generator:

The Lemon source file lemon.c, like most tools from the SQLite project, is created by merging multiple C sources into a single file via a technique called "amalgamation", in order to reduce the number of file dependencies and improve performance (5-10% speed gain). Except that today only the single source file of Lemon survives in the SQLite project — and all updates to its code are done directly in that amalgamated single source file.

I wanted to include in the Lemon Grove project a split version of the Lemon source files, to simplify studying its code and working on derivative versions and ports. Reversing the amalgamation is not a hard task in itself, for the amalgamator adds some comment lines indicating the name of the original file from which the code was taken:

void Configlist_reset(void);

/********* From the file "error.h" ***************************************/
void ErrorMsg(const char *, int,const char *, ...);

/****** From the file "option.h" ******************************************/
enum option_type { OPT_FLAG=1,  OPT_INT,  OPT_DBL,  OPT_STR,
         OPT_FFLAG, OPT_FINT, OPT_FDBL, OPT_FSTR};

So splitting the file manually is neither a huge nor hard task. The problem is that in the Lemon Grove project I need to keep the split sources always up to date with the unsplit sources, which are updated quite often on the SQLite repository. Therefore, I needed to create a small tool to automate this task, so that whenever I update the Lemon sources I can easily update their split version in a single click — so I created the Lemon Slicer tool.

About Lemon Slicer

  • lemon-slicer.pb — Lemon Slicer source (PureBasic).
  • lemon-slicer.exe — precompiled Lemon Slicer binary (64-bits).

Lemon Slicer is written in PureBasic and compiles as a single-file console application, no dependencies whatsoever. It can be compiled for Windows, Linux and macOS, targeting either 32- or 64-bits, although it was tested only on Windows so far.

Because PureBasic is a commercial tool, I've included a precompiled 64-bits binary in the repository itself — which also simplifies its integration in the Lemon Grove project (for which it was created) since it can be easily downloaded/updated via cURL (now included in Windows 10).

Usage Instructions

Lemon Slicer must be executed in a folder containing the (amalgamated) Lemon source files "lemon.c" and "lempar.c", otherwise it will fail. Just double click on lemon-slicer.exe, or invoke it from the command line, and the tool will work its magic in a matter of seconds.

It will create an output folder named "/sliced/", with all the de-amalgamated files from "lemon.c", plus "lempar.c" (which is just copied as is).

IMPORTANT! — At each execution, Lemon Slicer will delete every "*.c" and "*.h" file inside the "/sliced/" folder, before creating the new split files! This was enforced to ensure a clean output at each run. Files with other extensions won't be affected, but avoid using the output folder as a storage for important files.

Before exiting, Lemon Slicer will print a brief report on how many files were created from splitting "lemon.c", or an error message (and exit code 1) in case something went wrong.

Since the task at hand is quite straightforward, there are no options switches. Source files locations and destination folder are hardcoded into the application, for they mirror the needs of the Lemon Grove project — but these can easily be tweaked in the source code, if you need to.

License

Lemon Slicer is released under the MIT License:

MIT License

Copyright (c) 2019 Tristano Ajmone <tajmone@gmail.com>
https://github.com/tajmone/lemon-slicer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

When distributing Lemon Slicer in compiled binary form, you must also include the full LICENSE file found in this project, for the executable file contains third party components which must also be credited and licensed.

External Links