From c86bc7a8263fa79675293aff695185796b949ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Wed, 13 Nov 2024 01:07:02 +0100 Subject: [PATCH] remove demos --- .../parser/ParserTreeSitterDemo.scala | 37 ----- .../smithyql/parser/demo.worksheet.sc | 148 ------------------ 2 files changed, 185 deletions(-) delete mode 100644 modules/treesitter/src/main/scala/playground/smithyql/parser/ParserTreeSitterDemo.scala delete mode 100644 modules/treesitter/src/main/scala/playground/smithyql/parser/demo.worksheet.sc diff --git a/modules/treesitter/src/main/scala/playground/smithyql/parser/ParserTreeSitterDemo.scala b/modules/treesitter/src/main/scala/playground/smithyql/parser/ParserTreeSitterDemo.scala deleted file mode 100644 index b2704979..00000000 --- a/modules/treesitter/src/main/scala/playground/smithyql/parser/ParserTreeSitterDemo.scala +++ /dev/null @@ -1,37 +0,0 @@ -package playground.smithyql - -import org.polyvariant.treesitter4s.TreeSitterAPI -import playground.generated.nodes.* - -object ParserTreeSitterDemo extends App { - - val tree = TreeSitterAPI.make("smithyql").parse { - """ - use service foo.bar.bax.qux#Baz - - Bax { x = 42 } - """.stripMargin - } - - val bind = SourceFile - .unsafeApply(tree.rootNode.get) - .statements - .headOption - .getOrElse(sys.error("no statements section in source file")) - .run_query - .getOrElse(sys.error("no run_query in statements section")) - .input - .getOrElse(sys.error("no input in operation call")) - .bindings - .find(_.key.exists(_.source == "x")) - .getOrElse(sys.error("no binding with key 'x'")) - - println( - bind - .value - .getOrElse(sys.error("binding doesn't have a value")) - .asNumber - .getOrElse(sys.error("binding wasn't a number literal")) - .source - ) -} diff --git a/modules/treesitter/src/main/scala/playground/smithyql/parser/demo.worksheet.sc b/modules/treesitter/src/main/scala/playground/smithyql/parser/demo.worksheet.sc deleted file mode 100644 index 441bc313..00000000 --- a/modules/treesitter/src/main/scala/playground/smithyql/parser/demo.worksheet.sc +++ /dev/null @@ -1,148 +0,0 @@ -import org.polyvariant.treesitter4s.Node -import org.polyvariant.treesitter4s.TreeSitterAPI -import playground.generated.nodes.* - -val s = - """ -use service foo.bar.baz.bax#Baz - -Bax { a = , x = 44 y = 50, b = ,,42, xyz = { a = }} - """.stripMargin - -val p = TreeSitterAPI.make("smithyql") - -// hmm -// https://github.com/Jakobeha/type-sitter/blob/5d2cff2f2641d2af9a9a7ebdcd49b0311f19ad66/type-sitter-lib/src/node/incorrect_kind.rs#L10 -/// Underlying cause of why the node is the wrong kind -// pub enum IncorrectKindCause { -// /// Node is an error node -// Error, -// /// Node is a missing node -// Missing, -// /// Node is valid but simply of a different kind (bad node-types.json? Different language? -// /// Broken user invariant?) -// OtherKind(&'static str), -// } -case class ErrorNode(node: Node) extends Node { - export node.* -} - -val base = p.parse("Foo { true }").rootNode.get -SourceFile - .unsafeApply(base) - .statements - .get - .operation_call - .get - .input - .get - .children - .find(_.isError) - -// SourceFile(p.parse("use service foo.bar.baz.bax#Baz").rootNode.get).statements -// SourceFile(p.parse("use service foo.bar.baz.bax#Baz").rootNode.get).isError -// SourceFile(p.parse("use service foo.bar.baz.bax#Baz").rootNode.get).hasError -// SourceFile(p.parse("use service foo.bar.baz.bax#Baz").rootNode.get).children.map(_.tpe) - -val tree = p.parse(s) - -tree.rootNode.get.text - -SourceFile.unsafeApply(tree.rootNode.get).use_clause.get.identifier.head.source - -SourceFile.unsafeApply(tree.rootNode.get).use_clause.get.identifier.get.selection.get.source - -SourceFile - .unsafeApply(tree.rootNode.get) - .use_clause - .get - .identifier - .tail - -SourceFile - .unsafeApply(tree.rootNode.get) - .statements - .get - .operation_call - .get - .input - .get - .children - .filter(_.tpe == "ERROR") - .head - .source - -tree - .rootNode - .get - .fold[List[Node]]((n, ch) => n :: ch.toList.flatten) - .filter(_.tpe == "ERROR") - .map(_.source) - -tree - .rootNode - .get - .fold[List[Node]]((n, ch) => n :: ch.toList.flatten) - .filter(_.isMissing) - -tree - .rootNode - .get - .fold[List[Node]]((n, ch) => n :: ch.toList.flatten) - .filter(_.isExtra) - .size - -tree - .rootNode - .get - .fold[List[Node]]((n, ch) => n :: ch.toList.flatten) - .filter(_.isError) - .map(_.text) - .mkString("\n") - -tree - .rootNode - .get - .fold[List[Node]]((n, ch) => n :: ch.toList.flatten) - .size - -tree - .rootNode - .get - .fold[List[Node]]((n, ch) => n :: ch.toList.flatten) - .filter(_.hasError) - .size - -tree - .rootNode - .get - .fold[List[Node]]((n, ch) => n :: ch.toList.flatten) - // .filter(_.tpe == "MISSING") - // .map(_.source) - .map(_.tpe) - .toSet - -val bind = - SourceFile - .unsafeApply(tree.rootNode.get) - .statements - .get - .operation_call - .get - .input - .get - .bindings - .get - .binding - -// .find(_.key.source == "x") -// .get - -bind.size -bind.head.fields -bind.map(_.key.get.source) - -bind.last.value.get.asStruct.get.bindings.get.binding.head.value.get.asBoolean.get.tpe -// bind.key.source - -// bind.value.asNumber.get.source