44 Some specification package might thus intercept syntax processing at |
46 Some specification package might thus intercept syntax processing at |
45 a well-defined stage after @{text "parse"}, to a augment the |
47 a well-defined stage after @{text "parse"}, to a augment the |
46 resulting pre-term before full type-reconstruction is performed by |
48 resulting pre-term before full type-reconstruction is performed by |
47 @{text "check"}, for example. Note that the formal status of bound |
49 @{text "check"}, for example. Note that the formal status of bound |
48 variables, versus free variables, versus constants must not be |
50 variables, versus free variables, versus constants must not be |
49 changed here! *} |
51 changed between these phases! *} |
50 |
52 |
51 |
53 |
52 section {* Reading and pretty printing \label{sec:read-print} *} |
54 section {* Reading and pretty printing \label{sec:read-print} *} |
53 |
55 |
54 text {* Read and print operations are roughly dual to each other, such |
56 text {* Read and print operations are roughly dual to each other, such |
55 that for the user @{text "s' = pretty (read s)"} looks similar to |
57 that for the user @{text "s' = pretty (read s)"} looks similar to |
56 the original source text @{text "s"}, but the details depend on many |
58 the original source text @{text "s"}, but the details depend on many |
57 side-conditions. There are also explicit options to control |
59 side-conditions. There are also explicit options to control |
58 suppressing of type information in the output. The default |
60 suppressing of type information in the output. The default |
59 configuration routinely looses information, so @{text "t' = read |
61 configuration routinely looses information, so @{text "t' = read |
60 (pretty t)"} might fail, produce a differently typed term, or a |
62 (pretty t)"} might fail, or produce a differently typed term, or a |
61 completely different term in the face of syntactic overloading! *} |
63 completely different term in the face of syntactic overloading! *} |
62 |
64 |
63 text %mlref {* |
65 text %mlref {* |
64 \begin{mldecls} |
66 \begin{mldecls} |
65 @{index_ML Syntax.read_typ: "Proof.context -> string -> typ"} \\ |
67 @{index_ML Syntax.read_typ: "Proof.context -> string -> typ"} \\ |
77 |
79 |
78 text {* Parsing and unparsing converts between actual source text and |
80 text {* Parsing and unparsing converts between actual source text and |
79 a certain \emph{pre-term} format, where all bindings and scopes are |
81 a certain \emph{pre-term} format, where all bindings and scopes are |
80 resolved faithfully. Thus the names of free variables or constants |
82 resolved faithfully. Thus the names of free variables or constants |
81 are already determined in the sense of the logical context, but type |
83 are already determined in the sense of the logical context, but type |
82 information might is still missing. Pre-terms support an explicit |
84 information might be still missing. Pre-terms support an explicit |
83 language of \emph{type constraints} that may be augmented by user |
85 language of \emph{type constraints} that may be augmented by user |
84 code to guide the later \emph{check} phase, for example. |
86 code to guide the later \emph{check} phase. |
85 |
87 |
86 Actual parsing is based on traditional lexical analysis and Earley |
88 Actual parsing is based on traditional lexical analysis and Earley |
87 parsing for arbitrary context-free grammars. The user can specify |
89 parsing for arbitrary context-free grammars. The user can specify |
88 this via mixfix annotations. Moreover, there are \emph{syntax |
90 the grammar via mixfix annotations. Moreover, there are \emph{syntax |
89 translations} that can be augmented by the user, either |
91 translations} that can be augmented by the user, either |
90 declaratively via @{command translations} or programmatically via |
92 declaratively via @{command translations} or programmatically via |
91 @{command parse_translation}, @{command print_translation} etc. The |
93 @{command parse_translation}, @{command print_translation} etc. The |
92 final scope resolution is performed by the system, according to name |
94 final scope resolution is performed by the system, according to name |
93 spaces for types, constants etc.\ determined by the context. |
95 spaces for types, term variables and constants etc.\ determined by |
|
96 the context. |
94 *} |
97 *} |
95 |
98 |
96 text %mlref {* |
99 text %mlref {* |
97 \begin{mldecls} |
100 \begin{mldecls} |
98 @{index_ML Syntax.parse_typ: "Proof.context -> string -> typ"} \\ |
101 @{index_ML Syntax.parse_typ: "Proof.context -> string -> typ"} \\ |
124 "let"} bindings. These are expanded during the @{text "check"} |
127 "let"} bindings. These are expanded during the @{text "check"} |
125 phase, and contracted during the @{text "uncheck"} phase, without |
128 phase, and contracted during the @{text "uncheck"} phase, without |
126 affecting the type-assignment of the given terms. |
129 affecting the type-assignment of the given terms. |
127 |
130 |
128 \medskip The precise meaning of type checking depends on the context |
131 \medskip The precise meaning of type checking depends on the context |
129 --- additional check/uncheck plugins might be defined in user space! |
132 --- additional check/uncheck plugins might be defined in user space. |
130 |
133 |
131 For example, the @{command class} command defines a context where |
134 For example, the @{command class} command defines a context where |
132 @{text "check"} treats certain type instances of overloaded |
135 @{text "check"} treats certain type instances of overloaded |
133 constants according to the ``dictionary construction'' of its |
136 constants according to the ``dictionary construction'' of its |
134 logical foundation. This involves ``type improvement'' |
137 logical foundation. This involves ``type improvement'' |