GithubHelp home page GithubHelp logo

gsl_getopt's Introduction

GSL C Getopt parser generator

Introduction

After reading GSL I decided to try learning the key concepts and grasp the idea behind this approach to code generation. This is the result of my research: getopt C command-line parser generator. You just simply write an XML specification of the parser and the GSL script generates .c and .h file implementing the getopt based parser code. In case of parsers where the code connected implementing one option is scattered throughout the code base this approach is a clear win. You end up with short specification and a lot of code generated. The example specification is very simple - about 80 lines of code - and the generated code has about 700 lines of code.

Usage

Got to the model directory and run the generate script:

cd model
./generate

Note that you need to have the GSL tool installed. The C source and header files will be created in src/ and include/ directories. To add your own parser specification create an XML file in the model directory and modify the generate script. Look at the file model/example_parser.xml for example parser specification.

The GSL tool

First I had the impression that the tool is too simple to handle all the required XML file transformations but luckily I was wrong. GSL if carefully designed to provide the minimum constructs allowing practically any task you can imagine. It is designed "the Linux way" - compact and orthogonal. In other words it stays true to "the KISS principle". The .gls files contain two intertwined 'flows' of code - the GSL code and the 'target' language code. For readability it is better to keep them indented separately. Also the Vim coloring for GSL helps a lot to visually switch between the two flows. Learning the concepts and writing this generator took me about five hours. If you need more examples please look at FileMQ project. It has generators for protocol parsers and state machines in C and Java. I would also recommend the Peter Hintjens blog and his books including the ZeroMQ guide.

Contact

If you have questions, contact Mariusz Ryndzionek at:

[email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.