Skip to content

Instantly share code, notes, and snippets.

@metaleap
Created June 20, 2024 06:44
Show Gist options
  • Save metaleap/c74763706c78d82332825cce45bd6265 to your computer and use it in GitHub Desktop.
Save metaleap/c74763706c78d82332825cce45bd6265 to your computer and use it in GitHub Desktop.
(import (only-in :gerbil/gambit pretty-print)
:std/sugar
:std/text/json)
(defsyntax deflsp
(syntax-rules ()
((deflsp $typename ($fields ...) $ctor-name)
(begin
(defclass ($type-name JSON) ($fields ...) constructor: $ctor-name)
(defmethod {$ctor-name $type-name}
(lambda ((this :- $type-name) json-obj)
(set! this.uri (hash-get json-obj "uri"))))
))
))
; (deflsp Position
; (line character))
(deflsp TextDocumentIdentifier
(uri) :init!)
; (deflsp TextDocumentPositionParams
; ((textDocument : TextDocumentIdentifier) (position : Position)))
; (deflsp (HoverParams TextDocumentPositionParams) ())
(def (main . args)
; (def pos (make-Position (string->json-object "{\"line\":11,\"character\":22}")))
(def doc (make-TextDocumentIdentifier (string->json-object "{\"uri\":\"file:///foo.txt\"}")))
; (def params (make-TextDocumentPositionParams (string->json-object "{\"position\":{\"character\":44,\"line\":77},\"textDocument\":{\"uri\":\"file:///baz.txt\"}}")))
; (displayln (json-object->string (trivial-class->json-object pos)))
(displayln (json-object->string (trivial-class->json-object doc)))
; (displayln (json-object->string (trivial-class->json-object params)))
)
(displayln "\n")
(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment