Class: Gloo::Core::Parser
- Inherits:
-
Object
- Object
- Gloo::Core::Parser
- Defined in:
- lib/gloo/core/parser.rb
Instance Method Summary collapse
-
#initialize(engine) ⇒ Parser
constructor
Set up the parser.
-
#parse_immediate(full_cmd) ⇒ Object
Parse a command from the immediate execution context.
-
#run(cmd) ⇒ Object
Parse a command and then run it if it parsed correctly.
-
#split_params(cmd) ⇒ Object
If additional params were provided, split them out from the token list.
Constructor Details
#initialize(engine) ⇒ Parser
Set up the parser.
15 16 17 18 |
# File 'lib/gloo/core/parser.rb', line 15 def initialize( engine ) @engine = engine @engine.log.debug 'parser intialized...' end |
Instance Method Details
#parse_immediate(full_cmd) ⇒ Object
Parse a command from the immediate execution context.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gloo/core/parser.rb', line 23 def parse_immediate( full_cmd ) # Break the full command into verb and params cmd, params = split_params full_cmd # Params are the parenthetical part of the command at the end params = Gloo::Core::Tokens.new( params ) if params tokens = Gloo::Core::Tokens.new( cmd ) dic = Gloo::Core::Dictionary.instance verb = dic.find_verb( tokens.verb ) return verb.new( @engine, tokens, params ) if verb @engine.err "Verb '#{tokens.verb}' was not found." return nil end |
#run(cmd) ⇒ Object
Parse a command and then run it if it parsed correctly.
56 57 58 59 |
# File 'lib/gloo/core/parser.rb', line 56 def run( cmd ) v = parse_immediate( cmd ) Gloo::Exec::Runner.go( @engine, v ) if v end |
#split_params(cmd) ⇒ Object
If additional params were provided, split them out from the token list.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gloo/core/parser.rb', line 42 def split_params( cmd ) params = nil i = cmd.rindex( '(' ) if i && cmd.strip.end_with?( ')' ) pstr = cmd[ i + 1..-1 ] params = pstr.strip[ 0..-2 ] if pstr cmd = cmd[ 0, i].strip end return cmd, params end |