yuho 5.0.0__py3-none-any.whl

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.
Files changed (91) hide show
  1. yuho/__init__.py +16 -0
  2. yuho/ast/__init__.py +196 -0
  3. yuho/ast/builder.py +926 -0
  4. yuho/ast/constant_folder.py +280 -0
  5. yuho/ast/dead_code.py +199 -0
  6. yuho/ast/exhaustiveness.py +503 -0
  7. yuho/ast/nodes.py +907 -0
  8. yuho/ast/overlap.py +291 -0
  9. yuho/ast/reachability.py +293 -0
  10. yuho/ast/scope_analysis.py +490 -0
  11. yuho/ast/transformer.py +490 -0
  12. yuho/ast/type_check.py +471 -0
  13. yuho/ast/type_inference.py +425 -0
  14. yuho/ast/visitor.py +239 -0
  15. yuho/cli/__init__.py +14 -0
  16. yuho/cli/commands/__init__.py +1 -0
  17. yuho/cli/commands/api.py +431 -0
  18. yuho/cli/commands/ast_viz.py +334 -0
  19. yuho/cli/commands/check.py +218 -0
  20. yuho/cli/commands/config.py +311 -0
  21. yuho/cli/commands/contribute.py +122 -0
  22. yuho/cli/commands/diff.py +487 -0
  23. yuho/cli/commands/explain.py +240 -0
  24. yuho/cli/commands/fmt.py +253 -0
  25. yuho/cli/commands/generate.py +316 -0
  26. yuho/cli/commands/graph.py +410 -0
  27. yuho/cli/commands/init.py +120 -0
  28. yuho/cli/commands/library.py +656 -0
  29. yuho/cli/commands/lint.py +503 -0
  30. yuho/cli/commands/lsp.py +36 -0
  31. yuho/cli/commands/preview.py +377 -0
  32. yuho/cli/commands/repl.py +444 -0
  33. yuho/cli/commands/serve.py +44 -0
  34. yuho/cli/commands/test.py +528 -0
  35. yuho/cli/commands/transpile.py +121 -0
  36. yuho/cli/commands/wizard.py +370 -0
  37. yuho/cli/completions.py +182 -0
  38. yuho/cli/error_formatter.py +193 -0
  39. yuho/cli/main.py +1064 -0
  40. yuho/config/__init__.py +46 -0
  41. yuho/config/loader.py +235 -0
  42. yuho/config/mask.py +194 -0
  43. yuho/config/schema.py +147 -0
  44. yuho/library/__init__.py +84 -0
  45. yuho/library/index.py +328 -0
  46. yuho/library/install.py +699 -0
  47. yuho/library/lockfile.py +330 -0
  48. yuho/library/package.py +421 -0
  49. yuho/library/resolver.py +791 -0
  50. yuho/library/signature.py +335 -0
  51. yuho/llm/__init__.py +45 -0
  52. yuho/llm/config.py +75 -0
  53. yuho/llm/factory.py +123 -0
  54. yuho/llm/prompts.py +146 -0
  55. yuho/llm/providers.py +383 -0
  56. yuho/llm/utils.py +470 -0
  57. yuho/lsp/__init__.py +14 -0
  58. yuho/lsp/code_action_handler.py +518 -0
  59. yuho/lsp/completion_handler.py +85 -0
  60. yuho/lsp/diagnostics.py +100 -0
  61. yuho/lsp/hover_handler.py +130 -0
  62. yuho/lsp/server.py +1425 -0
  63. yuho/mcp/__init__.py +10 -0
  64. yuho/mcp/server.py +1452 -0
  65. yuho/parser/__init__.py +8 -0
  66. yuho/parser/source_location.py +108 -0
  67. yuho/parser/wrapper.py +311 -0
  68. yuho/testing/__init__.py +48 -0
  69. yuho/testing/coverage.py +274 -0
  70. yuho/testing/fixtures.py +263 -0
  71. yuho/transpile/__init__.py +52 -0
  72. yuho/transpile/alloy_transpiler.py +546 -0
  73. yuho/transpile/base.py +100 -0
  74. yuho/transpile/blocks_transpiler.py +338 -0
  75. yuho/transpile/english_transpiler.py +470 -0
  76. yuho/transpile/graphql_transpiler.py +404 -0
  77. yuho/transpile/json_transpiler.py +217 -0
  78. yuho/transpile/jsonld_transpiler.py +250 -0
  79. yuho/transpile/latex_preamble.py +161 -0
  80. yuho/transpile/latex_transpiler.py +406 -0
  81. yuho/transpile/latex_utils.py +206 -0
  82. yuho/transpile/mermaid_transpiler.py +357 -0
  83. yuho/transpile/registry.py +275 -0
  84. yuho/verify/__init__.py +43 -0
  85. yuho/verify/alloy.py +352 -0
  86. yuho/verify/combined.py +218 -0
  87. yuho/verify/z3_solver.py +1155 -0
  88. yuho-5.0.0.dist-info/METADATA +186 -0
  89. yuho-5.0.0.dist-info/RECORD +91 -0
  90. yuho-5.0.0.dist-info/WHEEL +4 -0
  91. yuho-5.0.0.dist-info/entry_points.txt +2 -0
