harby 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80e0ad800028aa7cbefa4321ac94d5fc9b98ec18
4
+ data.tar.gz: 5696dbb4bd056261d88b220bf0b6dc98dee0a002
5
+ SHA512:
6
+ metadata.gz: 54708102b85c48181bec88bbad276f90a5b785ebadeaf1bc9c37f22467499076799113519bc8ca520a33e5b1a1e387ac92e6883320175173de3285a87cbf3bf3
7
+ data.tar.gz: 8aab3de3cea7344a55276ab816748801c582cd7dcd35dcda27552ea8e4513120afce9336602ee8e521c420e49157ea6cbcc45dd339f318ac2a3f02afe3be7a6a
@@ -13,5 +13,4 @@ require "harby/grammar/regex"
13
13
  require "harby/grammar/string"
14
14
  require "harby/grammar/arguments"
15
15
 
16
- require "harby/null_delegate"
17
16
  require "harby/parser"
@@ -5,23 +5,23 @@ module Harby
5
5
  include Numeric
6
6
  include Regex
7
7
  include String
8
-
8
+
9
9
  rule arguments
10
- first_arg:argument rest_args:(" "+ arg:argument)* {
10
+ ' '* first_arg:argument rest_args:(' '+ arg:argument)* ' '* {
11
11
  def args
12
12
  [first_arg] + rest_args
13
13
  end
14
-
14
+
15
15
  def parsed_args
16
16
  @parsed_args ||= args.map { |arg| arg.parsed_value }
17
17
  end
18
-
18
+
19
19
  def rest_args
20
20
  super.elements.map { |space_and_arg| space_and_arg.arg }
21
21
  end
22
22
  }
23
23
  end
24
-
24
+
25
25
  rule argument
26
26
  command / numeric / regex / string
27
27
  end
@@ -6,21 +6,17 @@ module Harby
6
6
  def args
7
7
  arguments.parsed_args
8
8
  end
9
-
9
+
10
10
  def name
11
11
  args.first
12
12
  end
13
-
13
+
14
14
  def parsed_args
15
15
  args[1..-1]
16
16
  end
17
-
17
+
18
18
  def parsed_value
19
- if delegate.respond_to?(:on_command)
20
- delegate.on_command(name, parsed_args)
21
- else
22
- ""
23
- end
19
+ delegate.call name, parsed_args
24
20
  end
25
21
  }
26
22
  end
@@ -4,33 +4,49 @@ module Harby
4
4
  rule string
5
5
  double_quoted / single_quoted / naked
6
6
  end
7
-
7
+
8
+ rule double_quote
9
+ '"' / '“' / '”'
10
+ end
11
+
12
+ rule escaped_double_quote
13
+ '\\' double_quote
14
+ end
15
+
8
16
  rule double_quoted
