Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,14 @@ jobs:
$releaseDir = "$env:GITHUB_WORKSPACE\dist\release"
if (Test-Path $releaseDir) { Remove-Item $releaseDir -Recurse -Force -ErrorAction SilentlyContinue }
New-Item -ItemType Directory -Path $releaseDir | Out-Null

$exePath = Get-ChildItem -Path "$env:GITHUB_WORKSPACE\dist-newstyle\build" -Recurse -Filter "jbeam-edit.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
if (-not $exePath) {
Write-Error "jbeam-edit.exe not found in dist-newstyle build tree. Make sure build-for-release succeeded."
}
Copy-Item $exePath.FullName $releaseDir

$jbflDest = Join-Path $releaseDir "examples\jbfl"
New-Item -ItemType Directory -Path $jbflDest -Force | Out-Null
Copy-Item -Path "examples\jbfl\*" -Destination $jbflDest -Recurse -Force

Copy-Item README.md $releaseDir -Force
Copy-Item JBFL_DOCS.md $releaseDir -Force
Copy-Item LICENSE $releaseDir -Force
Expand Down Expand Up @@ -125,7 +122,6 @@ jobs:
$zipDir = "$env:GITHUB_WORKSPACE\dist\zip_temp"
if (Test-Path $zipDir) { Remove-Item $zipDir -Recurse -Force -ErrorAction SilentlyContinue }
New-Item -ItemType Directory -Path $zipDir | Out-Null

