Module: DrgDSL

Defined in:
lib/drgdsl.rb,
lib/drgdsl/ast.rb,
lib/drgdsl/parser.rb,
lib/drgdsl/version.rb,
lib/drgdsl/visitor.rb,
lib/drgdsl/ast_builder.rb,
lib/drgdsl/paren_cleaner.rb,
lib/drgdsl/pretty_printer.rb,
lib/drgdsl/core_extensions.rb

Defined Under Namespace

Modules: Ast, CoreExtensions, Visitor Classes: AstBuilder, ParenCleaner, Parser, ParserError, PrettyPrinter, UnknownCstError

Constant Summary collapse

VERSION =
"1.2.0"

Class Method Summary collapse

Class Method Details

.json(input) ⇒ String

Returns JSON representation of the AST.

Parameters:

  • input (String)

Returns:

  • (String)

    JSON representation of the AST



24
25
26
# File 'lib/drgdsl.rb', line 24

def self.json(input)
  Oj.dump parse(input).to_hash, mode: :compat
end

.parse(input) ⇒ Ast::Node

Parameters:

  • input (String)

Returns:



18
19
20
# File 'lib/drgdsl.rb', line 18

def self.parse(input)
  Parser.parse(input)
end

.pretty_print(input, **options) ⇒ String

Returns pretty printed DrgDSL expression.

Examples:

Pretty printing with various options

input = "(pdx in table (a  )) and (drg (f46) or (drg (g22) and los < 3))"
DrgDSL.pretty_print(input)
# =>
#     (
#       PDX IN TABLE (A)
#     )
#     AND (
#       DRG (F46)
#       OR (
#         DRG (G22)
#         AND LOS < 3
#       )
#     )

DrgDSL.pretty_print(input, remove_redundant_parens: true)
# =>
#     PDX IN TABLE (A)
#     AND (
#       DRG (F46)
#       OR DRG (G22)
#       AND LOS < 3
#     )

DrgDSL.pretty_print(input, remove_redundant_parens: true, multiline: false)
# => PDX IN TABLE (A) AND (DRG (F46) OR DRG (G22) AND LOS < 3)

DrgDSL.pretty_print(input, remove_redundant_parens: true, output_format: html)
# =>
#     <pre>
#     <span class="drgdsl-variable">PDX</span> <span class="drgdsl-keyword">IN TABLE</span> (<span class="drgdsl-table">A</span>)
#     <span class="drgdsl-keyword">AND</span> (
#       <span class="drgdsl-variable">DRG</span> (<span class="drgdsl-drg">F46</span>)
#       <span class="drgdsl-keyword">OR</span> <span class="drgdsl-variable">DRG</span> (<span class="drgdsl-drg">G22</span>)
#       <span class="drgdsl-keyword">AND</span> <span class="drgdsl-variable">LOS</span> <span class="drgdsl-op">&lt;</span> <span class="drgdsl-constant">3</span>
#     )
#     </pre>

Parameters:

  • input (String)
  • remove_redundant_parens (Boolean)

    (false)

  • multiline (Boolean)

    (true) pass false to print the expression without any newlines.

  • output_format (Symbol)

    (:string) also supports :html and :bash.

Returns:

  • (String)

    pretty printed DrgDSL expression



74
75
76
# File 'lib/drgdsl.rb', line 74

def self.pretty_print(input, **options)
  PrettyPrinter.pretty_print(input, **options)
end