A peer-to-peer stack for code collaboration
Allow rad files to start with comments/spaces. (#94)
Julian Arni3eb11aa4080a
diff --git a/rad/chain.rad b/rad/chain.radindex 4850f43..ef4f77c 100644--- a/rad/chain.rad+++ b/rad/chain.rad@@ -1,5 +1,3 @@-"not a comment"-;; Chains: Functions for dealing with chains.;; A chain is conceptually:diff --git a/rad/issues.rad b/rad/issues.radindex 31028fd..d7b93ed 100644--- a/rad/issues.rad+++ b/rad/issues.rad@@ -1,5 +1,3 @@-"not a comment"-;; Issues for rad prelude(define create-rad-issue-chain (lambda ()diff --git a/rad/prelude/bool.rad b/rad/prelude/bool.radindex df42938..4933a2c 100644--- a/rad/prelude/bool.rad+++ b/rad/prelude/bool.rad@@ -1,5 +1,3 @@-"not a comment"-;; boolean functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; not@@ -61,4 +59,4 @@(should-be "some" (some '(#f)) #f)(should-be "some" (some '(#f #f #f)) #f)(should-be "some" (some '(#t #t #t #t)) #t)-(should-be "some" (some '(#t #t #f #t)) #t)\ No newline at end of file+(should-be "some" (some '(#t #t #f #t)) #t)diff --git a/rad/prelude/dict.rad b/rad/prelude/dict.radindex 1037765..7483544 100644--- a/rad/prelude/dict.rad+++ b/rad/prelude/dict.rad@@ -1,5 +1,3 @@-"not a comment"-;; dict functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; dict-from-list@@ -38,4 +36,4 @@(should-be "modify-map"(modify-map 'a (lambda (x) (+ x 1)) (dict 'a 5))- (dict 'a 6))\ No newline at end of file+ (dict 'a 6))diff --git a/rad/prelude/doc.rad b/rad/prelude/doc.radindex 464ffaf..3327f67 100644--- a/rad/prelude/doc.rad+++ b/rad/prelude/doc.rad@@ -1,3 +1,5 @@+;; doc-related functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+(define document(lambda (name args description)(define old (read-ref _doc-ref))@@ -21,4 +23,4 @@(document 'doc'(("name" atom))- "Retrieves the documentation for an atom, if there is any.")\ No newline at end of file+ "Retrieves the documentation for an atom, if there is any.")diff --git a/rad/prelude/io.rad b/rad/prelude/io.radindex 9fc5ab1..0b25ece 100644--- a/rad/prelude/io.rad+++ b/rad/prelude/io.rad@@ -1,5 +1,3 @@-"not a comment"-;; read-line(define read-line!(lambda () (read (get-line!))))@@ -18,4 +16,4 @@(document 'send-code!'(("chain-id" string) ("filename" string))- "Send code from a file to a remote chain.")\ No newline at end of file+ "Send code from a file to a remote chain.")diff --git a/rad/prelude/lens.rad b/rad/prelude/lens.radindex 5e1122f..6918d49 100644--- a/rad/prelude/lens.rad+++ b/rad/prelude/lens.rad@@ -1,5 +1,3 @@-"not a comment"-;; Lenses ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; make-lensdiff --git a/rad/prelude/list.rad b/rad/prelude/list.radindex 8444598..e40d18a 100644--- a/rad/prelude/list.rad+++ b/rad/prelude/list.rad@@ -1,5 +1,3 @@-"not a comment"-;; List functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; nil@@ -86,4 +84,4 @@(should-be "filter"(filter (lambda (x) (< x 10)) (list 3 10 11))- (list 3))\ No newline at end of file+ (list 3))diff --git a/rad/prelude/pure-should-be.rad b/rad/prelude/pure-should-be.radindex 8186bb5..eee1454 100644--- a/rad/prelude/pure-should-be.rad+++ b/rad/prelude/pure-should-be.rad@@ -1,5 +1,3 @@-"not a comment"-;; A version of should-be for pure environments.(define should-be@@ -12,4 +10,4 @@'(("test-name" string) ("actual" any) ("expected" any))"Checks that 'actual' equals 'expected'. Used for tests")-(should-be "doc" (string? (doc 'doc)) #t)\ No newline at end of file+(should-be "doc" (string? (doc 'doc)) #t)diff --git a/rad/prelude/recursion.rad b/rad/prelude/recursion.radindex 03c02ac..042250c 100644--- a/rad/prelude/recursion.rad+++ b/rad/prelude/recursion.rad@@ -1,5 +1,3 @@-"not a comment"-;; y-combinators ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(define Y@@ -15,4 +13,4 @@((lambda ()(define fac (Y (lambda (f) (lambda (x) (if (< x 2) 1 (* x (f (- x 1))))))))- (should-be "fac" (fac 10) 3628800)))\ No newline at end of file+ (should-be "fac" (fac 10) 3628800)))diff --git a/rad/prelude/ref.rad b/rad/prelude/ref.radindex 6aab113..a8ffd9f 100644--- a/rad/prelude/ref.rad+++ b/rad/prelude/ref.rad@@ -1,5 +1,3 @@-"not a comment"-;; ref functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; modify-ref@@ -9,4 +7,4 @@(document 'modify-ref'(("ref" ref) ("fn" function))- "Modify 'ref' by applying the provided function.")\ No newline at end of file+ "Modify 'ref' by applying the provided function.")diff --git a/rad/prelude/should-be.rad b/rad/prelude/should-be.radindex 36a851d..e41d4a8 100644--- a/rad/prelude/should-be.rad+++ b/rad/prelude/should-be.rad@@ -1,6 +1,4 @@-"not a comment"--;; should-be+;; should-be - testing functions(define should-be(lambda (name x y)@@ -12,4 +10,4 @@'(("test-name" string) ("actual" any) ("expected" any))"Checks that 'actual' equals 'expected'. Used for tests")-(should-be "doc" (string? (doc 'doc)) #t)\ No newline at end of file+(should-be "doc" (string? (doc 'doc)) #t)diff --git a/rad/state-machine.rad b/rad/state-machine.radindex 6a5b7f9..b5b5e57 100644--- a/rad/state-machine.rad+++ b/rad/state-machine.rad@@ -1,4 +1,3 @@-"not a comment"(define head-shots(dict "onur" "https://res.cloudinary.com/juliendonck/image/upload/v1536080565/avatars/1712926.png"diff --git a/src/Radicle/Internal/Parse.hs b/src/Radicle/Internal/Parse.hsindex a43c045..9aa9205 100644--- a/src/Radicle/Internal/Parse.hs+++ b/src/Radicle/Internal/Parse.hs@@ -130,7 +130,7 @@ interpret-> m (Either (LangError Value) Value)interpret sourceName expr bnds = dolet primopNames = Map.keys (bindingsPrimops bnds)- parsed = runReader (runParserT (valueP <* eof) (toS sourceName) expr) primopNames+ parsed = runReader (runParserT (spaceConsumer *> valueP <* eof) (toS sourceName) expr) primopNamescase parsed ofLeft e -> pure . Left $ ParseError eRight v -> fst <$> runLang bnds (eval v)@@ -147,10 +147,12 @@ interpretMany sourceName src = doprimopNames <- gets $ Map.keys . bindingsPrimopslet parsed = parseValues sourceName src primopNamescase partitionEithers parsed of- ([], vs) -> do es <- mapM eval vs- case lastMay es of- Just e -> pure e- _ -> throwError (OtherError "InterpretMany should be called with at least one expression.")+ ([], vs) -> do+ es <- mapM eval vs+ case lastMay es of+ Just e -> pure e+ _ -> throwError+ $ OtherError "InterpretMany should be called with at least one expression."(e:_, _) -> throwError $ ParseError e-- | Parse a Text as a series of values.@@ -158,14 +160,17 @@ interpretMany sourceName src = do---- Note that parsing continues even if one value fails to parse.parseValues :: Text -> Text -> [Ident] -> [Either (Par.ParseError Char Void) Value]-parseValues sourceName srcCode prims = go $ initial+parseValues sourceName srcCode prims = withoutLeadingSpaceswhereinitial = State- { stateInput = T.strip srcCode+ { stateInput = srcCode, statePos = initialPos (toS sourceName) :| [], stateTokensProcessed = 0, stateTabWidth = defaultTabWidth}+ withoutLeadingSpaces =+ let (s', _) = runReader (runParserT' spaceConsumer initial) prims+ in if T.null (stateInput s') then [] else go s'go s = let (s', v) = runReader (runParserT' valueP s) primsin if T.null (stateInput s') then [v] else v:go s'@@ -184,7 +189,7 @@ parseValues sourceName srcCode prims = go $ initial-- Right (Atom (Ident {fromIdent = "hi"}))parse :: MonadError Text m => Text -> Text -> [Ident] -> m Valueparse file src ids = do- let res = runReader (M.runParserT (valueP <* eof) (toS file) src) ids+ let res = runReader (M.runParserT (spaceConsumer *> valueP <* eof) (toS file) src) idscase res ofLeft err -> throwError . toS $ M.parseErrorPretty' src errRight v -> pure v