Class: Flexr::Options

Inherits:
Struct
  • Object
show all
Defined in:
lib/flexr/options.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#accelObject

Returns the value of attribute accel

Returns:

  • (Object)

    the current value of accel



6
7
8
# File 'lib/flexr/options.rb', line 6

def accel
  @accel
end

#backendObject

Returns the value of attribute backend

Returns:

  • (Object)

    the current value of backend



6
7
8
# File 'lib/flexr/options.rb', line 6

def backend
  @backend
end

#colorObject

Returns the value of attribute color

Returns:

  • (Object)

    the current value of color



6
7
8
# File 'lib/flexr/options.rb', line 6

def color
  @color
end

#eval_modeObject

Returns the value of attribute eval_mode

Returns:

  • (Object)

    the current value of eval_mode



6
7
8
# File 'lib/flexr/options.rb', line 6

def eval_mode
  @eval_mode
end

#formatObject

Returns the value of attribute format

Returns:

  • (Object)

    the current value of format



6
7
8
# File 'lib/flexr/options.rb', line 6

def format
  @format
end

#max_dfa_statesObject

Returns the value of attribute max_dfa_states

Returns:

  • (Object)

    the current value of max_dfa_states



6
7
8
# File 'lib/flexr/options.rb', line 6

def max_dfa_states
  @max_dfa_states
end

#overridesObject

Returns the value of attribute overrides

Returns:

  • (Object)

    the current value of overrides



6
7
8
# File 'lib/flexr/options.rb', line 6

def overrides
  @overrides
end

#standaloneObject

Returns the value of attribute standalone

Returns:

  • (Object)

    the current value of standalone



6
7
8
# File 'lib/flexr/options.rb', line 6

def standalone
  @standalone
end

#table_compressionObject

Returns the value of attribute table_compression

Returns:

  • (Object)

    the current value of table_compression



6
7
8
# File 'lib/flexr/options.rb', line 6

def table_compression
  @table_compression
end

#table_formatObject

Returns the value of attribute table_format

Returns:

  • (Object)

    the current value of table_format



6
7
8
# File 'lib/flexr/options.rb', line 6

def table_format
  @table_format
end

#token_kindObject

Returns the value of attribute token_kind

Returns:

  • (Object)

    the current value of token_kind



6
7
8
# File 'lib/flexr/options.rb', line 6

def token_kind
  @token_kind
end

#warn_as_errorObject

Returns the value of attribute warn_as_error

Returns:

  • (Object)

    the current value of warn_as_error



6
7
8
# File 'lib/flexr/options.rb', line 6

def warn_as_error
  @warn_as_error
end

#warn_levelObject

Returns the value of attribute warn_level

Returns:

  • (Object)

    the current value of warn_level



6
7
8
# File 'lib/flexr/options.rb', line 6

def warn_level
  @warn_level
end

Class Method Details

.defaultObject



11
12
13
14
15
16
# File 'lib/flexr/options.rb', line 11

def self.default
  new(backend: :table, token_kind: :array, accel: :auto, standalone: false,
      eval_mode: false, table_compression: :rows, table_format: :literal,
      max_dfa_states: 100_000, warn_level: :default, warn_as_error: false,
      color: :auto, format: :human, overrides: {})
end

Instance Method Details

#generator_optionsObject



37
38
39
# File 'lib/flexr/options.rb', line 37

def generator_options
  (overrides || {}).merge(warn_as_error: warn_as_error, color: color)
end

#set(name, value) ⇒ Object



18
19
20
21
22
# File 'lib/flexr/options.rb', line 18

def set(name, value)
  self[name] = value
  self.overrides ||= {}
  overrides[name] = value
end

#validate!Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/flexr/options.rb', line 24

def validate!
  validate_value!(backend, Configuration::BACKENDS, :backend)
  validate_value!(token_kind, Configuration::TOKEN_KINDS, :token_kind)
  validate_value!(accel, Configuration::ACCELERATORS, :accel)
  validate_value!(table_compression, %i[none rows full], :table_compression)
  validate_value!(table_format, %i[literal packed], :table_format)
  validate_value!(warn_level, %i[all default none], :warn_level)
  validate_value!(color, %i[auto always never], :color)
  validate_value!(format, %i[human json], :format)
  raise ArgumentError, "unsupported max_dfa_states: #{max_dfa_states.inspect}" unless max_dfa_states.is_a?(Integer) && max_dfa_states.positive?
  self
end