src/Pure/Syntax/parser.ML
changeset 367 b734dc03067e
parent 362 6bea8fdc0e70
child 372 40d565e51dea
equal deleted inserted replaced
366:5b6e4340085b 367:b734dc03067e
   471 fun syntax_error toks allowed =
   471 fun syntax_error toks allowed =
   472   error 
   472   error 
   473   ((if toks = [] then
   473   ((if toks = [] then
   474       "error: unexpected end of input\n"
   474       "error: unexpected end of input\n"
   475     else
   475     else
   476       "Syntax error at: " ^ quote (space_implode " " (map str_of_token toks))
   476       "Syntax error at: " ^ quote (space_implode " " (map str_of_token 
       
   477         ((rev o tl o rev) toks)))
   477       ^ "\n")
   478       ^ "\n")
   478    ^ "Expected tokens: " 
   479    ^ "Expected tokens: " 
   479    ^ space_implode ", " (map (quote o str_of_token) allowed));
   480    ^ space_implode ", " (map (quote o str_of_token) allowed));
   480 
   481 
   481 fun produce stateset i indata prev_token =
   482 fun produce stateset i indata prev_token =
   493                     in (get (!rhss_ref)) union (get_starts refs) end;
   494                     in (get (!rhss_ref)) union (get_starts refs) end;
   494 
   495 
   495               val NTs = map (fn (_, _, _, Nonterm (a, _) :: _, _, _) => a)
   496               val NTs = map (fn (_, _, _, Nonterm (a, _) :: _, _, _) => a)
   496                             (filter (fn (_, _, _, Nonterm _ :: _, _, _) => true
   497                             (filter (fn (_, _, _, Nonterm _ :: _, _, _) => true
   497                                      | _ => false) (Array.sub (stateset, i-1)));
   498                                      | _ => false) (Array.sub (stateset, i-1)));
   498               val allowed = get_starts NTs union
   499               val allowed = distinct (get_starts NTs @
   499                             (map (fn (_, _, _, Term a :: _, _, _) => a)
   500                             (map (fn (_, _, _, Term a :: _, _, _) => a)
   500                             (filter (fn (_, _, _, Term _ :: _, _, _) => true
   501                             (filter (fn (_, _, _, Term _ :: _, _, _) => true
   501                                     | _ => false) (Array.sub (stateset, i-1))));
   502                                    | _ => false) (Array.sub (stateset, i-1)))));
   502                                              (*terminals have to be searched for
   503                                              (*terminals have to be searched for
   503                                                because of lambda productions*)
   504                                                because of lambda productions*)
   504           in syntax_error (if prev_token = EndToken then indata
   505           in syntax_error (if prev_token = EndToken then indata
   505                            else prev_token :: indata) allowed
   506                            else prev_token :: indata) allowed
   506           end
   507           end