DrgDSL

Installation

Add this line to your application's Gemfile:

gem 'drgdsl', git: '[email protected]:gems/drgdsl.git'

And then execute:

$ bundle

Usage

From Ruby

# Use .parse to get an AST Object
DrgDSL.parse("PDX IN TABLES( A0801PXA, A0802PXA, A0803PXA, A0804PXA  )")
# => #<DrgDSL::Ast::BasicExpression:0x00007f9ad8e29558 @condition=#<DrgDSL::Ast::TableCondition:0x00007f9ad8e2ae58 @comparison=nil, @op="in tables", @tables=["A0801PXA", "A0802PXA", "A0803PXA", "A0804PXA"]>, @variable=#<DrgDSL::Ast::Variable:0x00007f9ad8e30010 @name="PDX">>

# Use .json to get a JSON representation of the AST
DrgDSL.json("PDX IN TABLES( A0801PXA, A0802PXA, A0803PXA, A0804PXA  )")
# => "{\"basic\":{\"var\":{\"name\":\"PDX\"},\"condition\":{\"table_condition\":{\"op\":\"in tables\",\"tables\":[\"A0801PXA\",\"A0802PXA\",\"A0803PXA\",\"A0804PXA\"],\"comparison\":null}}}}"

From the CLI

$ drgdsl "PDX IN TABLES( A0801PXA, A0802PXA, A0803PXA, A0804PXA  )"

{
    "basic": {
        "condition": {
            "table_condition": {
                "comparison": null,
                "op": "in tables",
                "tables": [
                    "A0801PXA",
                    "A0802PXA",
                    "A0803PXA",
                    "A0804PXA"
                ]
            }
        },
        "var": {
            "name": "PDX"
        }
    }
}

Traversing the AST

DrgDSL comes with a mixin that provides AST visit hooks. See DrgDSL::Visitor.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

License

The gem is available as open source under the terms of the MIT License.