yard2steep 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,13 @@
1
1
  module Yard2steep
2
2
  class Type
3
3
  class Parser
4
- # @param [Array<String>]
4
+ # @param [Array<String>] tokens
5
5
  # @return [Array<TypeBase>]
6
6
  def self.parse(tokens)
7
7
  Parser.new(tokens).parse
8
8
  end
9
9
 
10
- # @param [Array<String>]
10
+ # @param [Array<String>] tokens
11
11
  def initialize(tokens)
12
12
  @tokens = tokens
13
13
  @types = []
@@ -100,6 +100,7 @@ module Yard2steep
100
100
  end
101
101
  end
102
102
 
103
+ # @return [HashType]
103
104
  def parse_hash
104
105
  debug_print!("parse_hash, peek: #{peek}")
105
106
 
@@ -107,8 +108,11 @@ module Yard2steep
107
108
  when '{'
108
109
  expect!('{')
109
110
  key = parse_multiple_types('=')
111
+ Util.assert! { key.size > 0 }
112
+
110
113
  expect!('>')
111
114
  val = parse_multiple_types('}')
115
+ Util.assert! { val.size > 0 }
112
116
  HashType.new(
113
117
  key: key,
114
118
  val: val,
@@ -4,7 +4,7 @@ require 'yard2steep/type/parser'
4
4
 
5
5
  module Yard2steep
6
6
  class Type
7
- # @param [Strng]
7
+ # @param [String] text
8
8
  # @return [String]
9
9
  def self.translate(text)
10
10
  Type.new(text).translate
@@ -15,6 +15,7 @@ module Yard2steep
15
15
  @text = text
16
16
  end
17
17
 
18
+ # @return [String]
18
19
  def translate
19
20
  tokens = tokens(@text)
20
21
  ast = Parser.parse(tokens)
@@ -31,9 +32,14 @@ module Yard2steep
31
32
  def tokens(str)
32
33
  r = []
33
34
  s = StringScanner.new(str)
34
- while !s.eos?
35
+ while true
35
36
  s.scan(S_RE)
36
- r.push(s.scan(TOKENS))
37
+ break if s.eos?
38
+ if t = s.scan(TOKENS)
39
+ r.push(t)
40
+ else
41
+ raise "token must exist!"
42
+ end
37
43
  end
38
44
  r
39
45
  end
@@ -2,10 +2,18 @@ module Yard2steep
2
2
  module Util
3
3
  class AssertError < RuntimeError; end
4
4
 
5
- # @param [{ () -> any }]
6
5
  # @return [void]
7
6
  def self.assert!(&block)
8
7
  raise AssertError.new("Assertion failed!") if !block.call
8
+ rescue AssertError => e
9
+ # NOTE: Enable when debug option is true
10
+ # print e
11
+ # code = <<-CODE
12
+ # require 'pry'
13
+ # binding.pry
14
+ # CODE
15
+ # eval(code, block.binding)
16
+ raise e
9
17
  end
10
18
  end
11
19
  end
@@ -1,3 +1,3 @@
1
1
  module Yard2steep
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -4,59 +4,46 @@ end
4
4
  class Yard2steep::Parser
5
5
  @debug: any
6
6
  @file: any
7
+ @comments_map: any
7
8
  @ast: any
8
- @stack: any
9
- @state: any
10
9
  @current_class: any
11
- @p_types: any
12
10
  @r_type: any
13
- @m_name: any
14
- def initialize: () -> any
11
+ @p_types: any
12
+ def initialize: () -> Hash<any, any>
15
13
  def parse: (any, any, ?debug: bool) -> any
16
- def reset_method_context!: () -> any
17
- def parse_line: (any) -> any
18
- def try_parse_comment: (any) -> bool
19
- def try_parse_param_or_return: (any) -> void
20
- def try_parse_end: (any) -> bool
21
- def try_parse_postfix_if: (any) -> any
22
- def try_parse_begin_end: (any) -> bool
23
- def try_parse_class: (any) -> bool
24
- def try_parse_constant: (any) -> bool
25
- def try_parse_singleton_class: (any) -> bool
26
- def try_parse_param: (any) -> bool
27
- def try_parse_return: (any) -> bool
28
- def try_parse_method: (any) -> bool
29
- def try_parse_method_with_no_action: (any) -> bool
30
- def parse_method_params: (any) -> any
31
- def try_parse_attr: (any) -> bool
32
- def push_state!: (any) -> any
33
- def pop_state!: () -> void
34
- def stack_is_empty?: () -> any
14
+ def parse_program: (any) -> any
15
+ def parse_stmts: (any) -> any
16
+ def parse_stmt: (any) -> any
17
+ def parse_defs: (any) -> any
18
+ def parse_def: (any) -> any
19
+ def parse_method_impl: (any, any, any) -> any
20
+ def extract_p_types!: (any) -> void
21
+ def parse_comment!: (any) -> any
22
+ def try_param_comment: (any) -> bool
23
+ def try_return_comment: (any) -> bool
24
+ def parse_params: (any) -> any
25
+ def parse_paren_params: (any) -> any
26
+ def parse_no_paren_params: (any) -> any
27
+ def within_context: () -> any
28
+ def parse_class_or_module: (any) -> any
29
+ def parse_bodystmt: (any) -> any
30
+ def parse_assign: (any) -> void
31
+ def parse_command: (any) -> void
32
+ def parse_command_args_add_block: (any) -> any
33
+ def parse_method_add_arg: (any) -> void
34
+ def parse_attr_reader: (any) -> any
35
+ def extract_comments: (any) -> any
36
+ def debug_print!: (any) -> void
35
37
  def type_node: (any) -> any
36
- def debug_print!: (any, ?offset: Integer) -> void
38
+ def block_type_node: (any) -> any
37
39
  def normalize_type: (any) -> any
38
40
  end
39
41
 
40
42
  Yard2steep::Parser::S_RE: Regexp
41
- Yard2steep::Parser::S_P_RE: Regexp
42
- Yard2steep::Parser::PRE_RE: Regexp
43
- Yard2steep::Parser::POST_RE: Regexp
44
- Yard2steep::Parser::CLASS_RE: Regexp
45
- Yard2steep::Parser::MODULE_RE: Regexp
46
- Yard2steep::Parser::S_CLASS_RE: Regexp
47
- Yard2steep::Parser::END_RE: Regexp
48
- Yard2steep::Parser::CONSTANT_ASSIGN_RE: Regexp
49
- Yard2steep::Parser::POSTFIX_IF_RE: Regexp
50
- Yard2steep::Parser::BEGIN_END_RE: Regexp
51
- Yard2steep::Parser::COMMENT_RE: Regexp
52
43
  Yard2steep::Parser::TYPE_WITH_PAREN_RE: Regexp
44
+ Yard2steep::Parser::COMMENT_RE: Regexp
53
45
  Yard2steep::Parser::PARAM_RE: Regexp
54
46
  Yard2steep::Parser::RETURN_RE: Regexp
55
- Yard2steep::Parser::PAREN_RE: Regexp
56
- Yard2steep::Parser::ARGS_RE: Regexp
57
- Yard2steep::Parser::METHOD_RE: Regexp
58
- Yard2steep::Parser::ATTR_RE: Regexp
59
- Yard2steep::Parser::STATES: Hash<any, any>
60
47
  Yard2steep::Parser::ANY_TYPE: String
61
48
  Yard2steep::Parser::ANY_BLOCK_TYPE: String
62
49
  class Yard2steep::CLI
@@ -140,7 +127,7 @@ end
140
127
  Yard2steep::Type::S_RE: Regexp
141
128
  Yard2steep::Type::TOKENS: Regexp
142
129
  module Yard2steep::Util
143
- def self.assert!: { () -> any } -> void
130
+ def self.assert!: () -> any
144
131
  end
145
132
 
146
133
  class Yard2steep::Util::AssertError
@@ -1,48 +1,37 @@
1
1
  class Yard2steep::Parser
2
2
  def initialize: -> any
3
3
  def parse: (String, String, ?debug: bool) -> AST::ClassNode
4
- def reset_method_context!: -> void
5
- def parse_line: (String) -> void
6
- def try_parse_comment: (String) -> bool
7
- def try_parse_param_or_return: (String) -> bool
8
- def try_parse_end: (String) -> bool
9
- def try_parse_postfix_if: (String) -> bool
10
- def try_parse_begin_end: (String) -> bool
11
- def try_parse_class: (String) -> bool
12
- def try_parse_constant: (String) -> bool
13
- def try_parse_singleton_class: (String) -> bool
14
- def try_parse_param: (String) -> bool
15
- def try_parse_return: (String) -> bool
16
- def try_parse_method: (String) -> bool
17
- def try_parse_method_with_no_action: (String) -> bool
18
- def parse_method_params: (String) -> Array<AST::PNode>
19
- def try_parse_attr: (String) -> bool
20
- def push_state!: (String) -> void
21
- def pop_state!: -> void
22
- def stack_is_empty?: -> bool
4
+ def parse_program: (String) -> void
5
+ def parse_stmts: (Array<any>) -> void
6
+ def parse_stmt: (Array<any>) -> void
7
+ def parse_defs: (Array<any>) -> void
8
+ def parse_def: (Array<any>) -> void
9
+ def parse_method_impl: (String, Integer, Array<any>) -> void
10
+ def extract_p_types!: (Integer) -> void
11
+ def parse_comment!: (String) -> void
12
+ def try_param_comment: (String) -> bool
13
+ def try_return_comment: (String) -> bool
14
+ def parse_params: (Array<any>) -> Array<AST::PNode>
15
+ def parse_paren_params: (Array<any>) -> Array<AST::PNode>
16
+ def parse_no_paren_params: (Array<any>) -> Array<AST::PNode>
17
+ def within_context: { (any) -> any } -> void
18
+ def parse_class_or_module: (Array<any>) -> void
19
+ def parse_bodystmt: (Array<any>) -> void
20
+ def parse_assign: (Array<any>) -> void
21
+ def parse_command: (Array<any>) -> void
22
+ def parse_command_args_add_block: (Array<any>) -> Array<String>
23
+ def parse_method_add_arg: (Array<any>) -> void
24
+ def parse_attr_reader: (any) -> void
25
+ def extract_comments: (String) -> Hash<String, String>
26
+ def debug_print!: (String) -> void
23
27
  def type_node: (String) -> AST::PTypeNode
24
- def debug_print!: (String, ?offset: Integer) -> void
28
+ def block_type_node: (String) -> AST::PTypeNode
25
29
  def normalize_type: (String) -> String
26
30
  end
27
31
  Yard2steep::Parser::S_RE: any
28
- Yard2steep::Parser::S_P_RE: any
29
- Yard2steep::Parser::PRE_RE: any
30
- Yard2steep::Parser::POST_RE: any
31
- Yard2steep::Parser::CLASS_RE: any
32
- Yard2steep::Parser::MODULE_RE: any
33
- Yard2steep::Parser::S_CLASS_RE: any
34
- Yard2steep::Parser::END_RE: any
35
- Yard2steep::Parser::CONSTANT_ASSIGN_RE: any
36
- Yard2steep::Parser::POSTFIX_IF_RE: any
37
- Yard2steep::Parser::BEGIN_END_RE: any
38
- Yard2steep::Parser::COMMENT_RE: any
39
32
  Yard2steep::Parser::TYPE_WITH_PAREN_RE: any
33
+ Yard2steep::Parser::COMMENT_RE: any
40
34
  Yard2steep::Parser::PARAM_RE: any
41
35
  Yard2steep::Parser::RETURN_RE: any
42
- Yard2steep::Parser::PAREN_RE: any
43
- Yard2steep::Parser::ARGS_RE: any
44
- Yard2steep::Parser::METHOD_RE: any
45
- Yard2steep::Parser::ATTR_RE: any
46
- Yard2steep::Parser::STATES: any
47
36
  Yard2steep::Parser::ANY_TYPE: any
48
37
  Yard2steep::Parser::ANY_BLOCK_TYPE: any
@@ -1,12 +1,12 @@
1
1
  class Yard2steep::Type::Parser
2
- def self.parse: (any) -> Array<TypeBase>
3
- def initialize: (any) -> any
2
+ def self.parse: (Array<String>) -> Array<TypeBase>
3
+ def initialize: (Array<String>) -> any
4
4
  def parse: -> any
5
5
  def parse_type: -> TypeBase
6
6
  def parse_normal_type: (String) -> NormalType
7
7
  def parse_multiple_types: (String) -> Array<TypeBase>
8
8
  def parse_array: -> ArrayType
9
- def parse_hash: -> any
9
+ def parse_hash: -> HashType
10
10
  def expect!: (String) -> any
11
11
  def get: -> any
12
12
  def peek: -> any
@@ -1,7 +1,7 @@
1
1
  class Yard2steep::Type
2
- def self.translate: (any) -> String
2
+ def self.translate: (String) -> String
3
3
  def initialize: (String) -> any
4
- def translate: -> any
4
+ def translate: -> String
5
5
  def tokens: (String) -> Array<String>
6
6
  end
7
7
  Yard2steep::Type::S_RE: any
data/yard2steep.gemspec CHANGED
@@ -25,5 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.2"
27
27
  spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "pry-doc"
28
29
  spec.add_development_dependency "steep", "0.4.0"
29
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard2steep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nao Minami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2018-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-doc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: steep
71
85
  requirement: !ruby/object:Gem::Requirement