关于info格式的company

最近在看flex

首选就是直接 info flex

一大段的英文暂且不说,先说说里面的Indices

我想让company能够直接引用index里面的数据

不知道有没有相应的company-xxxxxx,能直接分析info文件 然后存储到sqlite或直接用.el文件保存数据 最后作为company-xxxxxx的数据源

其实我想得到的glic中的info补全

没有人回答呦 , 那我就 “自问自答” 吧

通过 info flex > flex.txt 得到flex的内容 (我还不敢直接分析flex.info)

可以发现 \nFile: 的下一个非空白行就是一章的标题 下一行一定是*{1…}

先用flex得到标题再说吧


         #include <string.h>

%x chapter
%x preindex
%x index

%%
        int line_num = 1;
        char pre_name [180];

<INITIAL,index>\nFile:[^\n]*    { // printf(" ship 0 on line %d:%s",line_num++,yytext);
                                  line_num++;
                                  BEGIN(chapter);
                                }

<chapter>\n[a-zA-Z0-9][^\n]+        { 
                                      printf("\n catch chapter at line %d:%s",++line_num,yytext+1);
                                      // save the name for check
                                      memcpy(pre_name, yytext+1,strlen(yytext));
                                    }
<chapter>\n"*"+[^\n]*   {  line_num ++;
                           // printf("\n return init at %d",line_num++);
                           BEGIN(0);
                        }
<chapter>\n"="+[^\n]*   {  line_num ++;
                           // printf("\n return init at %d",line_num++);
                           // if name contains index begin(preindex);
                           char * pos = NULL;
                           if((pos=strchr(pre_name,'I'))!=NULL){
                              if(*(pos+1)=='n' && *(pos+2)=='d'
                                   && *(pos+3)=='e' && *(pos+4)=='x'){
                                   BEGIN(preindex);
                               }
                              else{BEGIN(0);}
                           }else{ BEGIN(0); }
                           
                        }

<chapter>\n"-"+[^\n]*   {  line_num ++;
                           // printf("\n return init at %d",line_num++);
                           BEGIN(0);
                        }

<chapter>\n"."+[^\n]*   {  line_num ++;
                           // printf("\n return init at %d",line_num++);
                           BEGIN(0);
                        }

<chapter>\n             {
                          // printf("\n space line at %d:",line_num);
                          line_num++;
                         }


<preindex>\n"* "Menu:[^\n]*        {  ++line_num;
                                      // printf("\ninto index at line %d:%s",line_num,yytext+1);
                                      BEGIN(index);
                                    }
<preindex>\n[^\n]*        {
                           ++ line_num;
                           // printf("\n not match preindex at %d:%s",line_num,yytext);
                          }


<index>\n"*"[^\n]+         { ++line_num;
	                     printf("\n %d:%s:%s",line_num, pre_name,yytext+1);
                           }

<index>\n" "+"(line"[^\n]*      {  line_num ++;
                                     // printf("\n skip (line xxx) at %d",line_num);
                                   }

<index>\n                { line_num++;
                          // printf("\n index space line at %d:",line_num);
                          
                         }


[^\n]    /*skip*/
\n[^\n]*  {
           ++ line_num;
          /*  printf("\n not match line at %d:%s",line_num,yytext); ++line_num;*/
          }

可以执行了

1 个赞

         #include <string.h>
         #include <stdlib.h>

         char * quote(char *  pre){
            int len = strlen(pre);
            char * new_point = malloc(len * 2);
            int j = 0; int i = 0;
            for(i = 0;i<len;i++){
                if(pre[i] != '\''){
                    new_point[j] = pre[i];
                    j++;
                }else{
                    new_point[j] = '\'';
                    new_point[j+1] ='\'';
                    j++;j++;
                }
            }
            new_point[j] = 0;
            new_point[j+1] = 0;

            return new_point ;
         }


%x chapter
%x preindex
%x index
%x index_name
%x index_descript
%x index_descript_space

%%
        int line_num = 1;
        char pre_name [180];

<INITIAL,index>\nFile:[^\n]*    {
                                  line_num++;
                                  BEGIN(chapter);
                                }

<chapter>\n[a-zA-Z0-9][^\n]+        {
                     char * text = quote(yytext+1);
                     printf("\ninsert into flex_topic values('%s');",text);
                     memcpy(pre_name, text,strlen(text));
                     pre_name[strlen(text)] = 0;
                     free(text);
                                   }

<chapter>\n"*"+[^\n]*   {  line_num ++;
                           BEGIN(0);
                        }

<chapter>\n"="+[^\n]*   {  line_num ++;

                           char * pos = NULL;
                           if((pos=strchr(pre_name,'I'))!=NULL){
                              if(*(pos+1)=='n' && *(pos+2)=='d'
                                   && *(pos+3)=='e' && *(pos+4)=='x'){
                                   BEGIN(preindex);
                               }
                              else{BEGIN(0);}
                           }else{ BEGIN(0); }

                        }

<chapter>\n"-"+[^\n]*   {  line_num ++;
                           BEGIN(0);
                        }

<chapter>\n"."+[^\n]*   {  line_num ++;
                           BEGIN(0);
                        }

<chapter>\n             {
                          line_num++;
                         }



<preindex>\n"* "Menu:[^\n]*        {  ++line_num;
                                      BEGIN(index);
                                    }
<preindex>\n[^\n]*        {
                           ++ line_num;
                          }



<index>\n"* "             { ++line_num;
                           BEGIN(index_name);
                           }

<index>\n" "+"(line"[^\n]*      {  line_num ++;
                                   }

<index>\n                { line_num++;
                         }

<index_name>[^:]+      {
      char * text = quote(yytext);
      printf("\ninsert into flex_index values('%s','%s',",
             text,pre_name);
      free(text);
                        }

<index_name>":"[\s\t]*   {
                           // printf(" : ");
                           BEGIN(index_descript_space);
                         }


<index_descript_space>.   {
                     int c;
                     for ( ; ; ){
                         while ( (c = input()) == ' ' || c == '\t' );


                         if ( c != ' ' && c != '\t' ) {
                               unput(c);
                               break;
                         }
                      }

                      BEGIN(index_descript);
                   }


<index_descript>[^.]+  {
                 char * text = quote(yytext);
                 printf("'%s');",text);
                 free(text);
                       }


<index_descript>"."    {
                     int c;
                     for ( ; ; ){
                         while ( (c = input()) != '\n' && c != EOF );
                         if ( c == '\n' ) {
                               unput('\n');
                               break;
                         }

                         if ( c == EOF ) {
                             break;
                         }
                      }

                      BEGIN(index);
                   }


[^\n]    /*skip*/
\n[^\n]*  {
           ++ line_num;
          }

自动的导出 sqlite3 的语句

Makefile 如下

test: a.out flex.txt
        cat flex.txt | ./a.out

flex.txt:
        info flex > flex.txt

a.out: lex.yy.c
        gcc lex.yy.c -lfl

lex.yy.c : flex.l
        flex flex.l

Sqlite3 的表

PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE flex_topic (topic text);
CREATE TABLE flex_index (name text,index_name text, describe text);
insert into flex_topic values('1 Copyright');
insert into flex_topic values('2 Reporting Bugs');
insert into flex_index values('yywrap','Index of Scanner Options','Options Affe\
cting Scanner Behavior');
COMMIT;

hello

查询很简单

下一步 : company-backends