diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-10-31 15:05:17 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-10-31 15:05:17 -0700 |
| commit | 7a35e38d8778670fe0662f203e82638355db3bba (patch) | |
| tree | cc9f813d1350f23d2b81a81b18f4f127668bfec9 /nomnom/pretty_errors.nom | |
| parent | f43d8c58f755a7f208d84b43071490ab356c5ac8 (diff) | |
Renamed (action %) -> (%'s meaning)
Diffstat (limited to 'nomnom/pretty_errors.nom')
| -rw-r--r-- | nomnom/pretty_errors.nom | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/nomnom/pretty_errors.nom b/nomnom/pretty_errors.nom index f32b849..db4be5a 100644 --- a/nomnom/pretty_errors.nom +++ b/nomnom/pretty_errors.nom @@ -1,12 +1,11 @@ +#!/usr/bin/env nomsu -V4.8.10 # This file has code for converting errors to user-friendly format, with colors, line numbers, code excerpts, and so on. - -local action [visible size of %text]: +(visible size of %text) means: return (size of (%text::with "\027%[[0-9;]*m" -> "")) -local action [%text boxed]: - %max_line = (..) - max of ((visible size of %line) for %line in (%text::lines)) +(%text boxed) means: + %max_line = (max of ((visible size of %line) for %line in (%text::lines))) %ret = (..) "\n\%text"::with "\n([^\n]*)" -> (..) [%] -> (..) @@ -14,47 +13,45 @@ local action [%text boxed]: return %ret.[2,-1] %CONTEXT = 2 -action [pretty %title error at %tree %err hint %hint]: +externally (pretty %title error at %tree %err hint %hint) means: %source_code = (%tree::get source code) %start = %tree.source.start %stop = %tree.source.stop %filename = (%tree.source.filename or "???") - %err_line = (%source_code::line at %start) %err_linenum = (%source_code::line number at %start) %err_linepos = (%source_code::line position at %start) + # TODO: better handle multi-line errors - %err_size = (..) - min of [..] - %stop - %start - (size of %err_line) - %err_linepos + 1 + %err_size = (min of [%stop - %start, (size of %err_line) - %err_linepos + 1]) %nl_indicator = (" " if (%err_linepos > (size of %err_line)) else "") %fmt_str = " %\(size of "\(%err_linenum + %CONTEXT)")d|" - local action [num %i] (%fmt_str::formatted with %i) + (num %i) means (%fmt_str::formatted with %i) %linenum_size = (size of (num 0)) - %pointer = "\(" "::* (%err_linepos + %linenum_size - 1))" if (%err_size >= 2): %pointer += "╚\("═"::* (%err_size - 2))╝" - ..else: - %pointer += "⬆" - - %err_msg = "\027[33;41;1m\(%title or "Error") at \(%filename):\(%err_linenum)\027[0m" + ..else: %pointer += "⬆" + + %err_msg = "\ + ..\027[33;41;1m\(%title or "Error") at \%filename:\%err_linenum\027[0m" for %i in (%err_linenum - %CONTEXT) to (%err_linenum - 1): %line = (%source_code::line %i) if %line: %err_msg += "\n\027[2m\(num %i)\027[0m\(%line)\027[0m" + if %err_line: %before = %err_line.[1, %err_linepos - 1] %during = %err_line.[%err_linepos, %err_linepos + %err_size - 1] %after = %err_line.[%err_linepos + %err_size, -1] - %err_line = "\027[0m\(%before)\027[41;30m\(%during)\(%nl_indicator)\027[0m\(%after)" + %err_line = "\027[0m\(%before)\027[41;30m\%during\(%nl_indicator)\027[0m\%after" %err_msg += "\n\027[2m\(num %err_linenum)\(%err_line)\027[0m" + %err_linenum_end = (%source_code::line number at %stop) %err_linepos_end = (%source_code::line position at %stop) %err_linenum_end or= %err_linenum if (%err_linenum_end == %err_linenum): - %err_msg += "\n\(%pointer)" + %err_msg += "\n\%pointer" ..else: for %i in (%err_linenum + 1) to %err_linenum_end: %line = (%source_code::line %i) @@ -62,24 +59,27 @@ action [pretty %title error at %tree %err hint %hint]: if (%i == %err_linenum_end): %during = %line.[1, %err_linepos_end - 1] %after = %line.[%err_linepos_end, -1] - %err_msg += "\n\027[2m\(num %i)\027[0;41;30m\(%during)\027[0m\(%after)" + %err_msg += "\n\027[2m\(num %i)\027[0;41;30m\(%during)\027[0m\%after" ..else: %err_msg += "\n\027[2m\(num %i)\027[0;41;30m\(%line)\027[0m" - + %box_width = 70 %err_text = "\ - ..\027[47;31;1m\((" \(%err)"::wrapped to %box_width)::with "\n" -> "\n\027[47;31;1m ")" + ..\027[47;31;1m\((" \%err"::wrapped to %box_width)::with "\n" -> "\n\027[47;31;1m ")" if %hint: %err_text += "\n\027[47;30m\((" Suggestion: \(%hint)"::wrapped to %box_width)::with "\n" -> "\n\027[47;30m ")" %err_msg += "\n\027[33;1m \((%err_text boxed)::with "\n" -> "\n ")" - + + %err_msg += "\n\027[33;1m \((%err_text boxed)::with "\n" -> "\n ")" for %i in (%err_linenum_end + 1) to (%err_linenum_end + %CONTEXT): %line = (%source_code::line %i) if %line: %err_msg += "\n\027[2m\(num %i)\027[0m\(%line)\027[0m" + return %err_msg -action [pretty %title error at %tree %err] (pretty %title error at %tree %err (nil)) +externally (pretty %title error at %tree %err) means (..) + pretty %title error at %tree %err (nil) -action [%err_tree as a pretty error] (..) +externally (%err_tree as a pretty error) means (..) pretty %err_tree.title error at %err_tree %err_tree.error hint %err_tree.hint |
