diff --git a/docs/11-error-index.md b/docs/11-error-index.md new file mode 100644 index 0000000..ec33b1a --- /dev/null +++ b/docs/11-error-index.md @@ -0,0 +1,13 @@ +# Compiler Error Index + +Each diagnostic emitted from the compiler has a unique error number of the form +`SCMXXX` where `XXX` is the error number. Error numbers are grouped into +'categories' based on the phase in the compiler that emitted the diagnostic. + +Currently the diagnostic categories are: + + * `1-9` - Legacy syntax errors. + * `10-19` - Parser and read. + * `20-29` - Library declaration and use. + * `30-39` - Binder diagnostics. + * `40-49` - Macro definition and expansion. diff --git a/src/Feersum.CompilerServices/Binding/Binder.fs b/src/Feersum.CompilerServices/Binding/Binder.fs index 23ee1ac..2b080dd 100644 --- a/src/Feersum.CompilerServices/Binding/Binder.fs +++ b/src/Feersum.CompilerServices/Binding/Binder.fs @@ -59,6 +59,11 @@ type BoundLiteral = | SyntaxConstant.Boolean b -> BoundLiteral.Boolean b | SyntaxConstant.Str s -> BoundLiteral.Str s +/// Bound Datum Element +/// +/// Represents a form or atom when used as a data element rather than as a +/// program element. Used to hold the contents of quoted expressions, as well +/// as the lements winthin a vector literal. and BoundDatum = | Compound of BoundDatum list | SelfEval of BoundLiteral diff --git a/src/Feersum.CompilerServices/Diagnostics.fs b/src/Feersum.CompilerServices/Diagnostics.fs index 86d16b6..8be423f 100644 --- a/src/Feersum.CompilerServices/Diagnostics.fs +++ b/src/Feersum.CompilerServices/Diagnostics.fs @@ -79,6 +79,9 @@ type Diagnostic = Message = message } /// Format the diagnostic for output. + /// + /// The output format shold conform to the [MSBuild "Canonical Error + /// Format"](https://github.com/dotnet/msbuild/blob/94c28cca4cdb22f2cac279e3fd8d86aa4d061848/src/Shared/CanonicalError.cs#L12-L51) override d.ToString() = let normaliseName (stream: string) = if Path.IsPathRooted(stream) then @@ -91,18 +94,30 @@ type Diagnostic = | Point p -> sprintf "%s(%d,%d): %s: %s" (p.Source |> normaliseName) p.Line p.Col d.MessagePrefix d.FormattedMessage | Span (s, e) -> - sprintf - "%s(%d,%d,%d,%d): %s: %s" - (s.Source |> normaliseName) - s.Line - s.Col - e.Line - e.Col - d.MessagePrefix - d.FormattedMessage + // If both points are on the same line then we can use the a more + // compact format. + if s.Line = e.Line then + sprintf + "%s(%d,%d-%d): %s: %s" + (s.Source |> normaliseName) + s.Line + s.Col + e.Col + d.MessagePrefix + d.FormattedMessage + else + sprintf + "%s(%d,%d,%d,%d): %s: %s" + (s.Source |> normaliseName) + s.Line + s.Col + e.Line + e.Col + d.MessagePrefix + d.FormattedMessage /// Formatted value for the message - member private d.FormattedMessage = sprintf "%s %s" d.Kind.Title d.Message + member private d.FormattedMessage = sprintf "[%s] %s" d.Kind.Title d.Message /// Prefix for the message. Used to summarise the diagnostic kind. member private d.MessagePrefix =