Module: CultomePlayer::Command::Language

Included in:
CultomePlayer::Command
Defined in:
lib/cultome_player/command/language.rb

Instance Method Summary collapse

Instance Method Details

#semanticsHash<String, Regex>

Note:

The first literal in regex is the command itself.

Returns the semantics of the builtin commands.

Returns:

  • (Hash<String, Regex>)

    The key is the command name and the regex its format.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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

#sintaxHash

Define the sintax of the player language.

Returns:

  • (Hash)

    With the keys :command, :parameters, :actions, :param



7
8
9
10
11
12
13
14
15
16
17
18
# 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_identitiesList<Hash>

Return the token identities.

Returns:

  • (List<Hash>)

    The has contains the type of the token and their format.



47
48
49
50
51
52
53
54
55
56
57
58
# 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