diff --git a/corral.json b/corral.json index 0abae3c..e57c146 100644 --- a/corral.json +++ b/corral.json @@ -5,7 +5,7 @@ "deps": [ { "locator": "github.com/chalcolith/kiuatan.git", - "version": "1.6.0" + "version": "1.6.1" }, { "locator": "github.com/ponylang/appdirs.git", diff --git a/eohippus/analyzer/eohippus_analyzer.pony b/eohippus/analyzer/eohippus_analyzer.pony index a46d96a..65c635c 100644 --- a/eohippus/analyzer/eohippus_analyzer.pony +++ b/eohippus/analyzer/eohippus_analyzer.pony @@ -1101,7 +1101,7 @@ actor EohippusAnalyzer is Analyzer | let file: File => let json_str = recover val file.read_string(file.size()) end match json.Parse(json_str) - | let obj: json.Object => + | let obj: json.Object val => match ast.ParseNode(src_file.canonical_path.path, obj) | let node: ast.Node => _log(Fine) and _log.log( @@ -1114,7 +1114,7 @@ actor EohippusAnalyzer is Analyzer src_file.task_id.string() + ": error loading " + syntax_path.path + ": " + err) end - | let item: json.Item => + | let item: json.Item val => _log(Error) and _log.log( src_file.task_id.string() + ": error loading " + syntax_path.path + ": a syntax tree must be an object") @@ -1184,7 +1184,7 @@ actor EohippusAnalyzer is Analyzer match OpenFile(scope_path) | let file: File => let json_str = recover val file.read_string(file.size()) end - match recover val json.Parse(json_str) end + match json.Parse(json_str) | let obj: json.Object val => match recover val ParseScopeJson(_context.file_auth, obj, None) end | let scope: Scope val => diff --git a/eohippus/analyzer/scope.pony b/eohippus/analyzer/scope.pony index 1a6fc24..33e085e 100644 --- a/eohippus/analyzer/scope.pony +++ b/eohippus/analyzer/scope.pony @@ -1,5 +1,6 @@ use "collections" use "files" +use "itertools" use ast = "../ast" use json = "../json" @@ -102,7 +103,6 @@ class val Scope fun get_json(): json.Object => let props = [ as (String, json.Item): ("index", I128.from[USize](index)) ] - let kind_string = match kind | PackageScope => @@ -124,23 +124,26 @@ class val Scope props.push(("canonical_path", canonical_path.path)) end props.push( - ( "range", - json.Sequence( + ( "range" + , json.Sequence( [ as I128: I128.from[USize](range._1) I128.from[USize](range._2) I128.from[USize](range._3) I128.from[USize](range._4) - ])) ) + ]) )) if imports.size() > 0 then let import_items = Array[json.Item] for (node_index, identifier, path) in imports.values() do - import_items.push(json.Object( - [ as (String, json.Item): - ("node", I128.from[USize](node_index)) - ("identifier", identifier) - ("path", path) - ])) + import_items.push( + recover val + json.Object( + [ as (String, json.Item): + ("node", I128.from[USize](node_index)) + ("identifier", identifier) + ("path", path) + ]) + end) end props.push(("imports", json.Sequence(import_items))) end @@ -148,33 +151,34 @@ class val Scope let def_items = Array[json.Item] for def_array in definitions.values() do for (node_index, identifier, doc_string) in def_array.values() do - def_items.push(json.Object( - [ as (String, json.Item): - ("node", I128.from[USize](node_index)) - ("identifier", identifier) - ("doc_string", doc_string) ])) + def_items.push( + json.Object( + [ as (String, json.Item): + ("node", I128.from[USize](node_index)) + ("identifier", identifier) + ("doc_string", doc_string) ])) end end props.push(("definitions", json.Sequence(def_items))) end if children.size() > 0 then - let children_items = Array[json.Item] - for child in children.values() do - children_items.push(child.get_json()) - end - props.push(("children", json.Sequence(children_items))) + let child_items = + Iter[Scope box](children.values()) + .map[json.Item]({(child) => child.get_json() }) + .collect(Array[json.Item](children.size())) + props.push(("children", json.Sequence(child_items))) end - json.Object(consume props) + json.Object(props) primitive ParseScopeJson fun apply( auth: FileAuth, - scope_item: json.Item, + scope_item: json.Item val, parent: (Scope ref | None)) : (Scope ref | String) => match scope_item - | let scope_obj: json.Object => + | let scope_obj: json.Object val => let kind = match try scope_obj("kind")? end | "PackageScope" => @@ -194,14 +198,14 @@ primitive ParseScopeJson end let name = match try scope_obj("name")? end - | let str: String box => + | let str: String val => str else return "scope.name must be a string" end let canonical_path = match try scope_obj("canonical_path")? end - | let str: String box => + | let str: String val => FilePath(auth, str.clone()) else match parent @@ -213,7 +217,7 @@ primitive ParseScopeJson end let range = match try scope_obj("range")? end - | let seq: json.Sequence box => + | let seq: json.Sequence val => match try (seq(0)?, seq(1)?, seq(2)?, seq(3)?) end | (let l: I128, let c: I128, let nl: I128, let nc: I128) => ( USize.from[I128](l), @@ -239,10 +243,10 @@ primitive ParseScopeJson kind, name.clone(), canonical_path, range, index, parent) match try scope_obj("imports")? end - | let seq: json.Sequence => + | let seq: json.Sequence val => for item in seq.values() do match item - | let obj: json.Object => + | let obj: json.Object val => try let node_index = USize.from[I128](obj("node")? as I128) let identifier = obj("identifier")? as String box @@ -255,10 +259,10 @@ primitive ParseScopeJson end end match try scope_obj("definitions")? end - | let seq: json.Sequence => + | let seq: json.Sequence val => for item in seq.values() do match item - | let obj: json.Object => + | let obj: json.Object val => try let node_index = USize.from[I128](obj("node")? as I128) let identifier = obj("identifier")? as String box @@ -272,7 +276,7 @@ primitive ParseScopeJson end end match try scope_obj("children")? end - | let seq: json.Sequence => + | let seq: json.Sequence val => for item in seq.values() do match ParseScopeJson(auth, item, scope) | let child: Scope ref => diff --git a/eohippus/ast/annotation.pony b/eohippus/ast/annotation.pony index 800fd7e..a81873a 100644 --- a/eohippus/ast/annotation.pony +++ b/eohippus/ast/annotation.pony @@ -17,7 +17,7 @@ class val Annotation is NodeData props.push(("identifiers", node.child_refs(identifiers))) primitive ParseAnnotation - fun apply(obj: json.Object, children: NodeSeq): (Annotation | String) => + fun apply(obj: json.Object val, children: NodeSeq): (Annotation | String) => let identifiers = match ParseNode._get_seq_with[Identifier]( obj, diff --git a/eohippus/ast/call_args.pony b/eohippus/ast/call_args.pony index d461420..55f2db6 100644 --- a/eohippus/ast/call_args.pony +++ b/eohippus/ast/call_args.pony @@ -32,7 +32,7 @@ class val CallArgs is NodeData end primitive ParseCallArgs - fun apply(obj: json.Object, children: NodeSeq): (CallArgs | String) => + fun apply(obj: json.Object val, children: NodeSeq): (CallArgs | String) => let positional = match ParseNode._get_seq_with[Expression]( obj, diff --git a/eohippus/ast/doc_string.pony b/eohippus/ast/doc_string.pony index aa71051..2f4478c 100644 --- a/eohippus/ast/doc_string.pony +++ b/eohippus/ast/doc_string.pony @@ -17,7 +17,7 @@ class val DocString is NodeData props.push(("string", node.child_ref(string))) primitive ParseDocString - fun apply(obj: json.Object, children: NodeSeq): (DocString | String) => + fun apply(obj: json.Object val, children: NodeSeq): (DocString | String) => let string = match ParseNode._get_child_with[LiteralString]( obj, diff --git a/eohippus/ast/error_section.pony b/eohippus/ast/error_section.pony index 2254371..8beadfc 100644 --- a/eohippus/ast/error_section.pony +++ b/eohippus/ast/error_section.pony @@ -21,7 +21,7 @@ class val ErrorSection is NodeData props.push(("message", message)) primitive ParseErrorSection - fun apply(obj: json.Object, children: NodeSeq): (ErrorSection | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ErrorSection | String) => let message = match try obj("message")? end | let message': String box => diff --git a/eohippus/ast/exp_array.pony b/eohippus/ast/exp_array.pony index 91f413e..5d6d43e 100644 --- a/eohippus/ast/exp_array.pony +++ b/eohippus/ast/exp_array.pony @@ -34,7 +34,7 @@ class val ExpArray is NodeData end primitive ParseExpArray - fun apply(obj: json.Object, children: NodeSeq): (ExpArray | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpArray | String) => let array_type = match ParseNode._get_child_with[TypeType]( obj, diff --git a/eohippus/ast/exp_atom.pony b/eohippus/ast/exp_atom.pony index f6e6e59..0e44e10 100644 --- a/eohippus/ast/exp_atom.pony +++ b/eohippus/ast/exp_atom.pony @@ -21,7 +21,7 @@ class val ExpAtom is NodeData props.push(("body", node.child_ref(body))) primitive ParseExpAtom - fun apply(obj: json.Object, children: NodeSeq): (ExpAtom | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpAtom | String) => let body = match ParseNode._get_child( obj, diff --git a/eohippus/ast/exp_call.pony b/eohippus/ast/exp_call.pony index b83db50..7081504 100644 --- a/eohippus/ast/exp_call.pony +++ b/eohippus/ast/exp_call.pony @@ -37,7 +37,7 @@ class val ExpCall is NodeData end primitive ParseExpCall - fun apply(obj: json.Object, children: NodeSeq): (ExpCall | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpCall | String) => let lhs = match ParseNode._get_child_with[Expression]( obj, diff --git a/eohippus/ast/exp_consume.pony b/eohippus/ast/exp_consume.pony index eb77e78..568e92c 100644 --- a/eohippus/ast/exp_consume.pony +++ b/eohippus/ast/exp_consume.pony @@ -28,7 +28,7 @@ class val ExpConsume is NodeData props.push(("body", node.child_ref(body))) primitive ParseExpConsume - fun apply(obj: json.Object, children: NodeSeq): (ExpConsume | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpConsume | String) => let cap = match ParseNode._get_child_with[Keyword]( obj, diff --git a/eohippus/ast/exp_decl.pony b/eohippus/ast/exp_decl.pony index 0075687..f54f5cb 100644 --- a/eohippus/ast/exp_decl.pony +++ b/eohippus/ast/exp_decl.pony @@ -38,7 +38,7 @@ class val ExpDecl is NodeData end primitive ParseExpDecl - fun apply(obj: json.Object, children: NodeSeq): (ExpDecl | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpDecl | String) => let kind = match ParseNode._get_child_with[Keyword]( obj, children, "kind", "ExpDecl.kind must be a Keyword") diff --git a/eohippus/ast/exp_ffi.pony b/eohippus/ast/exp_ffi.pony index ca120b2..46540d0 100644 --- a/eohippus/ast/exp_ffi.pony +++ b/eohippus/ast/exp_ffi.pony @@ -48,7 +48,7 @@ class val ExpFfi is NodeData primitive ParseExpFfi fun help_id(): String => "ExpFfi.identifier must be an Identifier or Literal" - fun apply(obj: json.Object, children: NodeSeq): (ExpFfi | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpFfi | String) => let identifier = match ParseNode._get_child(obj, children, "identifier", help_id()) | let node: Node => diff --git a/eohippus/ast/exp_for.pony b/eohippus/ast/exp_for.pony index f1279d1..7d6af2e 100644 --- a/eohippus/ast/exp_for.pony +++ b/eohippus/ast/exp_for.pony @@ -40,7 +40,7 @@ class val ExpFor is NodeData end primitive ParseExpFor - fun apply(obj: json.Object, children: NodeSeq): (ExpFor | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpFor | String) => let pattern = match ParseNode._get_child_with[TuplePattern]( obj, diff --git a/eohippus/ast/exp_generic.pony b/eohippus/ast/exp_generic.pony index 06a5eb7..72ba685 100644 --- a/eohippus/ast/exp_generic.pony +++ b/eohippus/ast/exp_generic.pony @@ -24,7 +24,7 @@ class val ExpGeneric is NodeData props.push(("type_args", node.child_ref(type_args))) primitive ParseExpGeneric - fun apply(obj: json.Object, children: NodeSeq): (ExpGeneric | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpGeneric | String) => let lhs = match ParseNode._get_child_with[Expression]( obj, diff --git a/eohippus/ast/exp_hash.pony b/eohippus/ast/exp_hash.pony index 5e246e9..d8ac736 100644 --- a/eohippus/ast/exp_hash.pony +++ b/eohippus/ast/exp_hash.pony @@ -19,7 +19,7 @@ class val ExpHash is NodeData props.push(("rhs", node.child_ref(rhs))) primitive ParseExpHash - fun apply(obj: json.Object, children: NodeSeq): (ExpHash | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpHash | String) => let rhs = match ParseNode._get_child_with[Expression]( obj, diff --git a/eohippus/ast/exp_if.pony b/eohippus/ast/exp_if.pony index 9dc752d..2714402 100644 --- a/eohippus/ast/exp_if.pony +++ b/eohippus/ast/exp_if.pony @@ -48,7 +48,7 @@ class val ExpIf is NodeData end primitive ParseExpIf - fun apply(obj: json.Object, children: NodeSeq): (ExpIf | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpIf | String) => let kind = match try obj("kind")? end | let str: String box => @@ -117,7 +117,7 @@ class val IfCondition is NodeData props.push(("then_block", node.child_ref(then_block))) primitive ParseIfCondition - fun apply(obj: json.Object, children: NodeSeq): (IfCondition | String) => + fun apply(obj: json.Object val, children: NodeSeq): (IfCondition | String) => let if_true = match ParseNode._get_child_with[Expression]( obj, diff --git a/eohippus/ast/exp_jump.pony b/eohippus/ast/exp_jump.pony index ff225e7..f578c21 100644 --- a/eohippus/ast/exp_jump.pony +++ b/eohippus/ast/exp_jump.pony @@ -32,7 +32,7 @@ class val ExpJump is NodeData end primitive ParseExpJump - fun apply(obj: json.Object, children: NodeSeq): (ExpJump | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpJump | String) => let keyword = match ParseNode._get_child_with[Keyword]( obj, diff --git a/eohippus/ast/exp_lambda.pony b/eohippus/ast/exp_lambda.pony index ac40a68..27df25a 100644 --- a/eohippus/ast/exp_lambda.pony +++ b/eohippus/ast/exp_lambda.pony @@ -90,7 +90,7 @@ class val ExpLambda is NodeData end primitive ParseExpLambda - fun apply(obj: json.Object, children: NodeSeq): (ExpLambda | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpLambda | String) => let bare = match try obj("bare")? end | let bool: Bool => diff --git a/eohippus/ast/exp_match.pony b/eohippus/ast/exp_match.pony index 8f66a97..d80e18f 100644 --- a/eohippus/ast/exp_match.pony +++ b/eohippus/ast/exp_match.pony @@ -34,7 +34,7 @@ class val ExpMatch is NodeData end primitive ParseExpMatch - fun apply(obj: json.Object, children: NodeSeq): (ExpMatch | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpMatch | String) => let expression = match ParseNode._get_child_with[Expression]( obj, @@ -99,7 +99,7 @@ class val MatchPattern is NodeData end primitive ParseMatchPattern - fun apply(obj: json.Object, children: NodeSeq): (MatchPattern | String) => + fun apply(obj: json.Object val, children: NodeSeq): (MatchPattern | String) => let pattern = match ParseNode._get_child_with[Expression]( obj, @@ -152,7 +152,7 @@ class val MatchCase is NodeData props.push(("body", node.child_ref(body))) primitive ParseMatchCase - fun apply(obj: json.Object, children: NodeSeq): (MatchCase | String) => + fun apply(obj: json.Object val, children: NodeSeq): (MatchCase | String) => let patterns = match ParseNode._get_seq_with[MatchPattern]( obj, diff --git a/eohippus/ast/exp_object.pony b/eohippus/ast/exp_object.pony index 956b78a..2645468 100644 --- a/eohippus/ast/exp_object.pony +++ b/eohippus/ast/exp_object.pony @@ -36,7 +36,7 @@ class val ExpObject is NodeData props.push(("members", node.child_ref(members))) primitive ParseExpObject - fun apply(obj: json.Object, children: NodeSeq): (ExpObject | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpObject | String) => let cap = match ParseNode._get_child_with[Keyword]( obj, diff --git a/eohippus/ast/exp_operation.pony b/eohippus/ast/exp_operation.pony index f6b5483..7a3ee83 100644 --- a/eohippus/ast/exp_operation.pony +++ b/eohippus/ast/exp_operation.pony @@ -69,7 +69,7 @@ class val ExpOperation is NodeData end primitive ParseExpOperation - fun apply(obj: json.Object, children: NodeSeq): (ExpOperation | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpOperation | String) => let lhs = match ParseNode._get_child( obj, diff --git a/eohippus/ast/exp_recover.pony b/eohippus/ast/exp_recover.pony index 7a20114..9954393 100644 --- a/eohippus/ast/exp_recover.pony +++ b/eohippus/ast/exp_recover.pony @@ -28,7 +28,7 @@ class val ExpRecover is NodeData props.push(("body", node.child_ref(body))) primitive ParseExpRecover - fun apply(obj: json.Object, children: NodeSeq): (ExpRecover | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpRecover | String) => let cap = match ParseNode._get_child_with[Keyword]( obj, diff --git a/eohippus/ast/exp_repeat.pony b/eohippus/ast/exp_repeat.pony index af773ae..3f8d775 100644 --- a/eohippus/ast/exp_repeat.pony +++ b/eohippus/ast/exp_repeat.pony @@ -33,7 +33,7 @@ class val ExpRepeat is NodeData end primitive ParseExpRepeat - fun apply(obj: json.Object, children: NodeSeq): (ExpRepeat | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpRepeat | String) => let body = match ParseNode._get_child_with[Expression]( obj, diff --git a/eohippus/ast/exp_sequence.pony b/eohippus/ast/exp_sequence.pony index 899afa2..272bd5c 100644 --- a/eohippus/ast/exp_sequence.pony +++ b/eohippus/ast/exp_sequence.pony @@ -19,7 +19,7 @@ class val ExpSequence is NodeData props.push(("expressions", node.child_refs(expressions))) primitive ParseExpSequence - fun apply(obj: json.Object, children: NodeSeq): (ExpSequence | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpSequence | String) => let expressions = match ParseNode._get_seq_with[Expression]( obj, diff --git a/eohippus/ast/exp_try.pony b/eohippus/ast/exp_try.pony index 1f82435..6827321 100644 --- a/eohippus/ast/exp_try.pony +++ b/eohippus/ast/exp_try.pony @@ -31,7 +31,7 @@ class val ExpTry is NodeData end primitive ParseExpTry - fun apply(obj: json.Object, children: NodeSeq): (ExpTry | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpTry | String) => let body = match ParseNode._get_child_with[Expression]( obj, diff --git a/eohippus/ast/exp_tuple.pony b/eohippus/ast/exp_tuple.pony index a8b6c44..f5b88fe 100644 --- a/eohippus/ast/exp_tuple.pony +++ b/eohippus/ast/exp_tuple.pony @@ -19,7 +19,7 @@ class val ExpTuple is NodeData end primitive ParseExpTuple - fun apply(obj: json.Object, children: NodeSeq): (ExpTuple | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpTuple | String) => let sequences = match ParseNode._get_seq_with[Expression]( obj, diff --git a/eohippus/ast/exp_while.pony b/eohippus/ast/exp_while.pony index 52c98fc..dea718c 100644 --- a/eohippus/ast/exp_while.pony +++ b/eohippus/ast/exp_while.pony @@ -33,7 +33,7 @@ class val ExpWhile is NodeData end primitive ParseExpWhile - fun apply(obj: json.Object, children: NodeSeq): (ExpWhile | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpWhile | String) => let condition = match ParseNode._get_child_with[Expression]( obj, diff --git a/eohippus/ast/exp_with.pony b/eohippus/ast/exp_with.pony index c3200e8..a79596a 100644 --- a/eohippus/ast/exp_with.pony +++ b/eohippus/ast/exp_with.pony @@ -27,7 +27,7 @@ class val ExpWith is NodeData props.push(("body", node.child_ref(body))) primitive ParseExpWith - fun apply(obj: json.Object, children: NodeSeq): (ExpWith | String) => + fun apply(obj: json.Object val, children: NodeSeq): (ExpWith | String) => let elements = match ParseNode._get_seq_with[WithElement]( obj, @@ -80,7 +80,7 @@ class val WithElement is NodeData props.push(("body", node.child_ref(body))) primitive ParseWithElement - fun apply(obj: json.Object, children: NodeSeq): (WithElement | String) => + fun apply(obj: json.Object val, children: NodeSeq): (WithElement | String) => let pattern = match ParseNode._get_child_with[TuplePattern]( obj, diff --git a/eohippus/ast/identifier.pony b/eohippus/ast/identifier.pony index 89dd789..6ac85e3 100644 --- a/eohippus/ast/identifier.pony +++ b/eohippus/ast/identifier.pony @@ -15,7 +15,7 @@ class val Identifier is NodeData props.push(("string", string)) primitive ParseIdentifier - fun apply(obj: json.Object, children: NodeSeq): (Identifier | String) => + fun apply(obj: json.Object val, children: NodeSeq): (Identifier | String) => let string = match try obj("string")? end | let s: String box => diff --git a/eohippus/ast/keyword.pony b/eohippus/ast/keyword.pony index 2e1708c..417ccfd 100644 --- a/eohippus/ast/keyword.pony +++ b/eohippus/ast/keyword.pony @@ -82,7 +82,7 @@ class val Keyword is NodeData props.push(("string", string)) primitive ParseKeyword - fun apply(obj: json.Object, children: NodeSeq): (Keyword | String) => + fun apply(obj: json.Object val, children: NodeSeq): (Keyword | String) => let string = match try obj("string")? end | let str: String box => diff --git a/eohippus/ast/literal_bool.pony b/eohippus/ast/literal_bool.pony index e56a253..4ab216d 100644 --- a/eohippus/ast/literal_bool.pony +++ b/eohippus/ast/literal_bool.pony @@ -17,7 +17,7 @@ class val LiteralBool is NodeDataWithValue[LiteralBool, Bool] fun value(): Bool => _value primitive ParseLiteralBool - fun apply(obj: json.Object, children: NodeSeq): (LiteralBool | String) => + fun apply(obj: json.Object val, children: NodeSeq): (LiteralBool | String) => let value = match try obj("value")? end | let bool: Bool => diff --git a/eohippus/ast/literal_char.pony b/eohippus/ast/literal_char.pony index b7e29da..ff63186 100644 --- a/eohippus/ast/literal_char.pony +++ b/eohippus/ast/literal_char.pony @@ -39,7 +39,7 @@ class val LiteralChar is NodeDataWithValue[LiteralChar, U32] fun value(): U32 => _value primitive ParseLiteralChar - fun apply(obj: json.Object, children: NodeSeq): (LiteralChar | String) => + fun apply(obj: json.Object val, children: NodeSeq): (LiteralChar | String) => let kind = match try obj("kind")? end | let str: String box => diff --git a/eohippus/ast/literal_float.pony b/eohippus/ast/literal_float.pony index 1a8fbbc..efd185b 100644 --- a/eohippus/ast/literal_float.pony +++ b/eohippus/ast/literal_float.pony @@ -17,7 +17,7 @@ class val LiteralFloat is NodeDataWithValue[LiteralFloat, F64] fun value(): F64 => _value primitive ParseLiteralFloat - fun apply(obj: json.Object, children: NodeSeq): (LiteralFloat | String) => + fun apply(obj: json.Object val, children: NodeSeq): (LiteralFloat | String) => let value = match try obj("value")? end | let float: F64 => diff --git a/eohippus/ast/literal_integer.pony b/eohippus/ast/literal_integer.pony index 228528d..c44ec69 100644 --- a/eohippus/ast/literal_integer.pony +++ b/eohippus/ast/literal_integer.pony @@ -31,7 +31,9 @@ class val LiteralInteger is NodeDataWithValue[LiteralInteger, U128] fun value(): U128 => _value primitive ParseLiteralInteger - fun apply(obj: json.Object, children: NodeSeq): (LiteralInteger | String) => + fun apply(obj: json.Object val, children: NodeSeq) + : (LiteralInteger | String) + => let value = match try obj("value")? end | let n: I128 => diff --git a/eohippus/ast/literal_string.pony b/eohippus/ast/literal_string.pony index 23414e7..49d6a34 100644 --- a/eohippus/ast/literal_string.pony +++ b/eohippus/ast/literal_string.pony @@ -30,7 +30,9 @@ class val LiteralString is NodeDataWithValue[LiteralString, String] fun value(): String => _value primitive ParseLiteralString - fun apply(obj: json.Object, children: NodeSeq): (LiteralString | String) => + fun apply(obj: json.Object val, children: NodeSeq) + : (LiteralString | String) + => let value = match try obj("value")? end | let str: String box => diff --git a/eohippus/ast/method_params.pony b/eohippus/ast/method_params.pony index 39a6b18..2f70239 100644 --- a/eohippus/ast/method_params.pony +++ b/eohippus/ast/method_params.pony @@ -21,7 +21,7 @@ class val MethodParams is NodeData end primitive ParseMethodParams - fun apply(obj: json.Object, children: NodeSeq): (MethodParams | String) => + fun apply(obj: json.Object val, children: NodeSeq): (MethodParams | String) => let params = match ParseNode._get_seq_with[MethodParam]( obj, @@ -70,7 +70,7 @@ class val MethodParam is NodeData end primitive ParseMethodParam - fun apply(obj: json.Object, children: NodeSeq): (MethodParam | String) => + fun apply(obj: json.Object val, children: NodeSeq): (MethodParam | String) => let identifier = match ParseNode._get_child_with[Identifier]( obj, diff --git a/eohippus/ast/node.pony b/eohippus/ast/node.pony index 43cedde..cc8b860 100644 --- a/eohippus/ast/node.pony +++ b/eohippus/ast/node.pony @@ -52,8 +52,7 @@ trait val Node fun scope_index(): (USize | None) - fun get_json() - : json.Object + fun get_json() : json.Object """Get a JSON representation of the node.""" fun map[D: NodeData val](seq: NodeSeqWith[D], updates: ChildUpdateMap) @@ -80,11 +79,11 @@ trait val Node I128.from[ISize](-1) fun child_refs(childs: NodeSeq): json.Item => - let items: Array[json.Item] = Array[json.Item](childs.size()) + let seq = Array[json.Item](childs.size()) for child in childs.values() do - items.push(child_ref(child)) + seq.push(child_ref(child)) end - json.Sequence(consume items) + json.Sequence(seq) fun string(): String iso^ diff --git a/eohippus/ast/node_with.pony b/eohippus/ast/node_with.pony index b4c2e3d..e78f498 100644 --- a/eohippus/ast/node_with.pony +++ b/eohippus/ast/node_with.pony @@ -304,9 +304,7 @@ class val NodeWith[D: NodeData val] is Node fun scope_index(): (USize | None) => _scope_index - fun get_json() - : json.Object - => + fun get_json() : json.Object => """Get a JSON representation of the node.""" let props = [ as (String, json.Item): ("name", name()) ] match (_src_info.line, _src_info.column) @@ -341,9 +339,9 @@ class val NodeWith[D: NodeData val] is Node props.push(("post_trivia", child_refs(_post_trivia))) end if _children.size() > 0 then - let child_json = json.Sequence.from_iter( - Iter[Node](_children.values()).map[json.Item]( - {(child) => child.get_json()})) + let child_json = + json.Sequence.from_iter[Node]( + children().values(), {(child) => child.get_json() }) props.push(("children", child_json)) end json.Object(props) diff --git a/eohippus/ast/parse_node.pony b/eohippus/ast/parse_node.pony index 3cf7886..a1c895b 100644 --- a/eohippus/ast/parse_node.pony +++ b/eohippus/ast/parse_node.pony @@ -2,7 +2,7 @@ use json = "../json" use parser = "../parser" primitive ParseNode - fun apply(locator: parser.Locator, obj: json.Object): (Node | String) => + fun apply(locator: parser.Locator, obj: json.Object val): (Node | String) => let name = match try obj("name")? end | let str: String box => @@ -12,7 +12,7 @@ primitive ParseNode end let src_info = match try obj("src_info")? end - | let src_info_obj: json.Object box => + | let src_info_obj: json.Object val => let line' = match try src_info_obj("line")? end | let n: I128 => @@ -57,10 +57,10 @@ primitive ParseNode let children': Array[Node] trn = Array[Node] match try obj("children")? end - | let children_seq: json.Sequence => + | let children_seq: json.Sequence val => for child_item in children_seq.values() do match child_item - | let child_obj: json.Object => + | let child_obj: json.Object val => match ParseNode(locator, child_obj) | let n: Node => children'.push(n) @@ -72,7 +72,7 @@ primitive ParseNode end end end - let children: Array[Node] val = consume children' + let children: ReadSeq[Node] val = consume children' let annotation = match try obj("annotation")? end @@ -88,7 +88,6 @@ primitive ParseNode else return "annotation must refer to an Annotation" end - let doc_strings = match _get_seq_with[DocString]( obj, @@ -267,8 +266,38 @@ primitive ParseNode "unknown node data type " + name end + fun _ctor[D: NodeData val]( + ctor: {ref (): (D | String)}, + src_info: SrcInfo, + children: NodeSeq, + annotation: (NodeWith[Annotation] | None), + doc_strings: NodeSeqWith[DocString], + pre_trivia: NodeSeqWith[Trivia], + post_trivia: NodeSeqWith[Trivia], + scope_index: (USize | None)) + : (Node | String) + => + let data = + match ctor() + | let data': D => + data' + | let err: String => + return err + end + + NodeWith[D]( + src_info, + children, + data, + annotation, + doc_strings, + pre_trivia, + post_trivia, + None, + scope_index) + fun _get_child( - obj: json.Object, + obj: json.Object val, children: NodeSeq, key: String, help: String, @@ -290,7 +319,7 @@ primitive ParseNode end fun _get_child_with[D: NodeData val]( - obj: json.Object, + obj: json.Object val, children: NodeSeq, key: String, help: String, @@ -316,7 +345,7 @@ primitive ParseNode end fun _get_seq_with[D: NodeData val]( - obj: json.Object, + obj: json.Object val, children: NodeSeq, key: String, help: String, @@ -324,7 +353,7 @@ primitive ParseNode : (NodeSeqWith[D] | String) => match try obj(key)? end - | let seq: json.Sequence => + | let seq: json.Sequence box => let nodes: Array[NodeWith[D]] trn = Array[NodeWith[D]] for item in seq.values() do match item @@ -349,42 +378,13 @@ primitive ParseNode end end - fun _ctor[D: NodeData val]( - ctor: {(): (D | String)} box, - src_info: SrcInfo, - children: NodeSeq, - annotation: (NodeWith[Annotation] | None), - doc_strings: NodeSeqWith[DocString], - pre_trivia: NodeSeqWith[Trivia], - post_trivia: NodeSeqWith[Trivia], - scope_index: (USize | None)) - : (Node | String) - => - let data = - match ctor() - | let data': D => - data' - | let err: String => - return err - end - - NodeWith[D]( - src_info, - children, - data, - annotation, - doc_strings, - pre_trivia, - post_trivia, - None, - scope_index) - type _NodeConstructor is - {(SrcInfo, - NodeSeq, - (NodeWith[Annotation] | None), - NodeSeqWith[DocString], - NodeSeqWith[Trivia], - NodeSeqWith[Trivia], - (USize | None)) - : (Node | String)} box + { ref + ( SrcInfo + , NodeSeq + , (NodeWith[Annotation] | None) + , NodeSeqWith[DocString] + , NodeSeqWith[Trivia] + , NodeSeqWith[Trivia] + , (USize | None) ) + : (Node | String) } diff --git a/eohippus/ast/span.pony b/eohippus/ast/span.pony index 1986e7d..e029875 100644 --- a/eohippus/ast/span.pony +++ b/eohippus/ast/span.pony @@ -15,5 +15,5 @@ class val Span is NodeData None primitive ParseSpan - fun apply(obj: json.Object, children: NodeSeq): (Span | String) => + fun apply(obj: json.Object val, children: NodeSeq): (Span | String) => recover Span end diff --git a/eohippus/ast/src_file.pony b/eohippus/ast/src_file.pony index c57a814..0c78b72 100644 --- a/eohippus/ast/src_file.pony +++ b/eohippus/ast/src_file.pony @@ -37,7 +37,7 @@ class val SrcFile is NodeData end primitive ParseSrcFile - fun apply(obj: json.Object, children: NodeSeq): (SrcFile | String) => + fun apply(obj: json.Object val, children: NodeSeq): (SrcFile | String) => let locator = match try obj("locator")? end | let str: String box => diff --git a/eohippus/ast/syntax_tree.pony b/eohippus/ast/syntax_tree.pony index 98979aa..7dc81bd 100644 --- a/eohippus/ast/syntax_tree.pony +++ b/eohippus/ast/syntax_tree.pony @@ -63,40 +63,44 @@ primitive SyntaxTree // we inside-out these matches, because we still want to populate // new_children if there's a None new child, to record that the children // changed - match (new_children, update_map) - | (let nc: Array[Node] trn, let um: ChildUpdateMap trn) => - match new_child - | let new_child': Node => - nc.push(new_child') - um(child) = new_child' - end - | (None, None) if new_child isnt child => - let nc: Array[Node] trn = Array[Node](node.children().size()) - let um: ChildUpdateMap trn = ChildUpdateMap(node.children().size()) + (new_children, update_map) = + match (consume new_children, consume update_map) + | (let nc: Array[Node] trn, let um: ChildUpdateMap trn) => + match new_child + | let new_child': Node => + nc.push(new_child') + um.update(child, new_child') + end + (consume nc, consume um) + | (None, None) if new_child isnt child => + let nc: Array[Node] trn = Array[Node](node.children().size()) + let um: ChildUpdateMap trn = ChildUpdateMap(node.children().size()) - // if we haven't seen any changes until now, fill up our new_children - // with the old ones - for j in col.Range(0, i) do - try - let old_child = node.children()(j)? - nc.push(old_child) - um(old_child) = old_child + // if we haven't seen any changes until now, fill up our new_children + // with the old ones + for j in col.Range(0, i) do + try + let old_child = node.children()(j)? + nc.push(old_child) + um(old_child) = old_child + end end - end - match new_child - | let new_child': Node => - nc.push(new_child') - um(child) = new_child' + match new_child + | let new_child': Node => + nc.push(new_child') + um(child) = new_child' + end + (consume nc, consume um) + | ( let nc: (Array[Node] trn | None) + , let um: (ChildUpdateMap trn | None)) + => + (consume nc, consume um) end - - new_children = consume nc - update_map = consume um - end i = i + 1 end - match (new_children, update_map) + match (consume new_children, consume update_map) | (let nc: Array[Node] trn, let um: ChildUpdateMap trn) => (node_state, let new_node, errors') = visitor.visit_post( node_state, diff --git a/eohippus/ast/token.pony b/eohippus/ast/token.pony index b32f3bc..7ad1ea6 100644 --- a/eohippus/ast/token.pony +++ b/eohippus/ast/token.pony @@ -76,7 +76,7 @@ class val Token is NodeData props.push(("string", string)) primitive ParseToken - fun apply(obj: json.Object, children: NodeSeq): (Token | String) => + fun apply(obj: json.Object val, children: NodeSeq): (Token | String) => let string = match try obj("string")? end | let s: String box => diff --git a/eohippus/ast/trivia.pony b/eohippus/ast/trivia.pony index 6225a74..11aeccb 100644 --- a/eohippus/ast/trivia.pony +++ b/eohippus/ast/trivia.pony @@ -41,7 +41,7 @@ class val Trivia is NodeData props.push(("string", string)) primitive ParseTrivia - fun apply(obj: json.Object, children: NodeSeq): (Trivia | String) => + fun apply(obj: json.Object val, children: NodeSeq): (Trivia | String) => let kind: TriviaKind = match try obj("kind")? end | "LineCommentTrivia" => diff --git a/eohippus/ast/tuple_pattern.pony b/eohippus/ast/tuple_pattern.pony index 54c8838..56dd9ca 100644 --- a/eohippus/ast/tuple_pattern.pony +++ b/eohippus/ast/tuple_pattern.pony @@ -35,11 +35,11 @@ primitive ParseTuplePattern fun _help(): String => "TuplePattern.elements must be a sequence of " + "(Identifier | TuplePattern)" - fun apply(obj: json.Object, children: NodeSeq): (TuplePattern | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TuplePattern | String) => let elements: Array[(NodeWith[Identifier] | NodeWith[TuplePattern])] trn = Array[(NodeWith[Identifier] | NodeWith[TuplePattern])] match try obj("elements")? end - | let seq: json.Sequence => + | let seq: json.Sequence val => for item in seq.values() do match item | let i: I128 => diff --git a/eohippus/ast/type_args.pony b/eohippus/ast/type_args.pony index aa7c48b..1f422d9 100644 --- a/eohippus/ast/type_args.pony +++ b/eohippus/ast/type_args.pony @@ -19,7 +19,7 @@ class val TypeArgs is NodeData props.push(("types", node.child_refs(types))) primitive ParseTypeArgs - fun apply(obj: json.Object, children: NodeSeq): (TypeArgs | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypeArgs | String) => let types = match ParseNode._get_seq_with[TypeType]( obj, diff --git a/eohippus/ast/type_arrow.pony b/eohippus/ast/type_arrow.pony index f65e4a7..72446c4 100644 --- a/eohippus/ast/type_arrow.pony +++ b/eohippus/ast/type_arrow.pony @@ -28,7 +28,7 @@ class val TypeArrow is NodeData end primitive ParseTypeArrow - fun apply(obj: json.Object, children: NodeSeq): (TypeArrow | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypeArrow | String) => let lhs = match ParseNode._get_child( obj, diff --git a/eohippus/ast/type_atom.pony b/eohippus/ast/type_atom.pony index 7d6b66c..4bc0629 100644 --- a/eohippus/ast/type_atom.pony +++ b/eohippus/ast/type_atom.pony @@ -17,7 +17,7 @@ class val TypeAtom is NodeData props.push(("body", node.child_ref(body))) primitive ParseTypeAtom - fun apply(obj: json.Object, children: NodeSeq): (TypeAtom | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypeAtom | String) => let body = match ParseNode._get_child( obj, diff --git a/eohippus/ast/type_infix.pony b/eohippus/ast/type_infix.pony index 4a5b507..fb0d25f 100644 --- a/eohippus/ast/type_infix.pony +++ b/eohippus/ast/type_infix.pony @@ -31,7 +31,7 @@ class val TypeInfix is NodeData end primitive ParseTypeInfix - fun apply(obj: json.Object, children: NodeSeq): (TypeInfix | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypeInfix | String) => let types = match ParseNode._get_seq_with[TypeType]( obj, diff --git a/eohippus/ast/type_lambda.pony b/eohippus/ast/type_lambda.pony index 06fa2a8..0357774 100644 --- a/eohippus/ast/type_lambda.pony +++ b/eohippus/ast/type_lambda.pony @@ -82,7 +82,7 @@ class val TypeLambda is NodeData end primitive ParseTypeLambda - fun apply(obj: json.Object, children: NodeSeq): (TypeLambda | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypeLambda | String) => let bare = match try obj("bare")? end | let bool: Bool => diff --git a/eohippus/ast/type_nominal.pony b/eohippus/ast/type_nominal.pony index 04d8a1b..86cdf65 100644 --- a/eohippus/ast/type_nominal.pony +++ b/eohippus/ast/type_nominal.pony @@ -54,7 +54,7 @@ class val TypeNominal is NodeData end primitive ParseTypeNominal - fun apply(obj: json.Object, children: NodeSeq): (TypeNominal | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypeNominal | String) => let lhs = match ParseNode._get_child_with[Identifier]( obj, diff --git a/eohippus/ast/type_params.pony b/eohippus/ast/type_params.pony index 2e7613d..15f0cab 100644 --- a/eohippus/ast/type_params.pony +++ b/eohippus/ast/type_params.pony @@ -19,7 +19,7 @@ class val TypeParams is NodeData end primitive ParseTypeParams - fun apply(obj: json.Object, children: NodeSeq): (TypeParams | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypeParams | String) => let params = match ParseNode._get_seq_with[TypeParam]( obj, @@ -71,7 +71,7 @@ class val TypeParam is NodeData end primitive ParseTypeParam - fun apply(obj: json.Object, children: NodeSeq): (TypeParam | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypeParam | String) => let identifier = match ParseNode._get_child_with[Identifier]( obj, diff --git a/eohippus/ast/type_tuple.pony b/eohippus/ast/type_tuple.pony index 05f2018..cedb2f1 100644 --- a/eohippus/ast/type_tuple.pony +++ b/eohippus/ast/type_tuple.pony @@ -18,7 +18,7 @@ class val TypeTuple is NodeData end primitive ParseTypeTuple - fun apply(obj: json.Object, children: NodeSeq): (TypeTuple | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypeTuple | String) => let types = match ParseNode._get_seq_with[TypeType]( obj, diff --git a/eohippus/ast/typedef_alias.pony b/eohippus/ast/typedef_alias.pony index fdb4287..43a5908 100644 --- a/eohippus/ast/typedef_alias.pony +++ b/eohippus/ast/typedef_alias.pony @@ -33,7 +33,7 @@ class val TypedefAlias is NodeData props.push(("type", node.child_ref(type_type))) primitive ParseTypedefAlias - fun apply(obj: json.Object, children: NodeSeq): (TypedefAlias | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypedefAlias | String) => let identifier = match ParseNode._get_child_with[Identifier]( obj, diff --git a/eohippus/ast/typedef_class.pony b/eohippus/ast/typedef_class.pony index 27e9a57..77a680e 100644 --- a/eohippus/ast/typedef_class.pony +++ b/eohippus/ast/typedef_class.pony @@ -67,7 +67,7 @@ class val TypedefClass is NodeData end primitive ParseTypedefClass - fun apply(obj: json.Object, children: NodeSeq): (TypedefClass | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypedefClass | String) => let kind = match ParseNode._get_child_with[Keyword]( obj, diff --git a/eohippus/ast/typedef_field.pony b/eohippus/ast/typedef_field.pony index 970de94..3717067 100644 --- a/eohippus/ast/typedef_field.pony +++ b/eohippus/ast/typedef_field.pony @@ -44,7 +44,7 @@ class val TypedefField is NodeData end primitive ParseTypedefField - fun apply(obj: json.Object, children: NodeSeq): (TypedefField | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypedefField | String) => let kind = match ParseNode._get_child_with[Keyword]( obj, diff --git a/eohippus/ast/typedef_members.pony b/eohippus/ast/typedef_members.pony index 663f892..d5a7d94 100644 --- a/eohippus/ast/typedef_members.pony +++ b/eohippus/ast/typedef_members.pony @@ -31,7 +31,9 @@ class val TypedefMembers is NodeData end primitive ParseTypedefMembers - fun apply(obj: json.Object, children: NodeSeq): (TypedefMembers | String) => + fun apply(obj: json.Object val, children: NodeSeq) + : (TypedefMembers | String) + => let fields = match ParseNode._get_seq_with[TypedefField]( obj, diff --git a/eohippus/ast/typedef_method.pony b/eohippus/ast/typedef_method.pony index e0f2260..49e2646 100644 --- a/eohippus/ast/typedef_method.pony +++ b/eohippus/ast/typedef_method.pony @@ -83,7 +83,9 @@ class val TypedefMethod is NodeData end primitive ParseTypedefMethod - fun apply(obj: json.Object, children: NodeSeq): (TypedefMethod | String) => + fun apply(obj: json.Object val, children: NodeSeq) + : (TypedefMethod | String) + => let kind = match ParseNode._get_child_with[Keyword]( obj, diff --git a/eohippus/ast/typedef_primitive.pony b/eohippus/ast/typedef_primitive.pony index 523ec99..ffc35b7 100644 --- a/eohippus/ast/typedef_primitive.pony +++ b/eohippus/ast/typedef_primitive.pony @@ -44,7 +44,7 @@ class val TypedefPrimitive is NodeData end primitive ParseTypedefPrimitive - fun apply(obj: json.Object, children: NodeSeq): (TypedefPrimitive | String) => + fun apply(obj: json.Object val, children: NodeSeq): (TypedefPrimitive | String) => let identifier = match ParseNode._get_child_with[Identifier]( obj, diff --git a/eohippus/ast/using.pony b/eohippus/ast/using.pony index 6828eb9..2df94ac 100644 --- a/eohippus/ast/using.pony +++ b/eohippus/ast/using.pony @@ -47,7 +47,7 @@ class val UsingPony is NodeData end primitive ParseUsingPony - fun apply(obj: json.Object, children: NodeSeq): (UsingPony | String) => + fun apply(obj: json.Object val, children: NodeSeq): (UsingPony | String) => let identifier = match ParseNode._get_child_with[Identifier]( obj, @@ -170,7 +170,7 @@ class val UsingFFI is NodeData end primitive ParseUsingFFI - fun apply(obj: json.Object, children: NodeSeq): (UsingFFI | String) => + fun apply(obj: json.Object val, children: NodeSeq): (UsingFFI | String) => let identifier = match ParseNode._get_child_with[Identifier]( obj, diff --git a/eohippus/json/item.pony b/eohippus/json/item.pony index d35181f..88e4660 100644 --- a/eohippus/json/item.pony +++ b/eohippus/json/item.pony @@ -4,25 +4,21 @@ use ".." primitive Null fun string(): String iso^ => "null".clone() -type Item is (Object | Sequence | String box | I128 | F64 | Bool | Null) +type Item is (Object box | Sequence box | String box | I128 | F64 | Bool | Null) primitive Clone - fun apply(item: Item): Item val => + fun apply(item: Item) + : (Object ref | Sequence ref | String ref | I128 | F64 | Bool | Null) + => match item - | let obj: Object => - let props: Seq[(String, Item val)] trn = Array[(String, Item val)] + | let obj: Object box => + let props = Array[(String, Item)] for (k, v) in obj.pairs() do props.push((k, Clone(v))) end - let props': Seq[(String, Item val)] val = consume props - recover Object(props') end - | let seq: Sequence => - let items: Seq[Item val] trn = Array[Item val] - for v in items.values() do - items.push(Clone(v)) - end - let items': Seq[Item val] val = consume items - recover Sequence(items') end + Object(props) + | let seq: Sequence box => + Sequence.from_iter[Item](seq.values(), {(i) => Clone(i) }) | let str: String box => str.clone() | let int: I128 => diff --git a/eohippus/json/object.pony b/eohippus/json/object.pony index 43d86e3..cc773fa 100644 --- a/eohippus/json/object.pony +++ b/eohippus/json/object.pony @@ -2,12 +2,16 @@ use "collections" use "itertools" use ".." -class box Object - embed _items: Array[(String, Item)] = _items.create() +class Object + embed _items: Array[(String, Item)] - new create(items: ReadSeq[(String, Item)] box = Array[(String, Item)]) => - for (key, value) in items.values() do - _items.push((key, value)) + new create(items: (ReadSeq[(String, Item)] | None) = None) => + match items + | let items': ReadSeq[(String, Item)] => + _items = _items.create(items'.size()) + _items.append(items') + else + _items = _items.create() end fun contains(key: (String | USize)): Bool => @@ -70,11 +74,11 @@ class box Object result.append("\"" + key + "\":") if pretty then result.append(" ") end match value - | let obj: this->Object box => + | let obj: Object box => result.append(obj.get_string(pretty, indent')) - | let seq: this->Sequence box => + | let seq: Sequence box => result.append(seq.get_string(pretty, indent')) - | let str: this->String box => + | let str: String box => result.append("\"" + StringUtil.escape(str) + "\"") | let int: I128 => result.append(int.string()) diff --git a/eohippus/json/parse.pony b/eohippus/json/parse.pony index f9febdc..a36250c 100644 --- a/eohippus/json/parse.pony +++ b/eohippus/json/parse.pony @@ -1,15 +1,15 @@ primitive Parse - fun apply(str: String): (Item | ParseError) => + fun apply(str: String): (Item val | ParseError) => let parser = Parser for ch in str.values() do match parser.parse_char(ch) - | let item: (Item | ParseError) => + | let item: (Item val | ParseError) => return item end end match parser.parse_char(0) - | let item: (Item | ParseError) => + | let item: (Item val | ParseError) => return item end ParseError(str.size(), "unknown error") @@ -51,7 +51,7 @@ type _ParseState is | _InFalse | _InNull ) -type _TempItem is +type _StackItem is ( Object trn | Sequence trn | String trn @@ -60,9 +60,9 @@ type _TempItem is | Bool | Null | U32 - | (String trn, None) - | (F64, F64) // frac; floating point, next fractional power of 10 - | (F64, I32) ) // exp; floating point, exponent (∞ or -∞ to start) + | (String, None) // property to be filled + | (F64, F64) // frac; floating point, next fractional power of 10 + | (F64, I32) ) // exp; floating point, exponent (∞ or -∞ to start) type _TrnItem is ( Object trn @@ -75,7 +75,7 @@ type _TrnItem is class Parser let _ten: F64 = 10.0 - let _value_stack: Array[_TempItem] = _value_stack.create() + let _value_stack: Array[_StackItem] = _value_stack.create() var _state: _ParseState = _ExpectItem var _index: USize = 0 var _line: USize = 1 @@ -316,7 +316,7 @@ class Parser fun ref _expect_next(): _ParseState ? => if _value_stack.size() > 0 then match _value_stack(_value_stack.size() - 1)? - | let _: Object trn => + | let _: Object tag => return _ExpectName end end @@ -412,7 +412,8 @@ class Parser fun ref _handle_in_string(is_name: Bool): (ParseError | None) ? => if _ch == '"' then if is_name then - _value_stack.push((_value_stack.pop()? as String trn^, None)) + let name = _value_stack.pop()? as String trn^ + _value_stack.push((consume name, None)) _state = _ExpectColon else _add_item(_value_stack.pop()? as String trn^)? @@ -421,7 +422,7 @@ class Parser elseif (_ch == '\\') and (not is_name) then _state = _InEscape else - (_value_stack(_value_stack.size() - 1)? as String trn^).push(_ch) + (_value_stack(_value_stack.size() - 1)? as String trn).push(_ch) end None @@ -443,7 +444,7 @@ class Parser if _expect_hex > 0 then _value_stack.push(cur) else - (_value_stack(_value_stack.size() - 1)? as String trn^).push_utf32(cur) + (_value_stack(_value_stack.size() - 1)? as String trn).push_utf32(cur) _state = _InString end else @@ -471,7 +472,7 @@ class Parser else _ch end - (_value_stack(_value_stack.size() - 1)? as String trn^).push(ch') + (_value_stack(_value_stack.size() - 1)? as String trn).push(ch') _state = _InString end None @@ -580,13 +581,15 @@ class Parser if _value_stack.size() == 0 then _value_stack.push(consume item) else - match _value_stack(_value_stack.size() - 1)? + let top = _value_stack.pop()? + match consume top | let seq: Sequence trn => seq.push(consume item) - | (let name: String trn, _) => - (_value_stack(_value_stack.size() - 2)? as Object trn) - .update(consume name, consume item) - _value_stack.pop()? + _value_stack.push(consume seq) + | (let name: String, _) => + let obj = _value_stack.pop()? as Object trn^ + obj.update(consume name, consume item) + _value_stack.push(consume obj) else error end diff --git a/eohippus/json/sequence.pony b/eohippus/json/sequence.pony index d63fb2f..a23859e 100644 --- a/eohippus/json/sequence.pony +++ b/eohippus/json/sequence.pony @@ -1,14 +1,22 @@ use "collections" +use "itertools" use ".." -class box Sequence - embed _items: Array[Item] = _items.create() +class Sequence + embed _items: Array[Item] - new create(items: ReadSeq[this->Item] box = Array[this->Item]) => - _items.append(items) + new create(items: (ReadSeq[Item] | None) = None) => + match items + | let items': ReadSeq[Item] => + _items = _items.create(items'.size()) + _items.append(items') + else + _items = Array[Item](0) + end - new from_iter(items: Iterator[this->Item]) => - _items.concat(items) + new from_iter[T](items: Iterator[T], f: {(T!): Item } box) => + _items = Array[Item] + Iter[T](items).map[Item](f).collect(_items) fun size(): USize => _items.size() @@ -44,11 +52,11 @@ class box Sequence end if pretty then result.append(indent') end match item - | let obj: this->Object box => + | let obj: Object box => result.append(obj.get_string(pretty, indent')) - | let seq: this->Sequence box => + | let seq: Sequence box => result.append(seq.get_string(pretty, indent')) - | let str: this->String box => + | let str: String box => result.append("\"" + StringUtil.escape(str) + "\"") | let int: I128 => result.append(int.string()) diff --git a/eohippus/json/subsumes.pony b/eohippus/json/subsumes.pony index 6eae986..7f9f544 100644 --- a/eohippus/json/subsumes.pony +++ b/eohippus/json/subsumes.pony @@ -65,10 +65,10 @@ primitive Subsumes if a_str == b_str then return (true, "") else - return ( - false, - "'" + StringUtil.escape(a_str) + "' at " + p + " != '" + - StringUtil.escape(b_str) + "'") + return + ( false + , "'" + StringUtil.escape(a_str) + "' at " + p + " != '" + + StringUtil.escape(b_str) + "'" ) end end (false, "rhs at " + p + " is not a string") diff --git a/eohippus/server/rpc/data/client_capabilities/client_capabilities.pony b/eohippus/server/rpc/data/client_capabilities/client_capabilities.pony index dc00a3e..bf3d426 100644 --- a/eohippus/server/rpc/data/client_capabilities/client_capabilities.pony +++ b/eohippus/server/rpc/data/client_capabilities/client_capabilities.pony @@ -4,7 +4,7 @@ interface val ClientCapabilities fun val workspace(): (WorkspaceClientCapabilities | None) fun val textDocument(): (TextDocumentClientCapabilities | None) fun val general(): (GeneralClientCapabilities | None) - fun val experimental(): (json.Item val | None) + fun val experimental(): (json.Item | None) primitive ParseClientCapabilities fun apply(obj: json.Object val): (ClientCapabilities | String) => @@ -50,11 +50,14 @@ primitive ParseClientCapabilities return "clientCapabilities.general must be a JSON object" end end - let experimental' = try json.Clone(obj("experimental")?) end + let experimental': (json.Item val | None) = + try + recover val json.Clone(obj("experimental")?) end + end object val is ClientCapabilities fun val workspace(): (WorkspaceClientCapabilities | None) => workspace' fun val textDocument(): (TextDocumentClientCapabilities | None) => textDocument' fun val general(): (GeneralClientCapabilities | None) => general' - fun val experimental(): (json.Item val | None) => experimental' + fun val experimental(): (json.Item | None) => experimental' end diff --git a/eohippus/server/rpc/data/client_capabilities/general_client_capabilities.pony b/eohippus/server/rpc/data/client_capabilities/general_client_capabilities.pony index 00cc0f2..24d6578 100644 --- a/eohippus/server/rpc/data/client_capabilities/general_client_capabilities.pony +++ b/eohippus/server/rpc/data/client_capabilities/general_client_capabilities.pony @@ -88,7 +88,7 @@ interface val StaleRequestSupport fun val retryOnContentModified(): Array[String] val primitive ParseStaleRequestSupport - fun apply(obj: json.Object): (StaleRequestSupport | String) => + fun apply(obj: json.Object val): (StaleRequestSupport | String) => let cancel' = try match obj("cancel")? @@ -103,7 +103,7 @@ primitive ParseStaleRequestSupport let retryOnContentModified': Array[String] val = try match obj("retryOnContentModified")? - | let r_seq: json.Sequence => + | let r_seq: json.Sequence val => let reqs: Array[String] trn = Array[String] for r_item in r_seq.values() do match r_item diff --git a/eohippus/server/rpc/data/client_capabilities/regular_expressions_client_capabilities.pony b/eohippus/server/rpc/data/client_capabilities/regular_expressions_client_capabilities.pony index 37e6b47..0d7da50 100644 --- a/eohippus/server/rpc/data/client_capabilities/regular_expressions_client_capabilities.pony +++ b/eohippus/server/rpc/data/client_capabilities/regular_expressions_client_capabilities.pony @@ -11,7 +11,7 @@ primitive ParseRegularExpressionsClientCapabilities let engine': String = try match obj("engine")? - | let e: String => + | let e: String val => e.clone() else return "regularExpressions.engine must be of type string" @@ -22,7 +22,7 @@ primitive ParseRegularExpressionsClientCapabilities let version': (String | None) = try match obj("version")? - | let v: String => + | let v: String val => v.clone() else return "regularExpressions.version must be of type string" diff --git a/eohippus/server/rpc/data/client_capabilities/text_document_client_capabilities.pony b/eohippus/server/rpc/data/client_capabilities/text_document_client_capabilities.pony index a0717d3..d2bc943 100644 --- a/eohippus/server/rpc/data/client_capabilities/text_document_client_capabilities.pony +++ b/eohippus/server/rpc/data/client_capabilities/text_document_client_capabilities.pony @@ -115,7 +115,7 @@ primitive ParseTagSupport let valueSet': Array[DiagnosticTag] val = try match obj("valueSet")? - | let vs_seq: json.Sequence => + | let vs_seq: json.Sequence val => let values: Array[DiagnosticTag] trn = Array[DiagnosticTag] for item in vs_seq.values() do values.push( diff --git a/eohippus/server/rpc/data/client_capabilities/workspace_client_capabilities.pony b/eohippus/server/rpc/data/client_capabilities/workspace_client_capabilities.pony index 065eb3d..d377722 100644 --- a/eohippus/server/rpc/data/client_capabilities/workspace_client_capabilities.pony +++ b/eohippus/server/rpc/data/client_capabilities/workspace_client_capabilities.pony @@ -19,7 +19,7 @@ interface val WorkspaceClientCapabilities // fun val diagnostics(): (DiagnosticWorkspaceClientCapabilities | None) primitive ParseWorkspaceClientCapabilities - fun apply(obj: json.Object): (WorkspaceClientCapabilities | String) => + fun apply(obj: json.Object val): (WorkspaceClientCapabilities | String) => let applyEdit' = try match obj("applyEdit")? @@ -32,7 +32,7 @@ primitive ParseWorkspaceClientCapabilities let workspaceEdit' = try match obj("workspaceEdit")? - | let we_obj: json.Object => + | let we_obj: json.Object val => match ParseWorkspaceEditClientCapabilities(we_obj) | let we: WorkspaceEditClientCapabilities => we diff --git a/eohippus/server/rpc/data/client_capabilities/workspace_edit_client_capabilities.pony b/eohippus/server/rpc/data/client_capabilities/workspace_edit_client_capabilities.pony index cd6c42e..665bb9a 100644 --- a/eohippus/server/rpc/data/client_capabilities/workspace_edit_client_capabilities.pony +++ b/eohippus/server/rpc/data/client_capabilities/workspace_edit_client_capabilities.pony @@ -11,7 +11,7 @@ interface val WorkspaceEditClientCapabilities // (ChangeAnnotationSupportClientCapability | None) primitive ParseWorkspaceEditClientCapabilities - fun apply(obj: json.Object): (WorkspaceEditClientCapabilities | String) => + fun apply(obj: json.Object val): (WorkspaceEditClientCapabilities | String) => let documentChanges' = try match obj("documentChanges")? @@ -24,7 +24,7 @@ primitive ParseWorkspaceEditClientCapabilities let resourceOperations': (Array[ResourceOperationKind] val | None) = try match obj("resourceOperations")? - | let ro_seq: json.Sequence => + | let ro_seq: json.Sequence val => let ops: Array[ResourceOperationKind] trn = Array[ResourceOperationKind] for item in ro_seq.values() do @@ -50,7 +50,7 @@ interface val ChangeAnnotationSupportClientCapability fun val groupsOnLabel(): (Bool | None) primitive ParseChangeAnnotationSupportClientCapability - fun apply(obj: json.Object): + fun apply(obj: json.Object val): (ChangeAnnotationSupportClientCapability | String) => let groupsOnLabel' = diff --git a/eohippus/server/rpc/data/document.pony b/eohippus/server/rpc/data/document.pony index e71bac1..acc5647 100644 --- a/eohippus/server/rpc/data/document.pony +++ b/eohippus/server/rpc/data/document.pony @@ -21,4 +21,4 @@ interface val DocumentFilter is SendData end json.Object(props) -type DocumentSelector is Seq[DocumentFilter] +type DocumentSelector is Seq[DocumentFilter] val diff --git a/eohippus/server/rpc/data/initialize_params.pony b/eohippus/server/rpc/data/initialize_params.pony index 2f8e085..93cb9a5 100644 --- a/eohippus/server/rpc/data/initialize_params.pony +++ b/eohippus/server/rpc/data/initialize_params.pony @@ -55,7 +55,7 @@ primitive ParseInitializeParams let locale': (String | None) = try match obj("locale")? - | let str: String => + | let str: String val => str.clone() else return "initializeParams.locale must be of type string" @@ -64,7 +64,7 @@ primitive ParseInitializeParams let rootPath': (String | None) = try match obj("rootPath")? - | let str: String => + | let str: String val => str.clone() | json.Null => None @@ -75,7 +75,7 @@ primitive ParseInitializeParams let rootUri': (String | None) = try match obj("rootUri")? - | let str: String => + | let str: String val => str.clone() | json.Null => None @@ -87,7 +87,7 @@ primitive ParseInitializeParams end let initializationOptions': (json.Item val | None) = try - json.Clone(obj("initializationOptions")?) + recover val json.Clone(obj("initializationOptions")?) end end let capabilities' = try @@ -96,7 +96,7 @@ primitive ParseInitializeParams match c_caps.ParseClientCapabilities(cap_obj) | let client_caps: c_caps.ClientCapabilities => client_caps - | let err: String => + | let err: String val => return err end else @@ -112,7 +112,7 @@ primitive ParseInitializeParams match ParseTraceValue(str) | let tv: TraceValue => tv - | let err: String => + | let err: String val => return err end else @@ -149,7 +149,7 @@ primitive ParseInitializeParams fun val locale(): (String | None) => locale' fun val rootPath(): (String | None) => rootPath' fun val rootUri(): (DocumentUri | None) => rootUri' - fun val initializationOptions(): (json.Item val | None) => + fun val initializationOptions(): (json.Item | None) => initializationOptions' fun val capabilities(): c_caps.ClientCapabilities => capabilities' fun val trace(): (TraceValue | None) => trace' @@ -197,7 +197,7 @@ primitive TraceVerbose type TraceValue is (TraceOff | TraceMessages | TraceVerbose) primitive ParseTraceValue - fun apply(item: json.Item): (TraceValue | String) => + fun apply(item: json.Item val): (TraceValue | String) => match item | "off" => TraceOff diff --git a/eohippus/server/rpc/data/initialize_result.pony b/eohippus/server/rpc/data/initialize_result.pony index d3f41d0..7b8a84e 100644 --- a/eohippus/server/rpc/data/initialize_result.pony +++ b/eohippus/server/rpc/data/initialize_result.pony @@ -7,27 +7,23 @@ interface val InitializeResult is ResultData fun val capabilities(): s_caps.ServerCapabilities fun val serverInfo(): (ServerInfo | None) - fun val get_json(): json.Item val => - recover val - let props = - [ as (String, json.Item): ("capabilities", capabilities().get_json()) ] - match serverInfo() - | let si: ServerInfo => - props.push(("serverInfo", si.get_json())) - end - json.Object(props) + fun val get_json(): json.Item => + let props = + [ as (String, json.Item): ("capabilities", capabilities().get_json()) ] + match serverInfo() + | let si: ServerInfo => + props.push(("serverInfo", si.get_json())) end + json.Object(props) interface val ServerInfo is ResultData fun val name(): String fun val version(): (String | None) - fun val get_json(): json.Item val => - recover val - let props = [ as (String, json.Item): ("name", name()) ] - match version() - | let v: String => - props.push(("version", v)) - end - json.Object(props) + fun val get_json(): json.Item => + let props = [ as (String, json.Item): ("name", name()) ] + match version() + | let v: String => + props.push(("version", v)) end + json.Object(props) diff --git a/eohippus/server/rpc/data/misc_message_stuff.pony b/eohippus/server/rpc/data/misc_message_stuff.pony index 38afc9f..fbde1eb 100644 --- a/eohippus/server/rpc/data/misc_message_stuff.pony +++ b/eohippus/server/rpc/data/misc_message_stuff.pony @@ -11,7 +11,7 @@ interface val Notification is Message fun val params(): NotificationParams interface val NotificationParams - fun val get_json(): json.Item val + fun val get_json(): json.Item interface val RequestMessage is Message fun val id(): (I128 | String val) @@ -129,24 +129,20 @@ interface val Location fun val range(): Range fun val get_json(): json.Item => - recover val - json.Object( - [ as (String, json.Item): - ("uri", uri()) - ("range", range().get_json()) ]) - end + json.Object( + [ as (String, json.Item): + ("uri", uri()) + ("range", range().get_json()) ]) interface val Range fun val start(): Position fun val endd(): Position fun val get_json(): json.Item => - recover val - json.Object( - [ as (String, json.Item): - ("start", start().get_json()) - ("end", endd().get_json()) ]) - end + json.Object( + [ as (String, json.Item): + ("start", start().get_json()) + ("end", endd().get_json()) ]) primitive ParseRange fun apply(obj: json.Object val): (Range | String) => @@ -184,12 +180,10 @@ interface val Position fun val character(): I128 fun val get_json(): json.Item => - recover val - json.Object( - [ as (String, json.Item): - ("line", line()) - ("character", character()) ]) - end + json.Object( + [ as (String, json.Item): + ("line", line()) + ("character", character()) ]) primitive ParsePosition fun apply(obj: json.Object val): (Position | String) => diff --git a/eohippus/server/rpc/data/publish_diagnostics_params.pony b/eohippus/server/rpc/data/publish_diagnostics_params.pony index 6a10431..35a1290 100644 --- a/eohippus/server/rpc/data/publish_diagnostics_params.pony +++ b/eohippus/server/rpc/data/publish_diagnostics_params.pony @@ -1,3 +1,5 @@ +use "itertools" + use json = "../../../json" interface val PublishDiagnosticsParams is NotificationParams @@ -5,20 +7,19 @@ interface val PublishDiagnosticsParams is NotificationParams fun val version(): (I128 | None) => None fun val diagnostics(): Array[Diagnostic] val - fun val get_json(): json.Item val => - recover val - let props = [ as (String, json.Item): ("uri", uri()) ] - match version() - | let n: I128 => - props.push(("version", n)) - end - let diag_items = Array[json.Item val] - for diag in diagnostics().values() do - diag_items.push(diag.get_json()) - end - props.push(("diagnostics", json.Sequence(diag_items))) - json.Object(props) + fun val get_json(): json.Item => + let props = [ as (String, json.Item): ("uri", uri()) ] + match version() + | let n: I128 => + props.push(("version", n)) end + props.push( + ( "diagnostics" + , recover val + json.Sequence.from_iter[Diagnostic]( + diagnostics().values(), { (diag) => diag.get_json() }) + end )) + json.Object(props) primitive DiagnosticError fun apply(): I128 => 1 @@ -50,13 +51,11 @@ interface val DiagnosticRelatedInformation fun val location(): Location fun val message(): String - fun val get_json(): json.Item val => - recover val - json.Object( - [ as (String, json.Item): - ("location", location().get_json()) - ("message", message()) ]) - end + fun val get_json(): json.Item => + json.Object( + [ as (String, json.Item): + ("location", location().get_json()) + ("message", message()) ]) interface val Diagnostic fun val range(): Range @@ -70,55 +69,51 @@ interface val Diagnostic : (Array[DiagnosticRelatedInformation] val | None) => None - fun val data(): (json.Item val | None) => None - - fun val get_json(): json.Item val => - recover val - let props = [ as (String, json.Item): ("range", range().get_json()) ] - match severity() - | let s: DiagnosticSeverity => - props.push(("severity", s())) - end - match code() - | let item: (I128 | String) => - props.push(("code", item)) - end - match codeDescription() - | let cd: CodeDescription => - props.push(("codeDescription", cd.get_json())) - end - match source() - | let str: String => - props.push(("source", str)) - end - props.push(("message", message())) - match tags() - | let tags_arr: Array[DiagnosticTag] val => - let items = Array[json.Item] - for t in tags_arr.values() do - items.push(t()) - end - props.push(("tags", json.Sequence(items))) - end - match relatedInformation() - | let ri_arr: Array[DiagnosticRelatedInformation] val => - let items = Array[json.Item] - for ri in ri_arr.values() do - items.push(ri.get_json()) + fun val data(): (json.Item | None) => None + + fun val get_json(): json.Item => + let props = [ as (String, json.Item): ("range", range().get_json()) ] + match severity() + | let s: DiagnosticSeverity => + props.push(("severity", s())) + end + match code() + | let item: (I128 | String) => + props.push(("code", item)) + end + match codeDescription() + | let cd: CodeDescription => + props.push(("codeDescription", cd.get_json())) + end + match source() + | let str: String => + props.push(("source", str)) + end + props.push(("message", message())) + match tags() + | let tags_arr: Array[DiagnosticTag] val => + let seq = + recover val + json.Sequence.from_iter[DiagnosticTag]( + tags_arr.values(), {(t) => t() }) end - props.push(("relatedInformation", json.Sequence(items))) - end - match data() - | let d: json.Item => - props.push(("data", d)) - end - json.Object(props) + props.push(("tags", seq)) + end + match relatedInformation() + | let ri_arr: Array[DiagnosticRelatedInformation] val => + let seq = + json.Sequence.from_iter[DiagnosticRelatedInformation]( + ri_arr.values(), {(ri) => ri.get_json() }) + props.push(("relatedInformation", seq)) end + match data() + | let d: json.Item => + props.push(("data", d)) + end + json.Object(props) interface val CodeDescription fun val href(): String - fun val get_json(): json.Item val => - recover val - json.Object([ as (String, json.Item): ("href", href()) ]) - end + fun val get_json(): json.Item => + json.Object([ as (String, json.Item): ("href", href()) ]) diff --git a/eohippus/server/rpc/data/server_capabilities/notebook_document_sync_options.pony b/eohippus/server/rpc/data/server_capabilities/notebook_document_sync_options.pony index 53b30f5..de6dd63 100644 --- a/eohippus/server/rpc/data/server_capabilities/notebook_document_sync_options.pony +++ b/eohippus/server/rpc/data/server_capabilities/notebook_document_sync_options.pony @@ -1,5 +1,6 @@ -use json = "../../../../json" +use "itertools" +use json = "../../../../json" use ".." interface val NotebookDocumentSyncOptions is SendData @@ -7,17 +8,20 @@ interface val NotebookDocumentSyncOptions is SendData fun val save(): (Bool | None) => None fun val get_json_props(): Array[(String, json.Item)] => - let selector_values = Array[json.Item] - for selector in notebookSelector().values() do - let sv = selector.get_json() - if sv isnt json.Null then - selector_values.push(sv) - end - end - - let props = - [ as (String, json.Item): - ("notebookSelector", json.Sequence(selector_values)) ] + let seq = + json.Sequence( + Iter[NotebookSelectorData](notebookSelector().values()) + .filter_map[json.Item]( + { (selector) => + let sj = selector.get_json() + if sj isnt json.Null then + sj + else + None + end + }) + .collect(Array[json.Item])) + let props = [ as (String, json.Item): ("notebookSelector", seq) ] match save() | let s: Bool => props.push(("save", s)) @@ -29,17 +33,16 @@ interface val NotebookDocumentSyncOptions is SendData interface val NotebookSelectorData is SendData fun val notebook(): (String | NotebookDocumentFilter | None) => None - fun val cells(): (Array[NotebookCell] | None) => None + fun val cells(): (Array[NotebookCell] val | None) => None fun val get_json(): json.Item => let cells_value = match cells() - | let arr: Array[NotebookCell] => - let cell_items = Array[json.Item] - for cell in arr.values() do - cell_items.push(cell.get_json()) + | let arr: Array[NotebookCell] val => + recover val + json.Sequence.from_iter[NotebookCell]( + arr.values(), {(cell) => cell.get_json() }) end - json.Sequence(cell_items) end let props = Array[(String, json.Item)] @@ -50,7 +53,7 @@ interface val NotebookSelectorData is SendData props.push(("notebook", ndf.get_json())) end match cells_value - | let cv: json.Sequence => + | let cv: json.Sequence val => props.push(("cells", cv)) end if props.size() > 0 then diff --git a/eohippus/server/rpc/data/server_capabilities/semantic_tokens_options.pony b/eohippus/server/rpc/data/server_capabilities/semantic_tokens_options.pony index b49fae4..fc7f98a 100644 --- a/eohippus/server/rpc/data/server_capabilities/semantic_tokens_options.pony +++ b/eohippus/server/rpc/data/server_capabilities/semantic_tokens_options.pony @@ -42,11 +42,10 @@ interface val SemanticTokensRegistrationOptions is end match documentSelector() | let ds: DocumentSelector => - let items = Array[json.Item] - for filter in ds.values() do - items.push(filter.get_json()) - end - props.push(("documentSelector", json.Sequence(items))) + let seq = + json.Sequence.from_iter[DocumentFilter]( + ds.values(), {(filter) => filter.get_json() }) + props.push(("documentSelector", seq)) end props.append(get_json_props()) json.Object(props) @@ -58,8 +57,8 @@ interface val SemanticTokensLegend fun val get_json(): json.Item => json.Object( [ as (String, json.Item): - ("tokenTypes", json.Sequence(tokenTypes())) - ("tokenModifiers", json.Sequence(tokenModifiers())) ]) + ("tokenTypes", recover val json.Sequence(tokenTypes()) end) + ("tokenModifiers", recover val json.Sequence(tokenModifiers()) end) ]) interface val SemanticTokensFullOptions fun val delta(): (Bool | None) diff --git a/eohippus/server/rpc/data/server_capabilities/text_document_registration_options.pony b/eohippus/server/rpc/data/server_capabilities/text_document_registration_options.pony index 78e9c42..66cbbc1 100644 --- a/eohippus/server/rpc/data/server_capabilities/text_document_registration_options.pony +++ b/eohippus/server/rpc/data/server_capabilities/text_document_registration_options.pony @@ -9,10 +9,11 @@ interface val TextDocumentRegistrationOptions is SendData let props = Array[(String, json.Item)] match documentSelector() | let ds: DocumentSelector => - let items = Array[json.Item] - for filter in ds.values() do - items.push(filter.get_json()) - end - props.push(("documentSelector", json.Sequence(items))) + let seq = + recover val + json.Sequence.from_iter[DocumentFilter]( + ds.values(), {(filter) => filter.get_json() }) + end + props.push(("documentSelector", seq)) end - json.Object(props) + json.Object(consume props) diff --git a/eohippus/server/rpc/handler.pony b/eohippus/server/rpc/handler.pony index 8d124ca..0f5d439 100644 --- a/eohippus/server/rpc/handler.pony +++ b/eohippus/server/rpc/handler.pony @@ -57,7 +57,7 @@ actor EohippusHandler is Handler let _log: Logger[String] let _server: Server let _channel: Channel - let _json_parser: json.Parser + let _json_parser: json.Parser iso var _state: _HandlerState var _current_header_name: String ref @@ -514,7 +514,7 @@ actor EohippusHandler is Handler _state = _NotConnected _server.rpc_closed() - fun ref _write_message(obj: json.Object) => + fun ref _write_message(obj: json.Object box) => let body = recover val obj.get_string(false) end let message: String trn = String message.append("Content-Length:") diff --git a/eohippus/test/_test_ast_parse_node.pony b/eohippus/test/_test_ast_parse_node.pony index 4640418..da66e35 100644 --- a/eohippus/test/_test_ast_parse_node.pony +++ b/eohippus/test/_test_ast_parse_node.pony @@ -35,7 +35,7 @@ class iso _TestAstParseNodeAnnotation is UnitTest } """ match json.Parse(src) - | let obj: json.Object => + | let obj: json.Object val => match ast.ParseNode(name(), obj) | let ann: ast.NodeWith[ast.Annotation] => h.assert_is[(USize | None)](4, ann.src_info().line, "line") diff --git a/eohippus/test/_test_json.pony b/eohippus/test/_test_json.pony index 9dedebc..23d611c 100644 --- a/eohippus/test/_test_json.pony +++ b/eohippus/test/_test_json.pony @@ -132,6 +132,7 @@ class iso _TestJsonSubsumes is UnitTest let exp5 = json.Object( [ as (String, json.Item): - ("foo", json.Sequence([ as json.Item: I128(1); I128(2) ])) ]) + ( "foo" + , recover val json.Sequence([ as json.Item: I128(1); I128(2) ]) end) ]) let source5 = """{"foo":[1,2]}""" _test(h, source5, exp5) diff --git a/eohippus/test/lsp/test_stream.pony b/eohippus/test/lsp/test_stream.pony index d65e1a7..add84d5 100644 --- a/eohippus/test/lsp/test_stream.pony +++ b/eohippus/test/lsp/test_stream.pony @@ -22,9 +22,9 @@ actor TestInputStream is InputStream if not _valid then return end match _notify | let notify: InputNotify iso => - match data - | let str: String => - notify(str.clone().iso_array()) + match consume data + | let str: String iso => + notify((consume str).iso_array()) | let arr: Array[U8] iso => notify(consume arr) end