9
- '"' value:('\\"' / command / !'"' .)* '"' {
17
+ double_quote value:(escaped_double_quote / command / !double_quote .)* double_quote {
10
18
  def parsed_value
11
19
  value.elements.map do |element|
12
20
  if element.respond_to?(:parsed_value)
13
21
  element.parsed_value
14
22
  else
15
- element.text_value.gsub('\\"', '"')
23
+ element.text_value.gsub /\\(["“”])/, '\1'
16
24
  end
17
- end.join("")
25
+ end.join ''
18
26
  end
19
27
  }
20
28
  end
21
-
29
+
30
+ rule single_quote
31
+ "'" / '‘' / '’'
32
+ end
33
+
34
+ rule escaped_single_quote
35
+ '\\' single_quote
36
+ end
37
+
22
38
  rule single_quoted
23
- "'" value:("\\'" / !"'" .)* "'" {
39
+ single_quote value:(escaped_single_quote / !single_quote .)* single_quote {
24
40
  def parsed_value
25
- value.text_value.gsub("\\'", "'")
41
+ value.text_value.gsub /\\(['‘’])/, '\1'
26
42
  end
27
43
  }
28
44
  end
29
-
45
+
30
46
  rule naked
31
- ("\\ " / !" " !"]" .)+ {
47
+ ('\\ ' / !' ' !']' .)+ {
32
48
  def parsed_value
33
- text_value.gsub("\\ ", " ").gsub("\\/", "/")
49
+ text_value.gsub('\\ ', ' ').gsub '\\/', '/'
34
50
  end
35
51
  }
36
52
  end
@@ -1,35 +1,27 @@
1
1
  module Harby
2
2
  class Parser
3
3
  attr_reader :parser
4
-
5
- def initialize(delegate = nil)
4
+
5
+ def initialize(delegate = nil, &block)
6
6
  @parser = Grammar::ArgumentsParser.new
7
- @parser.delegate = delegate || NullDelegate.new
7
+ @parser.delegate = delegate || block
8
8
  end
9
-
10
- def parse(input)
11
- result = @parser.parse(input)
12
- result ? result.parsed_args : nil
13
- end
14
-
9
+
15
10
  def delegate=(delegate)
16
11
  @parser.delegate = delegate
17
12
  end
18
-
13
+
19
14
  def delegate
20
15
  @parser.delegate
21
16
  end
22
-
17
+
23
18
  def failure_reason
24
19
  @parser.failure_reason
25
20
  end
26
-
27
- def self.parse(input, delegate = nil)
28
- new(delegate).parse(input)
21
+
22
+ def parse(input)
23
+ result = @parser.parse(input)
24
+ result ? result.parsed_args : nil
29
25
  end
30
26
  end
31
-
32
- def self.parse(input, delegate = nil)
33
- Parser.parse(input, delegate)
34
- end
35
27
  end
metadata CHANGED
@@ -1,67 +1,89 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ross Paffett
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-11-22 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: treetop
16
- requirement: &70301669384000 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: 1.4.10
19
+ version: '1.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.3
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *70301669384000
25
- description: A grammar-based parser for textual commands. Ideal for IRC bots.
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.3'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.3'
47
+ description: Parser for a Tcl-like syntax. Ideal for IRC bots.
26
48
  email:
27
49
  - ross@rosspaffett.com
28
50
  executables: []
29
51
  extensions: []
30
52
  extra_rdoc_files: []
31
53
  files:
54
+ - lib/harby.rb
32
55
  - lib/harby/concerns/delegation.rb
33
56
  - lib/harby/ext/compiled_parser.rb
34
57
  - lib/harby/ext/syntax_node.rb
35
- - lib/harby/null_delegate.rb
36
- - lib/harby/parser.rb
37
- - lib/harby.rb
38
58
  - lib/harby/grammar/arguments.treetop
39
59
  - lib/harby/grammar/command.treetop
40
60
  - lib/harby/grammar/numeric.treetop
41
61
  - lib/harby/grammar/regex.treetop
42
62
  - lib/harby/grammar/string.treetop
63
+ - lib/harby/parser.rb
43
64
  homepage: http://github.com/raws/harby
44
- licenses: []
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
45
68
  post_install_message:
46
69
  rdoc_options: []
47
70
  require_paths:
48
71
  - lib
49
72
  required_ruby_version: !ruby/object:Gem::Requirement
50
- none: false
51
73
  requirements:
52
- - - ! '>='
74
+ - - ">="
53
75
  - !ruby/object:Gem::Version
54
- version: 1.9.2
76
+ version: '0'
55
77
  required_rubygems_version: !ruby/object:Gem::Requirement
56
- none: false
57
78
  requirements:
58
- - - ! '>='
79
+ - - ">="
59
80
  - !ruby/object:Gem::Version
60
81
  version: '0'
61
82
  requirements: []
62
83
  rubyforge_project:
63
- rubygems_version: 1.8.11
84
+ rubygems_version: 2.4.5
64
85
  signing_key:
65
- specification_version: 3
66
- summary: Simple textual command parser
86
+ specification_version: 4
87
+ summary: Parser for a Tcl-like syntax.
67
88
  test_files: []
89
+ has_rdoc:
@@ -1,5 +0,0 @@
1
- module Harby
2
- class NullDelegate
3
- def on_command(*args); end
4
- end
5
- end