Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nitinprakash96 committed Jun 18, 2024
1 parent 2491df0 commit f8fb449
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions editors/emacs/swarm-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"^"
"++"
"$"
":"
)
t)
"Regexp that recognizes operators for swarm language.")
Expand Down
7 changes: 3 additions & 4 deletions editors/vim/swarm.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ syn keyword Keyword def tydef rec end let in require
syn keyword Builtins self parent base if inl inr case fst snd force undefined fail not format chars split charat tochar key
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 match Type "\<[A-Z][a-zA-Z_]*\>"
syn match Operators "[-=!<>|&+*/^$:]"


syn match Comment "//.*$"
syn region MultilineComment start="/\*" end="\*/"
syn match Brackets "[\[\]\(\)\{\}]"
syn match Colon ":"
syn match String "\".*\""
syn match Number "\<[-]\=\d\+\>"

Expand All @@ -20,6 +19,6 @@ hi def link Direction Function
hi def link Comment Comment
hi def link MultilineComment Comment
hi def link Brackets Keyword
hi def link Colon Keyword
hi def link Operators Keyword
hi def link String String
hi def link Number Number
2 changes: 1 addition & 1 deletion editors/vscode/syntaxes/swarm.tmLanguage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ repository:
# ---------------------------------------------
operator:
name: keyword.operator
match: '-|==|!=|<|>|<=|>=|\|\||&&|\+|-|\*|/(?![/|*])|\^|\+\+|\$'
match: '-|==|!=|<|>|<=|>=|\|\||&&|\+|-|\*|/(?![/|*])|\^|\+\+|\$|:'
in:
name: keyword.control.dictionary.let.in
match: \b(in)\b
Expand Down
4 changes: 2 additions & 2 deletions src/swarm-doc/Swarm/Doc/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ generateEditorKeywords = \case
T.putStr $ keywordsCommands Vim
putStrLn "\nsyn keyword Direction "
T.putStr $ keywordsDirections Vim
putStrLn "\nsyn keyword Type "
T.putStr $ operatorNames Vim
putStrLn "\nsyn match Operators "
T.putStr $ "[" <> operatorNames Vim <> "]"

-- ----------------------------------------------------------------------------
-- GENERATE SPECIAL KEY NAMES
Expand Down
20 changes: 16 additions & 4 deletions src/swarm-doc/Swarm/Doc/Keyword.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Swarm.Doc.Keyword (
builtinFunctionList,
) where

import Data.List (nub)
import Data.Text (Text)
import Data.Text qualified as T
import Swarm.Doc.Util
Expand Down Expand Up @@ -45,15 +46,26 @@ keywordsDirections :: EditorType -> Text
keywordsDirections e = editorList e $ map directionSyntax allDirs

-- | A list of the names of all the operators in the language.
-- These are reflective of how the different editors treat operators,
-- keywords, symbols etc differently.
-- In order to get the list of operators supported by Swarm language
-- irrespective of an editor, @map constSyntax operators@ should suffice.
operatorNames :: EditorType -> Text
operatorNames e = editorList e $ case e of
Emacs -> map constSyntax operators
Vim -> map constSyntax operators
VSCode -> map (escape . constSyntax) operators
operatorNames e = case e of
Emacs -> editorList e $ map constSyntax operators <> extraOperators
-- Vim needs a list of unique characters that can be matched over using a regex
Vim -> T.pack . nub . T.unpack . T.concat $ map constSyntax operators <> extraOperators
VSCode -> editorList e $ map (escape . constSyntax) operators <> extraOperators
where
slashNotComment = \case
'/' -> "/(?![/|*])"
c -> T.singleton c

special :: String
special = "*+$[]|^"

-- Extra operators appearing in different places. Eg: Type signatures.
extraOperators :: [Text]
extraOperators = [":"]

escape = T.concatMap (\c -> if c `elem` special then T.snoc "\\" c else slashNotComment c)
2 changes: 1 addition & 1 deletion test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ testEditorFiles =
where
testTextInVSCode name tf = testTextInFile False name (tf VSCode) "editors/vscode/syntaxes/swarm.tmLanguage.yaml"
testTextInEmacs name tf = testTextInFile True name (tf Emacs) "editors/emacs/swarm-mode.el"
testTextInVim name tf = testTextInFile True name (tf Vim) "editors/vim/swarm.vim"
testTextInVim name tf = testTextInFile False name (tf Vim) "editors/vim/swarm.vim"
testTextInFile :: Bool -> String -> Text -> FilePath -> TestTree
testTextInFile whitespace name t fp = testCase name $ do
let removeLW' = T.unlines . map (T.dropWhile isSpace) . T.lines
Expand Down

0 comments on commit f8fb449

Please sign in to comment.