From 1f14e4ab9e7226892745c8afbb7cc46de819b227 Mon Sep 17 00:00:00 2001 From: rhiannon morris Date: Tue, 24 Oct 2023 18:25:56 +0200 Subject: [PATCH] automate more option stuff if the elaborator writes it then it will be kept up to date automatically --- exe/Options.idr | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/exe/Options.idr b/exe/Options.idr index 58b545b..7698730 100644 --- a/exe/Options.idr +++ b/exe/Options.idr @@ -7,6 +7,7 @@ import System.File import System.Term import Derive.Prelude +%default total %language ElabReflection public export @@ -63,20 +64,14 @@ toOutFile "" = Ok {outFile := None} toOutFile "-" = Ok {outFile := Stdout} toOutFile f = Ok {outFile := File f} -private -phaseName : Phase -> String -phaseName Parse = "parse" -phaseName Check = "check" -phaseName Erase = "erase" - private toPhase : String -> OptAction -toPhase str = case toLower str of - "parse" => Ok {until := Just Parse} - "check" => Ok {until := Just Check} - "erase" => Ok {until := Just Erase} - _ => Err "unknown phase name \{show str}\nphases: \{phaseNames}" -where phaseNames = joinBy ", " $ map phaseName allPhases +toPhase str = + let lstr = toLower str in + case find (\p => toLower (show p) == lstr) allPhases of + Just p => Ok {until := Just p} + Nothing => Err "unknown phase name \{show str}\nphases: \{phaseNames}" +where phaseNames = joinBy ", " $ map (toLower . show) allPhases private toWidth : String -> OptAction