File indexing completed on 2024-04-21 04:35:55
0001 /* This file is part of KDevelop 0002 * 0003 * Copyright (C) 2010-2015 Miquel Sabaté Solà <mikisabate@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 0020 #include <stdio.h> 0021 #include <stdlib.h> 0022 #include "node.h" 0023 0024 0025 extern int rb_debug_file(struct options_t *opts); 0026 0027 /* 0028 * This is a recursive function that steps over the AST to fetch 0029 * all the comments that the parser has stored. All the comments 0030 * are printed to the stdout. 0031 */ 0032 void fetch_comments(struct Node *tree) 0033 { 0034 if (!tree) 0035 return; 0036 if (tree->comment != NULL) 0037 printf("%s", tree->comment); 0038 0039 fetch_comments(tree->l); 0040 fetch_comments(tree->r); 0041 fetch_comments(tree->next); 0042 } 0043 0044 0045 /** 0046 * This is the main function for the parser's debugging utility. It's 0047 * used to perform all the tests. Please, take a look at the README file 0048 * for more info. 0049 */ 0050 int main(int argc, char *argv[]) 0051 { 0052 struct ast_t *ast; 0053 struct options_t opts; 0054 0055 switch (argc) { 0056 case 2: 0057 opts.path = argv[argc - 1]; 0058 opts.version = ruby21; 0059 return rb_debug_file(&opts); 0060 case 3: 0061 opts.path = argv[argc - 2]; 0062 opts.contents = NULL; 0063 opts.version = atoi(argv[argc - 1]); 0064 ast = rb_compile_file(&opts); 0065 if (ast->errors) { 0066 print_errors(ast->errors); 0067 exit(1); 0068 } 0069 fetch_comments(ast->tree); 0070 rb_free(ast); 0071 break; 0072 default: 0073 printf("Usage: ruby-parser file [ruby-version]\n\n"); 0074 printf("KDevelop Ruby parser debugging utility\n"); 0075 } 0076 return 0; 0077 }