=== Ungrammar Language Service <subsec-impl-langservice>

The Ungrammar Language Service serves as the foundational module of our system.
Its independence from external dependencies ensures a focused implementation of
core Ungrammar language logic. This modular approach offers several key
advantages:

- *Centralized Logic*: All core language features, including parsing, semantic
  analysis, and code generation, are encapsulated within this module, promoting
  a well-organized and maintainable codebase.
- *Dependency Isolation*: The Language Service's independence from other
  modules minimizes potential conflicts and simplifies testing and maintenance.
- *Reusability*: The Language Service can potentially be reused in other
  projects or applications, demonstrating its versatility and value.

Integration with Other Components:

- *Language Server (@subsec-impl-langserver)*: The Language Server module acts as a
  communication bridge between the Language Service and code editors, enabling
  seamless integration and feature access.
- *VS Code Extension*: The VS Code extension leverages the Language
  Service to provide LSP features within the VS Code environment, enhancing the
  user experience.
- *Monaco Editor Integration (@subsec-impl-monaco)*: The Monaco editor can directly
  interact with the Language Service, accessing its capabilities without the
  need for a separate Language Server module.

==== CST to AST Transpiler

A key differentiator of our LSP ecosystem is its innovative approach to
converting Concrete Syntax Trees (CSTs) to Abstract Syntax Trees (ASTs) using
the Ungrammar language. This transformation is crucial for enabling effective
analysis and manipulation of the parsed code.

We've developed a script that utilizes the Ungrammar parser to implement a
CST-to-AST translator. By employing the Visitor design pattern, we've ensured
that the generated AST is robust, modular, and maintainable. Each node within
the AST is treated as an acceptor, allowing for flexible and extensible
traversal; and analysis.

This approach effectively decouples the LSP's core logic from the AST
structure, promoting better code organization and maintainability. By
separating concerns, we've made it easier to modify and extend the LSP's
functionality without affecting the underlying AST representation.

#[
  #show figure: set block(breakable: true)
  #set raw(block: true)
  #figure(
    raw(read("/assets/ungrammar.ungram")),
    caption: [Ungrammar file of Ungrammar for Translator],
  )
  #figure(
    raw(read("/assets/generated.ts"), lang: "ts"),
    caption: [Generated AST (with hidden sections for clarity) totaling 439 lines of code],
  )
]

==== Implementing LSP Core Services

To enhance the structure and maintainability of our Language Service module,
we've strategically divided it into multiple submodules. This modular approach
leverages the power of the Abstract Syntax Tree (AST) generated by our parser
to organize and manage different aspects of language analysis and support.

#figure(
  raw(read("/assets/tree-service.txt"), block: true),
  caption: [Tree of Ungrammar Language Service workspace],
)

==== Deployment to NPM

Upon completion of development, we successfully deployed the Ungrammar Language
Service to the NPM registry. This strategic move allows other developers to
easily discover, integrate, and extend our project for their own
language-related endeavors. By making the Language Service readily available on
NPM, we've expanded the accessibility and potential impact of our work within
the developer community.

Here is our deployed Ungrammar Language Service, which has been downloaded by
187 users since its public release and is currently hosted at
#link("https://www.npmjs.com/package/ungrammar-languageservice").

#figure(
  image("/assets/service.jpg", width: 90%),
  caption: [Deployed Ungrammar Language Service on NPM],
)
