Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
revised mapping ops
Browse files Browse the repository at this point in the history
  • Loading branch information
cfr committed Jun 8, 2015
1 parent 51f6424 commit a99b8ed
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 489 deletions.
3 changes: 2 additions & 1 deletion spec.burnbar
Expand Up @@ -19,7 +19,8 @@
- # Type grammar
- type → array-type | dictionary-type | type-identifier | optional-type | primitive-type
- returnType → type-identifier | Void
- primitive-type → String | Int | Float | Bool | NSNumber
- primitive-type → String | NSNumber | overloaded
- overloaded → Int | Float | Bool | NSDate
- array-type → [ type ]
- dictionary-type → { String : type }
- optional-type → type ?
Expand Down
8 changes: 4 additions & 4 deletions src/BurningBar.hs
Expand Up @@ -26,15 +26,15 @@ main = do
let write = ( copy) writeFile (root </>)
spec readFile spec
let errors = check spec in when (errors []) (error errors)
let (ent, int) = translator (swift shield transport interface) (parse spec)
let (ent, int) = translator (swift overload transport interface) (parse spec)
(createDir root write entFn ent write intFn int)
`catch` handleEx
#ifdef DEBUG
print (spec, ent, int)
#endif

data Options = Options { transport Typename, interface Typename , spec String
, root FilePath, entFn FilePath, intFn FilePath, shield Bool}
, root FilePath, entFn FilePath, intFn FilePath, overload Bool}

defaults = Options "Transport" "Interface" "spec.burnbar" "./" entFn intFn False
where { intFn = "Interface.swift"; entFn = "Entities.swift" }
Expand All @@ -47,8 +47,8 @@ options = let opt (k, f, a, h) = Option k f a h in map opt
, ("i", ["interface-file"], ReqArg (\a o o {intFn = a}) "Interface.swift", "interface out filename")
, ("r", ["entities-file"], ReqArg (\a o o {entFn = a}) "Entities.swift", "entities out filename")
, ("s", ["spec-file"], ReqArg (\a o o {spec = a}) "spec.burnbar", "input spec file")
, ("b", ["dynamicity-shield"], NoArg (\o o {shield = True}), "accept weak-typed json")
, ("f", ["fucking-string"], NoArg (\o o {shield = True}), "accept weak-typed json")
, ("b", ["overload"], NoArg (\o o {overload = True}), "accept weak-typed json")
, ("f", ["fucking-string"], NoArg (\o o {overload = True}), "accept weak-typed json")
, ("p", ["path"], ReqArg (\a o o {root = a}) ".", "output path prefix") ]

use _ = error $ usageInfo ("Usage: burningbar [-vtnirsbfpcd]\n" bbURL version) options
Expand Down
6 changes: 4 additions & 2 deletions src/Checker.hs
Expand Up @@ -37,14 +37,17 @@ validHeadOrProto (Proto (n, rrt, nm)) = validName nm
validName nm = if all isSwiftId nm then Nothing
else Just ("invalid name " nm)
isSwiftId c = isAlphaNum c (c '_')
validSuper sup = if all isAlphaNum names then Nothing
validSuper sup = if all isSwiftId names then Nothing
else Just ("invalid proto " fromJust sup)
where names = separateBy ',' (fromMaybe [] sup) ≫= trim

validType (Dictionary k _) = if k TypeName "String"
then Just ("not String key found (" show k ")")
else Nothing
validType (TypeName t) = validName t
validType _ = Nothing


check String String
check = (≫= valid) enumerateLines
where valid = second (validSpecLine parseLine) printError
Expand All @@ -57,7 +60,6 @@ printError (n, Just error) = printf "spec line %03d: %s.\n" n error
printError _ = ""

-- TODO:
-- only optional newtypes in recs
-- no optionals in met args
-- validate paragraphs or ignore?
-- check matching parens
Expand Down
385 changes: 167 additions & 218 deletions src/Static.hs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Swift.hs
Expand Up @@ -9,9 +9,9 @@ import Language hiding (generate)
import Util

swift Bool Typename Typename Language
swift shield transport interface = Language generate wrapEnts (intDefs transport interface)
swift overload transport interface = Language generate wrapEnts (intDefs transport interface)
where wrapEnts e = "\nimport Foundation\n" e entDefs
if shield then dynamicityShield else []
if overload then overloaded else []

generate Declaration String
generate (Record name vars super) = struct name vars super
Expand Down

0 comments on commit a99b8ed

Please sign in to comment.