Skip to content

Commit

Permalink
format according to editors
Browse files Browse the repository at this point in the history
  • Loading branch information
nitinprakash96 committed Jun 17, 2024
1 parent 387dc64 commit 2491df0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
6 changes: 1 addition & 5 deletions editors/emacs/swarm-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@
"-"
"*"
"/"
"\\"
":"
"^"
"++"
"$"
"->"
"<-"
"=")
)
t)
"Regexp that recognizes operators for swarm language.")

Expand Down
2 changes: 1 addition & 1 deletion editors/vim/swarm.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ syn keyword Builtins self parent base if inl inr case fst snd force undefined fa
syn keyword Command noop wait selfdestruct move backup volume path push stride turn grab harvest sow ignite place ping give equip unequip make has equipped count drill use build salvage reprogram say listen log view appear create halt time scout whereami waypoint structure floorplan hastag tagmembers detect resonate density sniff chirp watch surveil heading blocked scan upload ishere isempty meet meetall whoami setname random run return try swap atomic instant installkeyhandler teleport as robotnamed robotnumbered knows
syn keyword Direction east north west south down forward left back right
syn keyword Type "\<[A-Z][a-zA-Z_]*\>"
syn keyword Operators - == != < > <= >= || && + - * / \ : ^ ++ $ -> <- =
syn keyword Operators - == != < > <= >= || && + - * / ^ ++ $


syn match Comment "//.*$"
Expand Down
20 changes: 10 additions & 10 deletions example/list.sw
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//
// It is the callers responsibility to make sure a program using this
// "type" is type safe. Notably 2 == [0] != [] == 0 but [] !! x == 0.
//
//
// TODO: once #153 is resolved, add types to definitions
//
// type ListI = Int
Expand All @@ -39,16 +39,16 @@
// chunks each prefixed by 1bit that marks if the byte is last in
// the header (0=YES).

/* EXAMPLE - [short_x,long_y] - concretly e.g. [42, 2^(2^7)]
/* EXAMPLE - [short_x,long_y] - concretly e.g. [42, 2^(2^7)]
0 < len short_x < 2^7
2^7 < len long_y < 2^14
2^7 < len long_y < 2^14
cons short_x $ cons long_y $ nil
vvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvvvvvv vvv
0|len x|x | 1|len y%2^7|0|len y/2^7|y | 0
^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
head tail
head tail
*/

/*******************************************************************/
Expand Down Expand Up @@ -123,7 +123,7 @@ end
/* LIST FUNCTIONS */
/*******************************************************************/

// headTail : ListI -> {Int} * {ListI}
// headTail : ListI -> {Int} * {ListI}
def headTail = \xs.
let sign = mod xs 2 in
let ns = xs / 2 in
Expand All @@ -140,7 +140,7 @@ def head : Int -> Int = \xs.
force $ fst $ headTail xs
end

// tail : ListI -> ListI
// tail : ListI -> ListI
def tail = \xs.
force $ snd $ headTail xs
end
Expand Down Expand Up @@ -226,19 +226,19 @@ def testLIST =
assert (ln1 == 517) "[-1] ~ 517";
assert (head ln1 == -1) "head [-1] == -1";
assert (tail ln1 == nil) "tail [-1] == []";

log "check [42]";
let l42 = cons 42 nil in
assert (l42 == 21528) "[42] ~ 21528";
assert (head l42 == 42) "head [42] == 42";
assert (tail l42 == nil) "tail [42] == []";

log "check [499672]";
let l499672 = cons 499672 nil in
assert (l499672 == 255832140) "[499672] ~ 255832140";
assert (head l499672 == 499672) "head [499672] == 499672";
assert (tail l499672 == nil) "tail [499672] == []";

log "check [1,0]";
let l1_0 = cons 1 l0 in
assert (l1_0 == 4612) "[1,0] ~ 4612";
Expand Down Expand Up @@ -304,7 +304,7 @@ def testLIST_BIG =
let lbiggest = cons bigger lbig in
assert (head lbiggest == bigger) "head [bigger,big] == bigger";
assert (tail lbiggest == lbig) "tail [bigger,big] == [big]";

log "OK - ALL TEST PASSED";
end

Expand Down
9 changes: 6 additions & 3 deletions src/swarm-doc/Swarm/Doc/Keyword.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ keywordsDirections e = editorList e $ map directionSyntax allDirs

-- | A list of the names of all the operators in the language.
operatorNames :: EditorType -> Text
operatorNames e = editorList e $ map (escape . constSyntax) operators
operatorNames e = editorList e $ case e of
Emacs -> map constSyntax operators
Vim -> map constSyntax operators
VSCode -> map (escape . constSyntax) operators
where
special :: String
special = "*+$[]|^"
slashNotComment = \case
'/' -> "/(?![/|*])"
c -> T.singleton c
special :: String
special = "*+$[]|^"
escape = T.concatMap (\c -> if c `elem` special then T.snoc "\\" c else slashNotComment c)
6 changes: 4 additions & 2 deletions test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,15 @@ testEditorFiles =
]
, testGroup
"Emacs"
[ testTextInEmacs "builtin" Keyword.builtinFunctionList
[ testTextInEmacs "operators" Keyword.operatorNames
, testTextInEmacs "builtin" Keyword.builtinFunctionList
, testTextInEmacs "commands" Keyword.keywordsCommands
, testTextInEmacs "directions" Keyword.keywordsDirections
]
, testGroup
"Vim"
[ testTextInVim "builtin" Keyword.builtinFunctionList
[ testTextInVim "operators" Keyword.operatorNames
, testTextInVim "builtin" Keyword.builtinFunctionList
, testTextInVim "commands" Keyword.keywordsCommands
, testTextInVim "directions" Keyword.keywordsDirections
]
Expand Down

0 comments on commit 2491df0

Please sign in to comment.