Skip to content

je-es/syntax

Repository files navigation


syntax

Defines the formal grammar and syntax rules.
Acts as the single source of truth for all language constructs and structures.

line
  • Install

    npm install @je-es/syntax
    import * as Syntax from "@je-es/syntax";

    line
  • Usage

    // [1] Create syntax object
    const syntax = Syntax.create({
        name     : 'Kemet',
        version  : '0.0.1',
        lexer    : lexerRules,      // Hint: use `@je-es/lexer`  for lexer rules
        parser   : parserRules,     // Hint: use `@je-es/parser` for parser rules
        settings : parserSettings   // Hint: use `@je-es/parser` for parser settings
        lsp      : lspConfig        // Hint: use `@je-es/lsp`    for lsp config
    } as Syntax.SyntaxConfig);
    // [2] One instruction that abbreviates both: lexer.tokenize() and parser.parse()
    syntax.parse('<your-text>');
  • LSP Integration

    The @je-es/syntax package now supports LSP (Language Server Protocol) configuration, allowing you to define language-specific features for IDE integration.

    • Define LSP Configuration

      import type { LSPConfig } from '@je-es/syntax';
      
      const lspConfig: LSPConfig = {
      
          keywords: {
              declarations    : ['let', 'fn', 'def', 'use', 'pub'],
              types           : ['i8', 'i16', 'i32', 'i64', 'bool', 'str'],
              controlFlow     : ['if', 'else', 'while', 'for', 'return'],
              modifiers       : ['mut', 'pub', 'static', 'inline'],
              operators       : ['as', 'typeof', 'sizeof', 'try', 'catch'],
              literals        : ['true', 'false', 'null', 'und'],
              builtins        : ['@print', '@i', 'self']
          },
      
          keywordDocs: {
              'let': {
                  signature   : '[pub] let [mut] name: type = value',
                  description : 'Declare a variable',
                  example     : 'let mut counter: i32 = 0;'
              },
              'fn': {
                  signature   : '[pub] fn name(params) -> type { }',
                  description : 'Declare a function',
                  example     : 'pub fn add(a: i32, b: i32) -> i32 { return a + b; }'
              }
              // ...
          },
      
          builtinDocs: {
              '@print'        : '```kemet\nfn @print(text: str) -> void\n```\n\nBuilt-in function to print text.',
              // ...
          },
      
          triggerCharacters   : ['.', ':', '@', ' '],
          fileExtension       : '.k'
      };
    • Use in LSP Server

      import { LSP } from '@je-es/lsp';
      import { kemetSyntax } from '@kemet-rules/lang';
      
      const lsp = new LSP(connection, documents, {
          syntax   : kemetSyntax,  // ← Pass syntax with LSP config
          rootPath : process.cwd()
      });
      
      lsp.start();

    line
  • Related


line

About

Defines the formal grammar and syntax rules.

Topics

Resources

License

Stars

Watchers

Forks