Created
March 31, 2016 06:40
-
-
Save faithandbrave/9bea3dec6c9a7b9197ed4ca1231cddb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def enumerate_recursive_dir(path) | |
| Dir::foreach(path) {|f| | |
| next if f == '.' or f == '..' | |
| if path =~ /\/$/ | |
| f = path + f | |
| else | |
| f = path + '/' + f | |
| end | |
| if FileTest::directory?(f) | |
| enumerate_recursive_dir(f) {|nested_file| | |
| yield nested_file | |
| } | |
| else | |
| yield f | |
| end | |
| } | |
| end | |
| def find_identifier(md_path, data, id) | |
| line_no = 1 | |
| in_code_block = false | |
| is_found_id_in_code_block = [] | |
| qualify_list = [] | |
| exit_block_line_no = 0 | |
| in_qualify_list = false | |
| data.lines {|line_with_return| | |
| line = line_with_return.chomp | |
| if line.include?('```cpp') | |
| in_code_block = true | |
| is_found_id_in_code_block = false | |
| elsif line == '```' | |
| if in_code_block | |
| in_code_block = false | |
| exit_block_line_no = line_no | |
| qualify_list = [] | |
| end | |
| else | |
| if in_code_block and line.include?(id) | |
| is_found_id_in_code_block = true | |
| end | |
| if line_no == exit_block_line_no + 1 and line[0] == '*' | |
| in_qualify_list = true | |
| elsif (in_qualify_list and line.empty?) or (line_no == exit_block_line_no + 1 and line.empty?) | |
| in_qualify_list = false | |
| if is_found_id_in_code_block and qualify_list.index {|x| x.include?(id)} == nil | |
| puts "#{md_path}:#{line_no} found identifier #{id}" | |
| end | |
| end | |
| if in_qualify_list | |
| qualify_list << line | |
| end | |
| end | |
| line_no = line_no + 1 | |
| } | |
| end | |
| enumerate_recursive_dir('site') {|md_path| | |
| if File.extname(md_path) != ".md" | |
| next | |
| end | |
| data = File.open(md_path).read | |
| find_identifier(md_path, data, 'std::vector') | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment