CookBook/Parsing.thy
changeset 133 3e94ccc0f31e
parent 132 2d9198bcb850
child 149 253ea99c1441
equal deleted inserted replaced
132:2d9198bcb850 133:3e94ccc0f31e
   202   r}. If you want to generate the correct error message for p-followed-by-q,
   202   r}. If you want to generate the correct error message for p-followed-by-q,
   203   then you have to write:
   203   then you have to write:
   204 *}
   204 *}
   205 
   205 
   206 ML{*fun p_followed_by_q p q r =
   206 ML{*fun p_followed_by_q p q r =
   207   let 
   207 let 
   208      val err_msg = (fn _ => p ^ " is not followed by " ^ q)
   208   val err_msg = (fn _ => p ^ " is not followed by " ^ q)
   209   in
   209 in
   210     ($$ p -- (!! err_msg ($$ q))) || ($$ r -- $$ r)
   210   ($$ p -- (!! err_msg ($$ q))) || ($$ r -- $$ r)
   211   end *}
   211 end *}
   212 
   212 
   213 
   213 
   214 text {*
   214 text {*
   215   Running this parser with the @{text [quotes] "h"} and @{text [quotes] "e"}, and 
   215   Running this parser with the @{text [quotes] "h"} and @{text [quotes] "e"}, and 
   216   the input @{text [quotes] "holle"} 
   216   the input @{text [quotes] "holle"} 
   346 
   346 
   347 section {* Parsing Theory Syntax *}
   347 section {* Parsing Theory Syntax *}
   348 
   348 
   349 text {*
   349 text {*
   350   Most of the time, however, Isabelle developers have to deal with parsing
   350   Most of the time, however, Isabelle developers have to deal with parsing
   351   tokens, not strings.  These token parsers will have the type
   351   tokens, not strings.  These token parsers will have the type:
   352 *}
   352 *}
   353   
   353   
   354 ML{*type 'a parser = OuterLex.token list -> 'a * OuterLex.token list*}
   354 ML{*type 'a parser = OuterLex.token list -> 'a * OuterLex.token list*}
   355 
   355 
   356 text {*
   356 text {*
   725 end" "(foo_lemma, [((\"intro\", []), \<dots>), ((\"dest\", [\<dots>]), \<dots>)])"}
   725 end" "(foo_lemma, [((\"intro\", []), \<dots>), ((\"dest\", [\<dots>]), \<dots>)])"}
   726  
   726  
   727   The function @{ML opt_thm_name in SpecParse} is the ``optional'' variant of
   727   The function @{ML opt_thm_name in SpecParse} is the ``optional'' variant of
   728   @{ML thm_name in SpecParse}. Theorem names can contain attributes. The name 
   728   @{ML thm_name in SpecParse}. Theorem names can contain attributes. The name 
   729   has to end with @{text [quotes] ":"}---see the argument of 
   729   has to end with @{text [quotes] ":"}---see the argument of 
   730   @{ML SpecParse.opt_thm_name} in Line 9.
   730   the function @{ML SpecParse.opt_thm_name} in Line 9.
   731 
   731 
   732   \begin{readmore}
   732   \begin{readmore}
   733   Attributes and arguments are implemented in the files @{ML_file "Pure/Isar/attrib.ML"} 
   733   Attributes and arguments are implemented in the files @{ML_file "Pure/Isar/attrib.ML"} 
   734   and @{ML_file "Pure/Isar/args.ML"}.
   734   and @{ML_file "Pure/Isar/args.ML"}.
   735   \end{readmore}
   735   \end{readmore}