Copy-Item "$env:GITHUB_WORKSPACE\dist\release\setup.exe" $zipDir -Force
Copy-Item "$env:GITHUB_WORKSPACE\dist\release\README.md" $zipDir -Force
Copy-Item "$env:GITHUB_WORKSPACE\dist\release\JBFL_DOCS.md" $zipDir -Force
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
examples/jbeam/*.jbeam.bak
cabal.project.local
cabal.project.local~
cabal.project.*.local
dist-newstyle/
TAGS
.stack-work/
Expand Down
11 changes: 6 additions & 5 deletions JBFL_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ Typical use cases include:

# Properties Overview

| Setting Name | Description | Applies To |
|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|
| `PadDecimals` | When non-zero, numeric values are padded with trailing zeros after the decimal point. The fractional part is extended to match the specified PadDecimals length. | Numeric values |
| `PadAmount` | Specifies the **total length** (number of characters) the formatted value should occupy. | Any scalar except for comments |
| `NoComplexNewLine` | When true, disables multiline or indented formatting for arrays, outputting values inline. | Any complex data structure |
| Setting Name | Description | Applies To |
|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| `PadDecimals` | When non-zero, numeric values are padded with trailing zeros after the decimal point. The fractional part is extended to match the specified PadDecimals length. | Numeric values |
| `PadAmount` | Specifies the **total length** (number of characters) the formatted value should occupy. | Any scalar except for comments |
| `NoComplexNewLine` | When true, disables multiline or indented formatting for arrays, outputting values inline. | Any complex data structure |
| `Indent` | When set, controls the the amount of indentation. Defaults to 2 spaces. | Any complex data structure with `NoComplexNewLine` set to `false` |

# How Matching Works

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Extract the contents of the downloaded `.zip` archive to a folder of your choice

Inside the extracted folder, right-click on **setup.exe** and choose **Run as administrator**.

## 4. Allow Windows protection if needed
## 4. Allow in Windows Defender if needed
If Windows shows a warning such as:

> *Windows protected your PC*
Expand Down
2 changes: 1 addition & 1 deletion jbeam-edit.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2

-- This file has been generated from package.yaml by hpack version 0.37.0.
-- This file has been generated from package.yaml by hpack version 0.38.0.
--
-- see: https://github.com/sol/hpack

Expand Down
1 change: 0 additions & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ flags:
default: false
manual: true


executables:
jbeam-edit:
main: Main.hs
Expand Down
12 changes: 8 additions & 4 deletions src/Formatting.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Formatting.Rules (
RuleSet (..),
applyPadLogic,
findPropertiesForCursor,
lookupIndentProperty,
newRuleSet,
noComplexNewLine,
)
Expand Down Expand Up @@ -47,18 +48,21 @@ addDelimiters rs index c complexChildren acc ns@(node : rest)
space = bool " " "" $ null rest || complexChildren
newline = bool "" "\n" complexChildren

indent :: Text -> Text
indent s
applyIndentation :: Int -> Text -> Text
applyIndentation n s
| T.all isSpace s = s
| otherwise = " " <> s
| otherwise = T.replicate n " " <> s

doFormatNode :: RuleSet -> NC.NodeCursor -> Vector Node -> Text
doFormatNode rs cursor nodes =
let formatted =
reverse . addDelimiters rs 0 cursor complexChildren [] . V.toList $
nodes
indentationAmount = lookupIndentProperty rs cursor
in if complexChildren
then T.unlines . map indent . concatMap T.lines $ formatted
then
T.unlines . map (applyIndentation indentationAmount) . concatMap T.lines $
formatted
else T.concat formatted
where
complexChildren =
Expand Down
13 changes: 12 additions & 1 deletion src/Formatting/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Formatting.Rules (
applyPadLogic,
comparePatternAndCursor,
noComplexNewLine,
lookupIndentProperty,
newRuleSet,
findPropertiesForCursor,
) where
Expand All @@ -27,6 +28,7 @@ import Core.NodePath (NodeSelector (..))
import Data.Function (on)
import Data.List (find)
import Data.Map (Map)
import Data.Maybe (fromMaybe)
import Data.Ord (Down (..))
import Data.Sequence (Seq (..))
import Data.Text (Text)
Expand Down Expand Up @@ -65,6 +67,7 @@ data PropertyKey a where
NoComplexNewLine :: PropertyKey Bool
PadAmount :: PropertyKey Int
PadDecimals :: PropertyKey Int
Indent :: PropertyKey Int

data SomeKey
= forall a.
Expand Down Expand Up @@ -93,6 +96,7 @@ eqKey :: PropertyKey a -> PropertyKey b -> Maybe (a :~: b)
eqKey PadAmount PadAmount = Just Refl
eqKey NoComplexNewLine NoComplexNewLine = Just Refl
eqKey PadDecimals PadDecimals = Just Refl
eqKey Indent Indent = Just Refl
eqKey _ _ = Nothing

instance Ord SomeKey where
Expand Down Expand Up @@ -131,6 +135,7 @@ propertyName :: PropertyKey a -> Text
propertyName NoComplexNewLine = "NoComplexNewLine"
propertyName PadAmount = "PadAmount"
propertyName PadDecimals = "PadDecimals"
propertyName Indent = "Indent"

keyName :: SomeKey -> Text
keyName (SomeKey key) = propertyName key
Expand All @@ -142,7 +147,7 @@ boolProperties :: [SomeKey]
boolProperties = [SomeKey NoComplexNewLine]

intProperties :: [SomeKey]
intProperties = map SomeKey [PadAmount, PadDecimals]
intProperties = map SomeKey [PadAmount, PadDecimals, Indent]

allProperties :: [SomeKey]
allProperties = boolProperties ++ intProperties
Expand Down Expand Up @@ -190,6 +195,12 @@ noComplexNewLine rs cursor =
maybeProp = lookupProp NoComplexNewLine ps
in (Just True == maybeProp)

lookupIndentProperty :: RuleSet -> NC.NodeCursor -> Int
lookupIndentProperty rs cursor =
let ps = findPropertiesForCursor cursor rs
indentProperty = lookupProp Indent ps
in fromMaybe 2 indentProperty

comparePC :: NodePatternSelector -> NC.NodeBreadcrumb -> Bool
comparePC AnyObjectKey (NC.ObjectIndexAndKey (_, _)) = True
comparePC AnyArrayIndex (NC.ArrayIndex _) = True
Expand Down
1 change: 1 addition & 0 deletions src/Parsing/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ parseValueForKey :: PropertyKey a -> Parser a
parseValueForKey NoComplexNewLine = parseBool <?> "bool"
parseValueForKey PadAmount = L.decimal <?> "integer"
parseValueForKey PadDecimals = L.decimal <?> "integer"
parseValueForKey Indent = L.decimal <?> "integer"

skipComment :: Parser ()
skipComment = void . MP.many $ comment <* skipWhiteSpace
Expand Down
5 changes: 5 additions & 0 deletions test/Parsing/DSLSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ intProperties :: [(String, (SomeKey, SomeProperty))]
intProperties =
[ ("PadDecimals : 3;", (SomeKey PadDecimals, SomeProperty PadDecimals 3))
, ("PadAmount : 8;", (SomeKey PadAmount, SomeProperty PadAmount 8))
, ("Indent : 4;", (SomeKey Indent, SomeProperty Indent 4))
]

boolProperties :: [(String, (SomeKey, SomeProperty))]
Expand Down Expand Up @@ -80,6 +81,10 @@ invalidIntProperties =
( "PadAmount : true;"
, err 12 (utok (toWord8 't') <> expLabels ["integer", "white space"])
)
,
( "Indent : true;"
, err 9 (utok (toWord8 't') <> expLabels ["integer", "white space"])
)
]

invalidBoolProperties :: [(String, ParseError ByteString Void)]
Expand Down
Loading