@@ -0,0 +1,130 @@
1
+ """
2
+ Hover handler for Yuho LSP.
3
+
4
+ Provides hover information for keywords, types, and user-defined symbols.
5
+ """
6
+
7
+ from typing import List, Optional, TYPE_CHECKING, Callable
8
+
9
+ try:
10
+ from lsprotocol import types as lsp
11
+ except ImportError:
12
+ raise ImportError(
13
+ "LSP dependencies not installed. Install with: pip install yuho[lsp]"
14
+ )
15
+
16
+ if TYPE_CHECKING:
17
+ from yuho.lsp.server import DocumentState
18
+ from yuho.ast.nodes import TypeNode
19
+
20
+ # Yuho keywords for hover
21
+ YUHO_KEYWORDS = [
22
+ "struct", "fn", "match", "case", "consequence", "pass", "return",
23
+ "statute", "definitions", "elements", "penalty", "illustration",
24
+ "import", "from", "actus_reus", "mens_rea", "circumstance",
25
+ "imprisonment", "fine", "supplementary", "TRUE", "FALSE",
26
+ ]
27
+
28
+ # Yuho built-in types
29
+ YUHO_TYPES = [
30
+ "int", "float", "bool", "string", "money", "percent", "date", "duration", "void",
31
+ ]
32
+
33
+ KEYWORD_DOCS = {
34
+ "struct": "Defines a structured type with named fields.",
35
+ "fn": "Defines a function.",
36
+ "match": "Pattern matching expression.",
37
+ "case": "Case arm in a match expression.",
38
+ "statute": "Defines a legal statute with elements and penalties.",
39
+ "elements": "Section containing the elements of an offense.",
40
+ "penalty": "Section specifying the punishment for an offense.",
41
+ "actus_reus": "Physical/conduct element of an offense (guilty act).",
42
+ "mens_rea": "Mental element of an offense (guilty mind).",
43
+ "circumstance": "Circumstantial element required for the offense.",
44
+ }
45
+
46
+ TYPE_DOCS = {
47
+ "int": "Integer number type (whole numbers).",
48
+ "float": "Floating-point number type (decimals).",
49
+ "bool": "Boolean type: TRUE or FALSE.",
50
+ "string": "Text string type.",
51
+ "money": "Monetary amount with currency (e.g., $1000.00 SGD).",
52
+ "percent": "Percentage value (0-100%).",
53
+ "date": "Calendar date (YYYY-MM-DD).",
54
+ "duration": "Time duration (years, months, days, etc.).",
55
+ "void": "No value type (for procedures).",
56
+ }
57
+
58
+
59
+ def get_hover(
60
+ doc_state: Optional["DocumentState"],
61
+ word: Optional[str],
62
+ type_to_str: Callable[["TypeNode"], str],
63
+ ) -> Optional[lsp.Hover]:
64
+ """Get hover information for word at position."""
65
+ if not word:
66
+ return None
67
+
68
+ hover_content: List[str] = []
69
+
70
+ # Check if it's a keyword
71
+ if word in YUHO_KEYWORDS:
72
+ hover_content.append(f"**keyword** `{word}`")
73
+ if word in KEYWORD_DOCS:
74
+ hover_content.append(KEYWORD_DOCS[word])
75
+
76
+ # Check if it's a built-in type
77
+ elif word in YUHO_TYPES:
78
+ hover_content.append(f"**type** `{word}`")
79
+ if word in TYPE_DOCS:
80
+ hover_content.append(TYPE_DOCS[word])
81
+
82
+ # Check AST for user-defined symbols
83
+ elif doc_state and doc_state.ast:
84
+ # Check structs
85
+ for struct in doc_state.ast.type_defs:
86
+ if struct.name == word:
87
+ fields = ", ".join(f"{f.name}: {type_to_str(f.type_annotation)}"
88
+ for f in struct.fields)
89
+ hover_content.append(f"```yuho\nstruct {struct.name} {{\n {fields}\n}}\n```")
90
+ break
91
+
92
+ # Check functions
93
+ for func in doc_state.ast.function_defs:
94
+ if func.name == word:
95
+ params = ", ".join(f"{p.name}: {type_to_str(p.type_annotation)}"
96
+ for p in func.params)
97
+ ret = f" -> {type_to_str(func.return_type)}" if func.return_type else ""
98
+ hover_content.append(f"```yuho\nfn {func.name}({params}){ret}\n```")
99
+ break
100
+
101
+ # Check statutes
102
+ for statute in doc_state.ast.statutes:
103
+ if statute.section_number == word or f"S{statute.section_number}" == word:
104
+ title = statute.title.value if statute.title else "Untitled"
105
+ hover_content.append(f"**Statute Section {statute.section_number}**: {title}")
106
+
107
+ # Add element summary
108
+ if statute.elements:
109
+ hover_content.append("\n**Elements:**")
110
+ for elem in statute.elements:
111
+ hover_content.append(f"- {elem.element_type}: {elem.name}")
112
+
113
+ # Add penalty summary
114
+ if statute.penalty:
115
+ hover_content.append("\n**Penalty:**")
116
+ if statute.penalty.imprisonment_max:
117
+ hover_content.append(f"- Imprisonment: up to {statute.penalty.imprisonment_max}")
118
+ if statute.penalty.fine_max:
119
+ hover_content.append(f"- Fine: up to {statute.penalty.fine_max}")
120
+ break
121
+
122
+ if not hover_content:
123
+ return None
124
+
125
+ return lsp.Hover(
126
+ contents=lsp.MarkupContent(
127
+ kind=lsp.MarkupKind.Markdown,
128
+ value="\n".join(hover_content),
129
+ )
130
+ )