jade-lang 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +23 -0
- data/LICENSE +21 -0
- data/README.md +386 -0
- data/exe/jade +6 -0
- data/lib/jade/ast/node.rb +44 -0
- data/lib/jade/ast/nodes.rb +35 -0
- data/lib/jade/ast/pretty_printer.rb +50 -0
- data/lib/jade/ast.rb +723 -0
- data/lib/jade/calendar/runtime.rb +15 -0
- data/lib/jade/cli/fmt.rb +96 -0
- data/lib/jade/cli/lsp.rb +13 -0
- data/lib/jade/cli/q.rb +113 -0
- data/lib/jade/cli.rb +43 -0
- data/lib/jade/clock/runtime.rb +13 -0
- data/lib/jade/codegen/boundary/cache.rb +94 -0
- data/lib/jade/codegen/boundary/specialized/list.rb +65 -0
- data/lib/jade/codegen/boundary/specialized/maybe.rb +40 -0
- data/lib/jade/codegen/boundary/specialized/record.rb +165 -0
- data/lib/jade/codegen/boundary/specialized/scalar.rb +67 -0
- data/lib/jade/codegen/boundary/specialized.rb +106 -0
- data/lib/jade/codegen/boundary.rb +189 -0
- data/lib/jade/codegen/constructor_reference.rb +18 -0
- data/lib/jade/codegen/context.rb +96 -0
- data/lib/jade/codegen/emitter.rb +81 -0
- data/lib/jade/codegen/function_call.rb +367 -0
- data/lib/jade/codegen/function_declaration.rb +199 -0
- data/lib/jade/codegen/helpers.rb +103 -0
- data/lib/jade/codegen/implementation.rb +178 -0
- data/lib/jade/codegen/inline.rb +89 -0
- data/lib/jade/codegen/inlines.rb +326 -0
- data/lib/jade/codegen/method_names.rb +54 -0
- data/lib/jade/codegen/pattern/constructor.rb +57 -0
- data/lib/jade/codegen/port_decoder.rb +77 -0
- data/lib/jade/codegen/pretty.rb +53 -0
- data/lib/jade/codegen/transforms/fold_shape.rb +222 -0
- data/lib/jade/codegen/transforms/self_call.rb +80 -0
- data/lib/jade/codegen/transforms/tail_call.rb +120 -0
- data/lib/jade/codegen/variant_declaration.rb +41 -0
- data/lib/jade/codegen.rb +400 -0
- data/lib/jade/compiler.rb +69 -0
- data/lib/jade/decode.rb +320 -0
- data/lib/jade/diagnostics/renderer.rb +121 -0
- data/lib/jade/diagnostics.rb +77 -0
- data/lib/jade/did_you_mean.rb +16 -0
- data/lib/jade/entry.rb +177 -0
- data/lib/jade/error.rb +72 -0
- data/lib/jade/formatter/accesses.rb +37 -0
- data/lib/jade/formatter/bindings.rb +29 -0
- data/lib/jade/formatter/body.rb +50 -0
- data/lib/jade/formatter/calls.rb +51 -0
- data/lib/jade/formatter/case_of.rb +31 -0
- data/lib/jade/formatter/case_of_branch.rb +59 -0
- data/lib/jade/formatter/collections.rb +78 -0
- data/lib/jade/formatter/declarations.rb +178 -0
- data/lib/jade/formatter/exposing.rb +48 -0
- data/lib/jade/formatter/function_declaration.rb +72 -0
- data/lib/jade/formatter/helper.rb +122 -0
- data/lib/jade/formatter/if_then_else.rb +64 -0
- data/lib/jade/formatter/infix_application.rb +69 -0
- data/lib/jade/formatter/lambda.rb +50 -0
- data/lib/jade/formatter/leaves.rb +111 -0
- data/lib/jade/formatter/module_node.rb +26 -0
- data/lib/jade/formatter/pattern.rb +61 -0
- data/lib/jade/formatter/type.rb +67 -0
- data/lib/jade/formatter.rb +38 -0
- data/lib/jade/frontend/comment_attacher.rb +121 -0
- data/lib/jade/frontend/desugaring/placeholder.rb +39 -0
- data/lib/jade/frontend/desugaring/resolved.rb +63 -0
- data/lib/jade/frontend/desugaring.rb +217 -0
- data/lib/jade/frontend/fixity_fixer.rb +209 -0
- data/lib/jade/frontend/forward_declaration/body.rb +30 -0
- data/lib/jade/frontend/forward_declaration/error/bad_import.rb +19 -0
- data/lib/jade/frontend/forward_declaration/error/exposed_type_not_found.rb +18 -0
- data/lib/jade/frontend/forward_declaration/error/exposed_value_not_found.rb +18 -0
- data/lib/jade/frontend/forward_declaration/error/module_not_found.rb +18 -0
- data/lib/jade/frontend/forward_declaration/error/private_type_expansion.rb +19 -0
- data/lib/jade/frontend/forward_declaration/error/tuple_arity_overflow.rb +25 -0
- data/lib/jade/frontend/forward_declaration/error/type_not_found.rb +29 -0
- data/lib/jade/frontend/forward_declaration/error/type_not_lowerable.rb +16 -0
- data/lib/jade/frontend/forward_declaration/error/unknown_extends_interface.rb +18 -0
- data/lib/jade/frontend/forward_declaration/error.rb +11 -0
- data/lib/jade/frontend/forward_declaration/function_declaration.rb +32 -0
- data/lib/jade/frontend/forward_declaration/helper.rb +91 -0
- data/lib/jade/frontend/forward_declaration/implementation.rb +63 -0
- data/lib/jade/frontend/forward_declaration/implementation_function.rb +39 -0
- data/lib/jade/frontend/forward_declaration/import_declaration.rb +115 -0
- data/lib/jade/frontend/forward_declaration/interface_declaration.rb +66 -0
- data/lib/jade/frontend/forward_declaration/interop_import_declaration.rb +99 -0
- data/lib/jade/frontend/forward_declaration/module.rb +98 -0
- data/lib/jade/frontend/forward_declaration/struct_declaration.rb +42 -0
- data/lib/jade/frontend/forward_declaration/type_declaration.rb +42 -0
- data/lib/jade/frontend/forward_declaration.rb +71 -0
- data/lib/jade/frontend/pattern_analysis/exhaustiveness.rb +65 -0
- data/lib/jade/frontend/pattern_analysis/matrix.rb +235 -0
- data/lib/jade/frontend/pattern_analysis.rb +40 -0
- data/lib/jade/frontend/semantic_analysis/assign.rb +20 -0
- data/lib/jade/frontend/semantic_analysis/body.rb +33 -0
- data/lib/jade/frontend/semantic_analysis/case_of.rb +19 -0
- data/lib/jade/frontend/semantic_analysis/case_of_branch.rb +20 -0
- data/lib/jade/frontend/semantic_analysis/char_literal.rb +14 -0
- data/lib/jade/frontend/semantic_analysis/constructor_reference.rb +64 -0
- data/lib/jade/frontend/semantic_analysis/error/circular_extends.rb +19 -0
- data/lib/jade/frontend/semantic_analysis/error/constant_not_callable.rb +24 -0
- data/lib/jade/frontend/semantic_analysis/error/constructor_not_found.rb +34 -0
- data/lib/jade/frontend/semantic_analysis/error/constructor_pattern_arity_mismatch.rb +24 -0
- data/lib/jade/frontend/semantic_analysis/error/duplicate_field.rb +18 -0
- data/lib/jade/frontend/semantic_analysis/error/duplicate_function_declaration.rb +25 -0
- data/lib/jade/frontend/semantic_analysis/error/duplicate_record_field.rb +19 -0
- data/lib/jade/frontend/semantic_analysis/error/invalid_list_rest_pattern.rb +21 -0
- data/lib/jade/frontend/semantic_analysis/error/kwargs_on_non_constructor.rb +17 -0
- data/lib/jade/frontend/semantic_analysis/error/missing_exposing_clause.rb +17 -0
- data/lib/jade/frontend/semantic_analysis/error/missing_extends_implementation.rb +21 -0
- data/lib/jade/frontend/semantic_analysis/error/missing_field.rb +20 -0
- data/lib/jade/frontend/semantic_analysis/error/missing_implementation_function.rb +19 -0
- data/lib/jade/frontend/semantic_analysis/error/module_not_found.rb +22 -0
- data/lib/jade/frontend/semantic_analysis/error/nested_task_port.rb +19 -0
- data/lib/jade/frontend/semantic_analysis/error/non_task_port.rb +22 -0
- data/lib/jade/frontend/semantic_analysis/error/orphan_implementation.rb +20 -0
- data/lib/jade/frontend/semantic_analysis/error/predicate_must_return_bool.rb +22 -0
- data/lib/jade/frontend/semantic_analysis/error/predicate_name_not_allowed.rb +25 -0
- data/lib/jade/frontend/semantic_analysis/error/shadowing_error.rb +22 -0
- data/lib/jade/frontend/semantic_analysis/error/type_args_mismatch.rb +25 -0
- data/lib/jade/frontend/semantic_analysis/error/type_param_required.rb +19 -0
- data/lib/jade/frontend/semantic_analysis/error/unbound_type_variable.rb +22 -0
- data/lib/jade/frontend/semantic_analysis/error/undefined_variable.rb +29 -0
- data/lib/jade/frontend/semantic_analysis/error/unknown_field.rb +20 -0
- data/lib/jade/frontend/semantic_analysis/error/unknown_implementation_function.rb +19 -0
- data/lib/jade/frontend/semantic_analysis/error/unused_interface_type_param.rb +24 -0
- data/lib/jade/frontend/semantic_analysis/error/value_not_exposed.rb +23 -0
- data/lib/jade/frontend/semantic_analysis/error/variable_not_found.rb +25 -0
- data/lib/jade/frontend/semantic_analysis/error.rb +40 -0
- data/lib/jade/frontend/semantic_analysis/function_call.rb +60 -0
- data/lib/jade/frontend/semantic_analysis/function_declaration.rb +58 -0
- data/lib/jade/frontend/semantic_analysis/grouping.rb +17 -0
- data/lib/jade/frontend/semantic_analysis/helper.rb +152 -0
- data/lib/jade/frontend/semantic_analysis/if_then_else.rb +20 -0
- data/lib/jade/frontend/semantic_analysis/implementation.rb +143 -0
- data/lib/jade/frontend/semantic_analysis/implementation_function.rb +16 -0
- data/lib/jade/frontend/semantic_analysis/import_declaration.rb +14 -0
- data/lib/jade/frontend/semantic_analysis/interface_declaration.rb +45 -0
- data/lib/jade/frontend/semantic_analysis/interop_import_declaration.rb +69 -0
- data/lib/jade/frontend/semantic_analysis/keyed_call/validation.rb +109 -0
- data/lib/jade/frontend/semantic_analysis/keyed_call.rb +88 -0
- data/lib/jade/frontend/semantic_analysis/lambda.rb +23 -0
- data/lib/jade/frontend/semantic_analysis/list.rb +17 -0
- data/lib/jade/frontend/semantic_analysis/literal.rb +23 -0
- data/lib/jade/frontend/semantic_analysis/member_access.rb +87 -0
- data/lib/jade/frontend/semantic_analysis/module_node.rb +27 -0
- data/lib/jade/frontend/semantic_analysis/pattern_binding.rb +27 -0
- data/lib/jade/frontend/semantic_analysis/pattern_constructor.rb +47 -0
- data/lib/jade/frontend/semantic_analysis/pattern_list.rb +33 -0
- data/lib/jade/frontend/semantic_analysis/pattern_literal.rb +17 -0
- data/lib/jade/frontend/semantic_analysis/pattern_record.rb +25 -0
- data/lib/jade/frontend/semantic_analysis/pattern_wildcard.rb +14 -0
- data/lib/jade/frontend/semantic_analysis/qualified_access.rb +14 -0
- data/lib/jade/frontend/semantic_analysis/record_access.rb +14 -0
- data/lib/jade/frontend/semantic_analysis/record_field.rb +17 -0
- data/lib/jade/frontend/semantic_analysis/record_literal.rb +21 -0
- data/lib/jade/frontend/semantic_analysis/record_update.rb +21 -0
- data/lib/jade/frontend/semantic_analysis/struct_declaration.rb +44 -0
- data/lib/jade/frontend/semantic_analysis/tuple.rb +17 -0
- data/lib/jade/frontend/semantic_analysis/type_declaration.rb +69 -0
- data/lib/jade/frontend/semantic_analysis/variable_reference.rb +27 -0
- data/lib/jade/frontend/semantic_analysis/variant_declaration.rb +18 -0
- data/lib/jade/frontend/semantic_analysis.rb +161 -0
- data/lib/jade/frontend/type_checking/canonicalize.rb +97 -0
- data/lib/jade/frontend/type_checking/constraints/deriving/decodable.rb +144 -0
- data/lib/jade/frontend/type_checking/constraints/deriving/encodable.rb +144 -0
- data/lib/jade/frontend/type_checking/constraints/deriving/eq.rb +265 -0
- data/lib/jade/frontend/type_checking/constraints/deriving/helpers.rb +59 -0
- data/lib/jade/frontend/type_checking/constraints/deriving.rb +28 -0
- data/lib/jade/frontend/type_checking/constraints.rb +101 -0
- data/lib/jade/frontend/type_checking/definition.rb +71 -0
- data/lib/jade/frontend/type_checking/env.rb +79 -0
- data/lib/jade/frontend/type_checking/error/case_of_branches_type_mismatch.rb +19 -0
- data/lib/jade/frontend/type_checking/error/derivation_failed.rb +21 -0
- data/lib/jade/frontend/type_checking/error/function_body_type_mismatch.rb +23 -0
- data/lib/jade/frontend/type_checking/error/function_call_type_mismatch.rb +37 -0
- data/lib/jade/frontend/type_checking/error/if_branch_type_mismatch.rb +19 -0
- data/lib/jade/frontend/type_checking/error/if_branches_type_mismatch.rb +18 -0
- data/lib/jade/frontend/type_checking/error/if_condition_type_mismatch.rb +17 -0
- data/lib/jade/frontend/type_checking/error/implementation_type_mismatch.rb +20 -0
- data/lib/jade/frontend/type_checking/error/list_item_type_mismatch.rb +19 -0
- data/lib/jade/frontend/type_checking/error/missing_implementation.rb +20 -0
- data/lib/jade/frontend/type_checking/error/missing_patterns.rb +26 -0
- data/lib/jade/frontend/type_checking/error/pattern_type_mismatch.rb +13 -0
- data/lib/jade/frontend/type_checking/error/port_not_decodable.rb +38 -0
- data/lib/jade/frontend/type_checking/error/record_access_type_mismatch.rb +14 -0
- data/lib/jade/frontend/type_checking/error/type_mismatch.rb +23 -0
- data/lib/jade/frontend/type_checking/error/unresolved_constraint.rb +20 -0
- data/lib/jade/frontend/type_checking/error.rb +18 -0
- data/lib/jade/frontend/type_checking/expected.rb +23 -0
- data/lib/jade/frontend/type_checking/generalization.rb +17 -0
- data/lib/jade/frontend/type_checking/generalizer.rb +38 -0
- data/lib/jade/frontend/type_checking/inference/assign.rb +58 -0
- data/lib/jade/frontend/type_checking/inference/body.rb +45 -0
- data/lib/jade/frontend/type_checking/inference/case_of.rb +102 -0
- data/lib/jade/frontend/type_checking/inference/constructor_reference.rb +21 -0
- data/lib/jade/frontend/type_checking/inference/function_call.rb +132 -0
- data/lib/jade/frontend/type_checking/inference/function_declaration.rb +70 -0
- data/lib/jade/frontend/type_checking/inference/grouping.rb +18 -0
- data/lib/jade/frontend/type_checking/inference/helpers.rb +34 -0
- data/lib/jade/frontend/type_checking/inference/if_then_else.rb +46 -0
- data/lib/jade/frontend/type_checking/inference/implementation.rb +150 -0
- data/lib/jade/frontend/type_checking/inference/import_declaration.rb +19 -0
- data/lib/jade/frontend/type_checking/inference/interface_declaration.rb +18 -0
- data/lib/jade/frontend/type_checking/inference/interop_import_declaration.rb +18 -0
- data/lib/jade/frontend/type_checking/inference/lambda.rb +87 -0
- data/lib/jade/frontend/type_checking/inference/list.rb +52 -0
- data/lib/jade/frontend/type_checking/inference/literal.rb +24 -0
- data/lib/jade/frontend/type_checking/inference/module.rb +18 -0
- data/lib/jade/frontend/type_checking/inference/pattern.rb +135 -0
- data/lib/jade/frontend/type_checking/inference/qualified_access.rb +23 -0
- data/lib/jade/frontend/type_checking/inference/record_access.rb +35 -0
- data/lib/jade/frontend/type_checking/inference/record_field.rb +19 -0
- data/lib/jade/frontend/type_checking/inference/record_literal.rb +24 -0
- data/lib/jade/frontend/type_checking/inference/record_update.rb +37 -0
- data/lib/jade/frontend/type_checking/inference/struct_declaration.rb +18 -0
- data/lib/jade/frontend/type_checking/inference/type_declaration.rb +18 -0
- data/lib/jade/frontend/type_checking/inference/variable_reference.rb +27 -0
- data/lib/jade/frontend/type_checking/inference.rb +27 -0
- data/lib/jade/frontend/type_checking/instantiation.rb +24 -0
- data/lib/jade/frontend/type_checking/loader.rb +80 -0
- data/lib/jade/frontend/type_checking/placeholder.rb +12 -0
- data/lib/jade/frontend/type_checking/port_resolution.rb +123 -0
- data/lib/jade/frontend/type_checking/result.rb +41 -0
- data/lib/jade/frontend/type_checking/scheme.rb +20 -0
- data/lib/jade/frontend/type_checking/state.rb +52 -0
- data/lib/jade/frontend/type_checking/substitution.rb +93 -0
- data/lib/jade/frontend/type_checking/unification.rb +282 -0
- data/lib/jade/frontend/type_checking/var_gen.rb +33 -0
- data/lib/jade/frontend/type_checking.rb +129 -0
- data/lib/jade/frontend/unused_analysis.rb +41 -0
- data/lib/jade/frontend/usage_analysis/reference_index.rb +53 -0
- data/lib/jade/frontend/usage_analysis.rb +195 -0
- data/lib/jade/frontend.rb +101 -0
- data/lib/jade/interop/boundary.rb +68 -0
- data/lib/jade/interop/error.rb +84 -0
- data/lib/jade/interop/lowering/error.rb +32 -0
- data/lib/jade/interop/lowering.rb +53 -0
- data/lib/jade/interop/runtime.rb +24 -0
- data/lib/jade/interop.rb +1 -0
- data/lib/jade/lexer.rb +189 -0
- data/lib/jade/lsp/converters.rb +542 -0
- data/lib/jade/lsp/handlers.rb +340 -0
- data/lib/jade/lsp/server.rb +63 -0
- data/lib/jade/lsp/snippets.rb +100 -0
- data/lib/jade/lsp/state.rb +25 -0
- data/lib/jade/lsp.rb +16 -0
- data/lib/jade/module_loader/cache.rb +56 -0
- data/lib/jade/module_loader/dependency_graph.rb +23 -0
- data/lib/jade/module_loader/dependency_resolver.rb +48 -0
- data/lib/jade/module_loader/normalize.rb +34 -0
- data/lib/jade/module_loader/topological_sort.rb +41 -0
- data/lib/jade/module_loader.rb +127 -0
- data/lib/jade/parsing/combinators.rb +291 -0
- data/lib/jade/parsing/error.rb +154 -0
- data/lib/jade/parsing/token.rb +12 -0
- data/lib/jade/parsing/type.rb +92 -0
- data/lib/jade/parsing.rb +674 -0
- data/lib/jade/port.rb +1 -0
- data/lib/jade/registry.rb +79 -0
- data/lib/jade/result.rb +121 -0
- data/lib/jade/runtime.rb +127 -0
- data/lib/jade/source.rb +62 -0
- data/lib/jade/stdlib/basics.rb +214 -0
- data/lib/jade/stdlib/bytes.rb +70 -0
- data/lib/jade/stdlib/calendar.rb +405 -0
- data/lib/jade/stdlib/char.rb +27 -0
- data/lib/jade/stdlib/clock.rb +342 -0
- data/lib/jade/stdlib/compiled.rb +48 -0
- data/lib/jade/stdlib/decode/params.rb +154 -0
- data/lib/jade/stdlib/decode.rb +315 -0
- data/lib/jade/stdlib/dict.rb +134 -0
- data/lib/jade/stdlib/encode.rb +143 -0
- data/lib/jade/stdlib/intrinsics.rb +280 -0
- data/lib/jade/stdlib/list.rb +214 -0
- data/lib/jade/stdlib/maybe.rb +73 -0
- data/lib/jade/stdlib/result.rb +131 -0
- data/lib/jade/stdlib/set.rb +123 -0
- data/lib/jade/stdlib/string.rb +65 -0
- data/lib/jade/stdlib/task.rb +55 -0
- data/lib/jade/stdlib/tuple.rb +21 -0
- data/lib/jade/stdlib.rb +112 -0
- data/lib/jade/symbol/anonymous_record.rb +7 -0
- data/lib/jade/symbol/base.rb +15 -0
- data/lib/jade/symbol/constructor.rb +11 -0
- data/lib/jade/symbol/derived_function.rb +5 -0
- data/lib/jade/symbol/function.rb +15 -0
- data/lib/jade/symbol/function_type.rb +7 -0
- data/lib/jade/symbol/implementation.rb +17 -0
- data/lib/jade/symbol/implementation_template.rb +13 -0
- data/lib/jade/symbol/interface.rb +11 -0
- data/lib/jade/symbol/interface_function.rb +18 -0
- data/lib/jade/symbol/interop_function.rb +22 -0
- data/lib/jade/symbol/lambda.rb +7 -0
- data/lib/jade/symbol/parser.rb +79 -0
- data/lib/jade/symbol/partial_application.rb +7 -0
- data/lib/jade/symbol/record_type.rb +8 -0
- data/lib/jade/symbol/stdlib_function.rb +15 -0
- data/lib/jade/symbol/stdlib_implementation.rb +7 -0
- data/lib/jade/symbol/struct.rb +15 -0
- data/lib/jade/symbol/type_application.rb +8 -0
- data/lib/jade/symbol/type_ref.rb +11 -0
- data/lib/jade/symbol/union.rb +15 -0
- data/lib/jade/symbol/value_ref.rb +15 -0
- data/lib/jade/symbol/variable.rb +7 -0
- data/lib/jade/symbol/variant.rb +11 -0
- data/lib/jade/symbol.rb +162 -0
- data/lib/jade/task.rb +103 -0
- data/lib/jade/tasks/rspec.rb +266 -0
- data/lib/jade/tasks.rb +70 -0
- data/lib/jade/type/anonymous_record.rb +33 -0
- data/lib/jade/type/application.rb +21 -0
- data/lib/jade/type/base.rb +9 -0
- data/lib/jade/type/constraint.rb +17 -0
- data/lib/jade/type/constructor.rb +19 -0
- data/lib/jade/type/function.rb +18 -0
- data/lib/jade/type/partial_application.rb +17 -0
- data/lib/jade/type/unit.rb +15 -0
- data/lib/jade/type/var.rb +21 -0
- data/lib/jade/type.rb +259 -0
- data/lib/jade/version.rb +3 -0
- data/lib/jade.rb +55 -0
- metadata +387 -0
data/lib/jade/parsing.rb
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
require 'jade/result'
|
|
2
|
+
|
|
3
|
+
require 'jade/parsing/combinators'
|
|
4
|
+
require 'jade/parsing/error'
|
|
5
|
+
require 'jade/parsing/token'
|
|
6
|
+
require 'jade/parsing/type'
|
|
7
|
+
|
|
8
|
+
module Jade
|
|
9
|
+
module Parsing
|
|
10
|
+
extend self
|
|
11
|
+
include Combinators
|
|
12
|
+
include Token
|
|
13
|
+
include Type
|
|
14
|
+
extend Combinators::Dsl
|
|
15
|
+
|
|
16
|
+
FunctionCallPostfix = Data.define(:lparen, :args, :rparen) do
|
|
17
|
+
def apply(node)
|
|
18
|
+
AST.function_call.call(node, lparen, args, rparen)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
KeyedCallPostfix = Data.define(:lparen, :fields, :rparen) do
|
|
23
|
+
def apply(node)
|
|
24
|
+
AST.keyed_call.call(node, lparen, fields, rparen)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
MemberAccessPostfix = Data.define(:dot, :identifier) do
|
|
29
|
+
def apply(node)
|
|
30
|
+
AST.member_access.call(node, dot, identifier)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Tokens that start a top-level declaration. The recovering parser skips
|
|
35
|
+
# to one of these (or EOF) when it can't make progress in tolerant mode.
|
|
36
|
+
TOP_LEVEL_SYNC = %i[def type struct import uses implements interface module].freeze
|
|
37
|
+
|
|
38
|
+
def parse(tokens, source:, parser: program, tolerant: false)
|
|
39
|
+
comments = tokens.select { it.type == :comment }
|
|
40
|
+
state = State.new(
|
|
41
|
+
tokens: tokens.reject { it.type == :comment },
|
|
42
|
+
entry: source.uri,
|
|
43
|
+
tolerant:,
|
|
44
|
+
source:,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
result = parser.call(state)
|
|
48
|
+
|
|
49
|
+
if tolerant
|
|
50
|
+
# Tolerant mode: always Ok. Returns (ast, comments, diagnostics).
|
|
51
|
+
case result
|
|
52
|
+
in Ok([ast, end_state])
|
|
53
|
+
Ok[[ast, comments, end_state.diagnostics]]
|
|
54
|
+
|
|
55
|
+
in Err([err, err_state])
|
|
56
|
+
diagnostics = err_state.diagnostics.add(error_to_diagnostic(err))
|
|
57
|
+
Ok[[nil, comments, diagnostics]]
|
|
58
|
+
end
|
|
59
|
+
else
|
|
60
|
+
result
|
|
61
|
+
.and_then { |(ast, end_state)|
|
|
62
|
+
end_state.eof? ?
|
|
63
|
+
Ok[[ast, end_state]] :
|
|
64
|
+
end_state.current.then { |tok|
|
|
65
|
+
Err[[
|
|
66
|
+
UnexpectedTokenError.new(
|
|
67
|
+
entry: end_state.entry,
|
|
68
|
+
span: tok.range,
|
|
69
|
+
actual: tok,
|
|
70
|
+
expected: "end of input",
|
|
71
|
+
),
|
|
72
|
+
end_state,
|
|
73
|
+
]]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
.map { [it.first, comments] }
|
|
77
|
+
.map_error(&:first)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
parser(:module_) {
|
|
82
|
+
(
|
|
83
|
+
type(:module).skip >>
|
|
84
|
+
(
|
|
85
|
+
module_name >>
|
|
86
|
+
exposing >>
|
|
87
|
+
program_body
|
|
88
|
+
).commit
|
|
89
|
+
).map(&AST.module_)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
parser(:program) { module_ | program_body }
|
|
93
|
+
|
|
94
|
+
parser(:program_body) {
|
|
95
|
+
(declaration | statement).then { |item|
|
|
96
|
+
P.new do |state|
|
|
97
|
+
(
|
|
98
|
+
state.tolerant ?
|
|
99
|
+
recovering_sequence(item, sync_types: TOP_LEVEL_SYNC) :
|
|
100
|
+
sequence(item)
|
|
101
|
+
)
|
|
102
|
+
.map(&AST.body)
|
|
103
|
+
.call(state)
|
|
104
|
+
end
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
parser(:statement) { bind | assign | expression }
|
|
109
|
+
|
|
110
|
+
parser(:declaration) {
|
|
111
|
+
function_declaration | type_declaration | import_declaration | interop_import_declaration |
|
|
112
|
+
struct_declaration | implementation | interface_declaration
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
parser(:expression) {
|
|
116
|
+
(
|
|
117
|
+
(case_of | if_then_else | lambda | infix_expression) >>
|
|
118
|
+
optional(ternary_tail, default: [nil, nil])
|
|
119
|
+
).map(&AST.maybe_ternary)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# Right-associative: ternary in `b` extends (`a ? b : c ? d : e` →
|
|
123
|
+
# `a ? b : (c ? d : e)`); ternary in `a` doesn't because that side
|
|
124
|
+
# is parsed by `infix_expression`, which stops before `?`.
|
|
125
|
+
parser(:ternary_tail, private: true) {
|
|
126
|
+
type(:question).skip >>
|
|
127
|
+
(
|
|
128
|
+
lazy { expression } >>
|
|
129
|
+
type(:colon).skip >>
|
|
130
|
+
lazy { expression }
|
|
131
|
+
).commit
|
|
132
|
+
.context("ternary")
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
parser(:tuple) {
|
|
136
|
+
(
|
|
137
|
+
type(:lparen) >>
|
|
138
|
+
lazy { expression } >>
|
|
139
|
+
type(:comma).skip >>
|
|
140
|
+
comma_sequence(lazy { expression }) >>
|
|
141
|
+
type(:rparen)
|
|
142
|
+
).map(&AST.tuple)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
parser(:grouping) {
|
|
146
|
+
(type(:lparen) >> lazy { expression } >> type(:rparen)).map(&AST.grouping)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
parser(:infix_expression) {
|
|
150
|
+
(primary >> many(operator >> primary))
|
|
151
|
+
.map do |(head, *tail)|
|
|
152
|
+
tail.reduce(head) do |left, (op, right)|
|
|
153
|
+
AST.infix_application.call(left, op, right)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
parser(:lambda) {
|
|
159
|
+
(
|
|
160
|
+
(
|
|
161
|
+
(type(:lparen) >>
|
|
162
|
+
(comma_sequence(assignment_pattern) | empty_comma_list) >>
|
|
163
|
+
type(:rparen).skip >>
|
|
164
|
+
type(:arrow).skip) |
|
|
165
|
+
type(:arrow).map { [it, Parsing::Combinators::CommaList.empty] }
|
|
166
|
+
) >>
|
|
167
|
+
type(:lbrace).skip >>
|
|
168
|
+
body >>
|
|
169
|
+
type(:rbrace)
|
|
170
|
+
).map(&AST.lambda)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
parser(:if_then_else) {
|
|
174
|
+
(
|
|
175
|
+
type(:if) >>
|
|
176
|
+
(
|
|
177
|
+
lazy { expression } >>
|
|
178
|
+
type(:then).skip >>
|
|
179
|
+
body >>
|
|
180
|
+
type(:else).skip >>
|
|
181
|
+
body >>
|
|
182
|
+
type(:end)
|
|
183
|
+
).commit
|
|
184
|
+
).map(&AST.if_then_else)
|
|
185
|
+
.context("if/then/else")
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
parser(:case_of) {
|
|
189
|
+
(
|
|
190
|
+
type(:case) >>
|
|
191
|
+
(
|
|
192
|
+
lazy { expression } >>
|
|
193
|
+
many(case_of_branch).map { [it] } >>
|
|
194
|
+
optional(case_else_branch, default: nil) >>
|
|
195
|
+
type(:end)
|
|
196
|
+
).commit
|
|
197
|
+
).map(&AST.case_of)
|
|
198
|
+
.context("case")
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
# `then` is optional before a branch body. The formatter emits it for
|
|
202
|
+
# inline single-expression branches and strips it for multi-statement
|
|
203
|
+
# bodies. The catch — `in <pat> "12"` (body on the same source line
|
|
204
|
+
# as `in`, no `then`) is almost always a forgotten `then`, so we
|
|
205
|
+
# raise a targeted error instead of silently treating it as a body.
|
|
206
|
+
# `else` doesn't get the same check: `else <expr>` is the natural
|
|
207
|
+
# inline form (no `then` keyword on else-branches).
|
|
208
|
+
parser(:case_of_branch) {
|
|
209
|
+
P.new do |state|
|
|
210
|
+
in_tok = state.current
|
|
211
|
+
next type(:in).call(state) unless in_tok&.type == :in
|
|
212
|
+
|
|
213
|
+
pattern.call(state.advance).and_then do |(pat, s)|
|
|
214
|
+
checked_branch_body(in_tok).call(s).map do |(body_node, s2)|
|
|
215
|
+
[AST.case_of_branch.call([in_tok, pat, body_node]), s2]
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
parser(:case_else_branch) {
|
|
222
|
+
P.new do |state|
|
|
223
|
+
else_tok = state.current
|
|
224
|
+
next type(:else).call(state) unless else_tok&.type == :else
|
|
225
|
+
|
|
226
|
+
body_after_optional_then(state.advance).map do |(body_node, s)|
|
|
227
|
+
[AST.case_else_branch.call([else_tok, body_node]), s]
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
def body_after_optional_then(state)
|
|
233
|
+
state.current&.type == :then ? body.call(state.advance) : body.call(state)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def checked_branch_body(in_tok)
|
|
237
|
+
P.new do |state|
|
|
238
|
+
next body.call(state.advance) if state.current&.type == :then
|
|
239
|
+
|
|
240
|
+
next_tok = state.current
|
|
241
|
+
if next_tok && state.same_line?(in_tok.range.begin, next_tok.range.begin)
|
|
242
|
+
next Err[[
|
|
243
|
+
MissingThenError.new(
|
|
244
|
+
entry: state.entry,
|
|
245
|
+
span: next_tok.range,
|
|
246
|
+
actual: next_tok,
|
|
247
|
+
expected: :then,
|
|
248
|
+
committed: true,
|
|
249
|
+
),
|
|
250
|
+
state,
|
|
251
|
+
]]
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
body.call(state)
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
parser(:pattern) {
|
|
259
|
+
wildcard_pattern | list_pattern | literal_pattern | binding_pattern |
|
|
260
|
+
constructor_pattern | tuple_pattern | record_pattern
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
parser(:tuple_pattern) {
|
|
264
|
+
(
|
|
265
|
+
type(:lparen) >>
|
|
266
|
+
lazy { pattern } >>
|
|
267
|
+
type(:comma).skip >>
|
|
268
|
+
comma_sequence(lazy { pattern }) >>
|
|
269
|
+
type(:rparen)
|
|
270
|
+
).map(&AST.tuple_pattern)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
parser(:wildcard_pattern) { type(:wildcard).map(&AST.wildcard_pattern) }
|
|
274
|
+
|
|
275
|
+
parser(:binding_pattern) { identifier.map(&AST.binding_pattern) }
|
|
276
|
+
|
|
277
|
+
parser(:literal_pattern) { literal.map(&AST.literal_pattern) }
|
|
278
|
+
|
|
279
|
+
parser(:constructor_pattern) {
|
|
280
|
+
(constructor_reference >>
|
|
281
|
+
((type(:lparen).skip >>
|
|
282
|
+
(keyed_pattern |
|
|
283
|
+
comma_sequence(lazy { pattern }) |
|
|
284
|
+
empty_comma_list) >>
|
|
285
|
+
type(:rparen)) | empty_comma_list)
|
|
286
|
+
).map(&AST.constructor_pattern)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
parser(:keyed_pattern) {
|
|
290
|
+
fields = sequence(record_field_pattern, separated_by: type(:comma).skip)
|
|
291
|
+
|
|
292
|
+
(fields >> maybe(type(:comma))).map(&AST.keyed_pattern)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
parser(:record_pattern) {
|
|
296
|
+
(
|
|
297
|
+
type(:lbrace) >>
|
|
298
|
+
comma_sequence(record_field_pattern) >>
|
|
299
|
+
type(:rbrace)
|
|
300
|
+
).map(&AST.record_pattern)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
parser(:record_field_pattern) {
|
|
304
|
+
(
|
|
305
|
+
(identifier >> type(:colon) >> lazy { pattern }) |
|
|
306
|
+
(identifier >> type(:colon))
|
|
307
|
+
.map { |identifier, colon| [identifier, colon, AST.binding_pattern.call(identifier)] }
|
|
308
|
+
).map(&AST.record_field_pattern)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
parser(:body) { sequence(lazy { statement }).map(&AST.body) }
|
|
312
|
+
|
|
313
|
+
parser(:operator) {
|
|
314
|
+
type(:plus) | type(:minus) | type(:star) | type(:slash) |
|
|
315
|
+
type(:pipe_forward) | type(:pipe_backward) | type(:eq) | type(:not_eq) |
|
|
316
|
+
type(:lt) | type(:gt) | type(:lte) | type(:gte) | type(:andand) | type(:oror) |
|
|
317
|
+
type(:plusplus)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
parser(:primary) {
|
|
321
|
+
(atom >> many(postfix))
|
|
322
|
+
.map do |(node, *postfixes)|
|
|
323
|
+
postfixes.reduce(node) do |acc, postfix_type|
|
|
324
|
+
postfix_type.apply(acc)
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
parser(:negative_literal) {
|
|
330
|
+
(type(:minus) >> (int | float)).map do |(minus_tok, lit_node)|
|
|
331
|
+
lit_node.with(
|
|
332
|
+
value: -lit_node.value,
|
|
333
|
+
range: minus_tok.range.begin...lit_node.range.end,
|
|
334
|
+
)
|
|
335
|
+
end
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
parser(:atom) {
|
|
339
|
+
variable_reference | negative_literal | literal | constructor_reference |
|
|
340
|
+
lambda | tuple | grouping |
|
|
341
|
+
record_literal | record_update_sugar | record_access_sugar | record_update
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
parser(:postfix) { function_call | member_access }
|
|
345
|
+
|
|
346
|
+
parser(:module_name) {
|
|
347
|
+
sequence(constant, separated_by: type(:dot).skip).map { [it] }
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
parser(:function_call) {
|
|
351
|
+
keyed_call_postfix | positional_call_postfix
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
parser(:positional_call_postfix) {
|
|
355
|
+
(
|
|
356
|
+
type(:lparen) >>
|
|
357
|
+
(comma_sequence(function_call_arg) | empty_comma_list) >>
|
|
358
|
+
type(:rparen)
|
|
359
|
+
).map { FunctionCallPostfix[*it] }
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
parser(:keyed_call_postfix) {
|
|
363
|
+
(
|
|
364
|
+
type(:lparen) >>
|
|
365
|
+
comma_sequence(record_field) >>
|
|
366
|
+
type(:rparen)
|
|
367
|
+
).map { |(lparen, fields, rparen)| KeyedCallPostfix[lparen, fields, rparen] }
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
parser(:function_call_arg) { placeholder | lazy { expression } }
|
|
371
|
+
|
|
372
|
+
parser(:placeholder) { type(:wildcard).map(&AST.placeholder) }
|
|
373
|
+
|
|
374
|
+
parser(:member_access) {
|
|
375
|
+
(type(:dot) >> (variable_reference | constructor_reference))
|
|
376
|
+
.map { MemberAccessPostfix[*it] }
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
parser(:import_declaration) {
|
|
380
|
+
alias_clause = (type(:as).skip >> constant).map(&AST.expose_as)
|
|
381
|
+
|
|
382
|
+
(
|
|
383
|
+
type(:import) >>
|
|
384
|
+
(
|
|
385
|
+
module_name >>
|
|
386
|
+
optional(alias_clause, default: [nil]) >>
|
|
387
|
+
optional(exposing, default: [[]])
|
|
388
|
+
).commit
|
|
389
|
+
).map(&AST.import_declaration)
|
|
390
|
+
.context("import declaration")
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
parser(:exposing) {
|
|
394
|
+
(type(:exposing).skip >>
|
|
395
|
+
type(:lparen).skip >>
|
|
396
|
+
(expose_list | expose_all) >>
|
|
397
|
+
type(:rparen).skip
|
|
398
|
+
) | expose_none
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
parser(:expose_none) { none.map(&AST.expose_none) }
|
|
402
|
+
|
|
403
|
+
parser(:expose_all) { type(:dotdot).map(&AST.expose_all) }
|
|
404
|
+
|
|
405
|
+
parser(:expose_list) { comma_sequence(expose_item).map(&AST.expose_list) }
|
|
406
|
+
|
|
407
|
+
parser(:expose_item) { expose_value | expose_type_expand | expose_type }
|
|
408
|
+
|
|
409
|
+
parser(:expose_value) { identifier.map(&AST.expose_value) }
|
|
410
|
+
|
|
411
|
+
parser(:expose_type_expand) {
|
|
412
|
+
(constant >> type(:lparen) >> type(:dotdot) >> type(:rparen))
|
|
413
|
+
.map(&AST.expose_type_expand)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
parser(:expose_type) { constant.map(&AST.expose_type) }
|
|
417
|
+
|
|
418
|
+
parser(:function_declaration) {
|
|
419
|
+
(
|
|
420
|
+
type(:def) >>
|
|
421
|
+
(
|
|
422
|
+
identifier >>
|
|
423
|
+
(
|
|
424
|
+
(type(:lparen).skip >>
|
|
425
|
+
(
|
|
426
|
+
type(:rparen).skip.map { Combinators::CommaList.empty } |
|
|
427
|
+
(comma_sequence(param) >> type(:rparen).skip).commit
|
|
428
|
+
)) |
|
|
429
|
+
empty_comma_list
|
|
430
|
+
) >>
|
|
431
|
+
type(:arrow).skip >>
|
|
432
|
+
type_expression >>
|
|
433
|
+
sequence(statement).map(&AST.body) >>
|
|
434
|
+
type(:end)
|
|
435
|
+
).commit
|
|
436
|
+
).map(&AST.function_declaration)
|
|
437
|
+
.context("function declaration")
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
parser(:type_declaration) {
|
|
441
|
+
(
|
|
442
|
+
type(:type) >>
|
|
443
|
+
(
|
|
444
|
+
constant >>
|
|
445
|
+
(type_params | empty_comma_list) >>
|
|
446
|
+
type(:assign).skip >>
|
|
447
|
+
sequence(variant_declaration, separated_by: type(:pipe).skip).map { [it] }
|
|
448
|
+
).commit
|
|
449
|
+
).map(&AST.type_declaration)
|
|
450
|
+
.context("type declaration")
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
parser(:record_declaration) {
|
|
454
|
+
(
|
|
455
|
+
type(:data) >>
|
|
456
|
+
constant >>
|
|
457
|
+
(type_params | empty_comma_list) >>
|
|
458
|
+
type(:assign).skip >>
|
|
459
|
+
type_record
|
|
460
|
+
).map(&AST.record_declaration)
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
parser(:variant_declaration) {
|
|
464
|
+
(
|
|
465
|
+
constant >>
|
|
466
|
+
(keyed_variant | type_expressions | empty_comma_list)
|
|
467
|
+
).map(&AST.variant_declaration)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
parser(:keyed_variant) {
|
|
471
|
+
(
|
|
472
|
+
type(:lparen) >>
|
|
473
|
+
type_record_fields >>
|
|
474
|
+
type(:rparen)
|
|
475
|
+
).map(&AST.keyed_variant)
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
parser(:literal) { string | char | int | bool | float | list }
|
|
479
|
+
|
|
480
|
+
parser(:list_pattern) {
|
|
481
|
+
(
|
|
482
|
+
type(:lbrack) >>
|
|
483
|
+
(
|
|
484
|
+
(
|
|
485
|
+
comma_sequence(lazy { pattern }) >>
|
|
486
|
+
(type(:pipe).skip >> lazy { pattern } | none)
|
|
487
|
+
) | (empty_comma_list >> none)
|
|
488
|
+
).map { [it] } >>
|
|
489
|
+
type(:rbrack)
|
|
490
|
+
).map(&AST.list_pattern)
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
parser(:list) {
|
|
494
|
+
(type(:lbrack) >>
|
|
495
|
+
(comma_sequence(lazy { expression }) | empty_comma_list) >>
|
|
496
|
+
type(:rbrack)
|
|
497
|
+
).map(&AST.list)
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
# Should refactor to just an Identifier node
|
|
501
|
+
parser(:variable_reference) { identifier.map(&AST.variable_reference) }
|
|
502
|
+
|
|
503
|
+
# Should refactor to just an Constant node
|
|
504
|
+
parser(:constructor_reference) { constant.map(&AST.constructor_reference) }
|
|
505
|
+
|
|
506
|
+
parser(:param) {
|
|
507
|
+
(
|
|
508
|
+
identifier >> type(:colon).skip >> type_expression
|
|
509
|
+
).map(&AST.function_declaration_param)
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
parser(:bind) {
|
|
513
|
+
(
|
|
514
|
+
assignment_pattern >>
|
|
515
|
+
type(:bind) >>
|
|
516
|
+
expression.commit
|
|
517
|
+
).map(&AST.bind)
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
parser(:assign) {
|
|
521
|
+
(
|
|
522
|
+
assignment_pattern >>
|
|
523
|
+
type(:assign) >>
|
|
524
|
+
expression.commit
|
|
525
|
+
).map(&AST.assign)
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
parser(:assignment_pattern) {
|
|
529
|
+
wildcard_pattern | constructor_pattern | tuple_pattern | record_pattern |
|
|
530
|
+
list_pattern | binding_pattern
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
# Records
|
|
534
|
+
parser(:record_literal) {
|
|
535
|
+
(type(:lbrace) >> record_fields >> type(:rbrace)).map(&AST.record_literal)
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
parser(:record_fields) { comma_sequence(record_field) }
|
|
539
|
+
|
|
540
|
+
parser(:record_field) {
|
|
541
|
+
(identifier >> type(:colon).skip >> lazy { expression }).map(&AST.record_field)
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
parser(:record_access_sugar) {
|
|
545
|
+
(type(:dot) >> type(:identifier)).map(&AST.record_access_sugar)
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
parser(:record_update) {
|
|
549
|
+
(type(:lbrace) >> variable_reference >> type(:pipe) >> record_fields >> type(:rbrace))
|
|
550
|
+
.map(&AST.record_update)
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
parser(:record_update_sugar) {
|
|
554
|
+
(type(:dot) >> type(:identifier) >> type(:assign)).map(&AST.record_update_sugar)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
parser(:interop_import_declaration) {
|
|
558
|
+
(
|
|
559
|
+
type(:uses) >>
|
|
560
|
+
(interop_module_name >> type(:with) >> interop_functions >> type(:end))
|
|
561
|
+
.commit
|
|
562
|
+
).map(&AST.interop_import_declaration)
|
|
563
|
+
.context("interop import declaration")
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
parser(:interop_namespace_sep) { type(:coloncolon) }
|
|
567
|
+
|
|
568
|
+
parser(:interop_module_name) {
|
|
569
|
+
at_least_one(constant, separated_by: interop_namespace_sep.skip)
|
|
570
|
+
.map(&AST.interop_module)
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
parser(:interop_functions) {
|
|
574
|
+
fns = at_least_one(interop_function, separated_by: type(:comma).skip)
|
|
575
|
+
|
|
576
|
+
(fns >> maybe(type(:comma))).map { [it] }
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
parser(:interop_function) {
|
|
580
|
+
(identifier >> type(:colon).skip >> type_expression)
|
|
581
|
+
.map(&AST.interop_function)
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
parser(:implementation) {
|
|
585
|
+
extends_list =
|
|
586
|
+
type(:extends).skip >>
|
|
587
|
+
at_least_one(constant, separated_by: type(:comma).skip) >>
|
|
588
|
+
maybe(type(:comma))
|
|
589
|
+
|
|
590
|
+
fns =
|
|
591
|
+
at_least_one(implementation_function, separated_by: type(:comma).skip) >>
|
|
592
|
+
maybe(type(:comma))
|
|
593
|
+
|
|
594
|
+
(
|
|
595
|
+
type(:implements) >>
|
|
596
|
+
(
|
|
597
|
+
type(:constant) >>
|
|
598
|
+
type(:lparen).skip >>
|
|
599
|
+
type_application >>
|
|
600
|
+
type(:rparen).skip >>
|
|
601
|
+
optional(extends_list, default: []).map { [it] } >>
|
|
602
|
+
type(:with).skip >>
|
|
603
|
+
optional(fns, default: []).map { [it] } >>
|
|
604
|
+
type(:end)
|
|
605
|
+
).commit
|
|
606
|
+
).map(&AST.implementation)
|
|
607
|
+
.context("implementation")
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
parser(:interface_declaration) {
|
|
611
|
+
fns =
|
|
612
|
+
at_least_one(interface_function_decl, separated_by: type(:comma).skip) >>
|
|
613
|
+
maybe(type(:comma))
|
|
614
|
+
|
|
615
|
+
(
|
|
616
|
+
type(:interface) >>
|
|
617
|
+
(
|
|
618
|
+
type(:constant) >>
|
|
619
|
+
type(:lparen).skip >>
|
|
620
|
+
type_param >>
|
|
621
|
+
type(:rparen).skip >>
|
|
622
|
+
type(:with).skip >>
|
|
623
|
+
optional(fns, default: []).map { [it] } >>
|
|
624
|
+
type(:end)
|
|
625
|
+
).commit
|
|
626
|
+
).map(&AST.interface_declaration)
|
|
627
|
+
.context("interface declaration")
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
parser(:interface_function_decl) {
|
|
631
|
+
(
|
|
632
|
+
(type(:identifier) | (type(:lparen).skip >> operator >> type(:rparen).skip)) >>
|
|
633
|
+
type(:colon).skip >>
|
|
634
|
+
type_expression
|
|
635
|
+
).map(&AST.interface_function_decl)
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
parser(:implementation_function) {
|
|
639
|
+
(
|
|
640
|
+
(type(:identifier) | (type(:lparen).skip >> operator >> type(:rparen).skip)) >>
|
|
641
|
+
type(:colon).skip >>
|
|
642
|
+
(lambda | variable_reference)
|
|
643
|
+
)
|
|
644
|
+
.map(&AST.implementation_function)
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
parser(:struct_declaration) {
|
|
648
|
+
(
|
|
649
|
+
type(:struct) >>
|
|
650
|
+
(
|
|
651
|
+
constant >>
|
|
652
|
+
(type_params | empty_comma_list) >>
|
|
653
|
+
type(:assign).skip >>
|
|
654
|
+
type_record
|
|
655
|
+
).commit
|
|
656
|
+
).map(&AST.struct_declaration)
|
|
657
|
+
.context("struct declaration")
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
parser(:int) { type(:int).map(&AST.literal) }
|
|
661
|
+
parser(:float) { type(:float).map(&AST.literal) }
|
|
662
|
+
parser(:bool) { type(:bool).map(&AST.literal) }
|
|
663
|
+
parser(:char) { type(:char).map(&AST.char_literal) }
|
|
664
|
+
|
|
665
|
+
parser(:string) {
|
|
666
|
+
(
|
|
667
|
+
type(:quote) >>
|
|
668
|
+
(type(:string_chunk) >> type(:quote))
|
|
669
|
+
.commit
|
|
670
|
+
)
|
|
671
|
+
.map(&AST.string_literal)
|
|
672
|
+
}
|
|
673
|
+
end
|
|
674
|
+
end
|
data/lib/jade/port.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'jade/tasks'
|