Commits

ccorrodi committed ef12b19

update parser and lexer

- resolve multiple shift/reduce conflicts
- allow multiple databases in one file (for an example, see test/vim.mkdb)

  • Participants
  • Parent commits cbd9937
  • Branches develop

Comments (0)

Files changed (2)

File src/lexer.mll

   | '#' [^'\n']* '\n'? as comment {
     COMMENT comment :: rule_token lexbuf
   }
-  | ([^'\n' '=']* as target) ':' ([^'\n' '=']* as prereqs) '\n'? {
-    [TARGETS target; PREREQS prereqs] @ rule_token lexbuf
-  }
-  | '\t' [^'\n']* '\n'? as tabline {
-    COMMAND tabline :: rule_token lexbuf
-  }
-  (* skip empty lines *)
   | '\n' {
     rule_token lexbuf
   }
+  | ([^'\n' '=']* as target) ':' ([^'\n' '=']* as prereqs) '\n'? {
+    [TARGETS target; PREREQS prereqs] @ in_rule_token lexbuf
+  }
   | eof {
     [EOF]
   }
 
-and file_token = parse
+and in_rule_token = parse
   | '#' [^'\n']* '\n'? as comment {
-    COMMENT comment :: file_token lexbuf
-  }
-  | ([^'\n' '=']* as target) ':' ([^'\n' '=']* as prereqs) '\n'? {
-    [TARGETS target; PREREQS prereqs] @ file_token lexbuf
+    RULECOMMENT comment :: in_rule_token lexbuf
   }
   | '\t' [^'\n']* '\n'? as tabline {
-    COMMAND tabline :: file_token lexbuf
+    COMMAND tabline :: in_rule_token lexbuf
+  }
+  | "" {
+    rule_token lexbuf
+  }
+
+and file_token = parse
+  | "# Finished" [^'\n']* '\n'? {
+    FINISHED :: command_token lexbuf
+  }
+  | '#' [^'\n']* '\n'? as comment {
+    COMMENT comment :: file_token lexbuf
   }
-  (* skip empty lines *)
   | '\n' {
     file_token lexbuf
   }
+  | ([^'\n' '=']* as target) ':' ([^'\n' '=']* as prereqs) '\n'? {
+    [TARGETS target; PREREQS prereqs] @ in_file_token lexbuf
+  }
   | eof {
     [EOF]
   }
+
+and in_file_token = parse
+  | '#' [^'\n']* '\n'? as comment {
+    RULECOMMENT comment :: in_file_token lexbuf
+  }
+  | '\t' [^'\n']* '\n'? as tabline {
+    COMMAND tabline :: in_file_token lexbuf
+  }
+  | "" {
+    file_token lexbuf
+  }

File src/parser.mly

   module L = List
 %}
 
-%token VARSEP DIRSEP RULESEP FILESEP
+%token VARSEP DIRSEP RULESEP FILESEP FINISHED
 %token EOF
 
 %token <string> COMMAND
 
 %token <string> TARGETS PREREQS
 %token <string> LINE
-%token <string> COMMENT
+%token <string> COMMENT RULECOMMENT
 
 %start input
 %type <Ast.ast> input
   | COMMENT in_file {
     $2
   }
-  | EOF {
+  | FINISHED input {
+    []
+  }
+  | FINISHED EOF {
     []
   }
 
 rule:
-  | TARGETS PREREQS rulebody {
+  | TARGETS PREREQS rulebodyoption {
     let targets = S.split (S.regexp " ") $1 in
     let prereqs = L.map A.s_to_dep (S.split (S.regexp " ") $2) in
 
       ~in_use:false
   }
 
+rulebodyoption:
+  | rulebody {
+    $1
+  }
+  | {
+    []
+  }
+
 rulebody:
   | COMMAND rulebody {
     (A.s_to_command $1) :: $2
   }
-  | COMMENT rulebody {
+  | COMMAND {
+    [A.s_to_command $1]
+  }
+  | RULECOMMENT rulebody {
     $2
   }
-  | {
+  | RULECOMMENT {
     []
   }