Skip to content

Commit

Permalink
Fixup schema lines parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrisbin committed Oct 24, 2024
1 parent bce857a commit 847e291
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/Restyler/Docs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ settings =
section "DESCRIPTION"
. ronnDefList
( \doc -> case getSchemaLines doc of
OneLine x ->
SingleType x ->
RonnConcat
[ RonnBacktick
$ RonnRaw
Expand All @@ -148,7 +148,7 @@ settings =
, "="
, RonnRaw x
]
MultiLine {} ->
ArrayType x ->
RonnConcat
[ RonnBacktick
$ RonnRaw
Expand All @@ -158,29 +158,49 @@ settings =
$ toList
$ confDocKeys doc
, "="
, RonnAngles "object"
, RonnAngles $ RonnBracket $ RonnRaw x
]
Unknown {} ->
RonnConcat
[ RonnBacktick
$ RonnRaw
$ pack
$ intercalate "."
$ concatMap (toList . fst)
$ toList
$ confDocKeys doc
, "="
, RonnAngles "schema"
]
)
( \doc -> case getSchemaLines doc of
OneLine {} ->
SingleType {} ->
[ RonnLine $ pure $ ronnHelp $ confDocHelp doc
]
ArrayType {} ->
[ RonnLine $ pure $ ronnHelp $ confDocHelp doc
]
MultiLine ls ->
Unknown ls ->
[ RonnLine $ pure $ ronnHelp $ confDocHelp doc
, RonnLine []
]
<> map (indentRonnLine 4) ls
)

data SchemaLines
= OneLine Text
| MultiLine [RonnLine]
= SingleType Text
| ArrayType Text
| Unknown [RonnLine]

getSchemaLines :: ConfDoc -> SchemaLines
getSchemaLines doc =
case texts of
[t] -> OneLine t
ts -> MultiLine $ map (RonnLine . pure . RonnRaw) ts
[t]
| Just x <- T.stripPrefix "- <" t
, Just y <- T.stripSuffix ">" x ->
ArrayType y
| otherwise -> SingleType t
ts -> Unknown $ map (RonnLine . pure . RonnRaw) ts
where
texts = filter (/= "# or null") $ map (mconcat . map chunkText) chunks
chunks =
Expand Down

0 comments on commit 847e291

Please sign in to comment.