module CultomePlayer::Command::Language

Public Instance Methods

semantics() click to toggle source

Returns the semantics of the builtin commands.

@note The first literal in regex is the command itself. @return [Hash<String, Regex>] The key is the command name and the regex its format.

# File lib/cultome_player/command/language.rb, line 24
def semantics
  {
    "play" => /^literal(literal|number|criteria|object|[\s]+)*$/,
    "show" => /^literal(number|object|[\s]+)*$/,
    "search" => /^literal(literal|criteria|[\s]+)+$/,
    "enqueue" => /^literal(literal|number|criteria|object|[\s]+)+$/,
    "connect" => /^literal ((literal)|(path) bubble (literal))$/,
    "disconnect" => /^literal (literal)$/,
    "stop" => /^literal[\s]*$/,
    "pause" => /^literal (boolean)$/,
    "prev" => /^literal[\s]*$/,
    "next" => /^literal[\s]*$/,
    "quit" => /^literal[\s]*$/,
    "ff" => /^literal(number|[\s]+)*$/,
    "fb" => /^literal(number|[\s]+)*$/,
    "shuffle" => /^literal[\s]+(boolean)$/,
    "repeat" => /^literal[\s]*$/,
  }
end
sintax() click to toggle source

Define the sintax of the player language.

@return [Hash] With the keys :command, :parameters, :actions, :param

# File lib/cultome_player/command/language.rb, line 7
def sintax
  # <command>    : <action> | <action> <parameters>
  # <action>     : literal
  # <parameters> : <param> | <param> <parameters>
  # <param>      : literal | criteria | number | object | path | bubble
  {
    command: ["action", "action parameters"],
    parameters: ["param", "param parameters"],
    action: [:literal],
    param: [:literal, :criteria, :number, :object, :path, :boolean, :bubble],
  }
end
token_identities() click to toggle source

Return the token identities.

@return [List<Hash>] The has contains the type of the token and their format.

# File lib/cultome_player/command/language.rb, line 47
def token_identities
  [
    {type: :bubble, identity: /^(=>|->)$/},
    {type: :number, identity: /^([\d]+)$/},
    {type: :object, identity: /^@([\w\d]+)$/},
    {type: :path, identity: /^(['"]?(?:\/|~\/)[\/\w\d\s.]+)["']?$/},
    {type: :criteria, identity: /^([\w]+):([\d\w\s]+)$/, captures: 2, labels: [:criteria, :value]},
    {type: :boolean, identity: /^(on|off|yes|false|true|si|no|y|n|s|ok)$/},
    {type: :ip, identity: /^([\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})$/},
    {type: :literal, identity: /^['"]?([\w\d\s%]+)['"]?$/}, # add % for the alias parameters placeholders
  ]
end