Last-Modified: Tue, 14 Jul 2026 08:24:20 GMT Expires: Fri, 11 Jul 2036 08:24:20 GMT helix - Unnamed repository; edit this file 'description' to name the repository.
Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{ stdenv, lib, runCommand, yj }:
let
  # HACK: nix < 2.6 has a bug in the toml parser, so we convert to JSON
  # before parsing
  languages-json = runCommand "languages-toml-to-json" { } ''
    ${yj}/bin/yj -t < ${./languages.toml} > $out
  '';
  languagesConfig = if lib.versionAtLeast builtins.nixVersion "2.6.0" then
      builtins.fromTOML (builtins.readFile ./languages.toml)
    else
      builtins.fromJSON (builtins.readFile (builtins.toPath languages-json));
  isGitGrammar = (grammar:
    builtins.hasAttr "source" grammar && builtins.hasAttr "git" grammar.source
    && builtins.hasAttr "rev" grammar.source);
  isGitHubGrammar = grammar: lib.hasPrefix "https://github.com" grammar.source.git;
  toGitHubFetcher = url: let
    match = builtins.match "https://github\.com/([^/]*)/([^/]*)/?" url;
  in {
    owner = builtins.elemAt match 0;
    repo = builtins.elemAt match 1;
  };
  gitGrammars = builtins.filter isGitGrammar languagesConfig.grammar;
  buildGrammar = grammar:
    let
      gh = toGitHubFetcher grammar.source.git;
      sourceGit = builtins.fetchTree {
        type = "git";
        url = grammar.source.git;
        rev = grammar.source.rev;
        ref = grammar.source.ref or "HEAD";
        shallow = true;
      };
      sourceGitHub = builtins.fetchTree {
        type = "github";
        owner = gh.owner;
        repo = gh.repo;
        inherit (grammar.source) rev;
      };
      source = if isGitHubGrammar grammar then sourceGitHub else sourceGit;
    in stdenv.mkDerivation rec {
      # see https://github.com/NixOS/nixpkgs/blob/fbdd1a7c0bc29af5325e0d7dd70e804a972eb465/pkgs/development/tools/parsing/tree-sitter/grammar.nix

      pname = "helix-tree-sitter-${grammar.name}";
      version = grammar.source.rev;

      src = if builtins.hasAttr "subpath" grammar.source then
        "${source}/${grammar.source.subpath}"
      else
        source;

      dontUnpack = true;
      dontConfigure = true;

      FLAGS = [
        "-I${src}/src"
        "-g"
        "-O3"
        "-fPIC"
        "-fno-exceptions"
        "-Wl,-z,relro,-z,now"
      ];

      NAME = grammar.name;

      buildPhase = ''
        runHook preBuild

        if [[ -e "$src/src/scanner.cc" ]]; then
          $CXX -c "$src/src/scanner.cc" -o scanner.o $FLAGS
        elif [[ -e "$src/src/scanner.c" ]]; then
          $CC -c "$src/src/scanner.c" -o scanner.o $FLAGS
        fi

        $CC -c "$src/src/parser.c" -o parser.o $FLAGS
        $CXX -shared -o $NAME.so *.o

        ls -al

        runHook postBuild
      '';

      installPhase = ''
        runHook preInstall
        mkdir $out
        mv $NAME.so $out/
        runHook postInstall
      '';

      # Strip failed on darwin: strip: error: symbols referenced by indirect symbol table entries that can't be stripped
      fixupPhase = lib.optionalString stdenv.isLinux ''
        runHook preFixup
        $STRIP $out/$NAME.so
        runHook postFixup
      '';
    };
  builtGrammars = builtins.map (grammar: {
    inherit (grammar) name;
    artifact = buildGrammar grammar;
  }) gitGrammars;
  grammarLinks = builtins.map (grammar:
    "ln -s ${grammar.artifact}/${grammar.name}.so $out/${grammar.name}.so")
    builtGrammars;
in runCommand "consolidated-helix-grammars" { } ''
  mkdir -p $out
  ${builtins.concatStringsSep "\n" grammarLinks}
''
t;}"
  WHITESPACE@33..34 "\n"
  FN@34..68
    FN_KW@34..36 "fn"
    WHITESPACE@36..37 " "
    NAME@37..38
      IDENT@37..38 "b"
    PARAM_LIST@38..40
      L_PAREN@38..39 "("
      R_PAREN@39..40 ")"
    WHITESPACE@40..41 " "
    BLOCK_EXPR@41..68
      STMT_LIST@41..68
        L_CURLY@41..42 "{"
        WHITESPACE@42..43 " "
        EXPR_STMT@43..54
          CALL_EXPR@43..54
            PATH_EXPR@43..46
              PATH@43..46
                PATH_SEGMENT@43..46
                  NAME_REF@43..46
                    IDENT@43..46 "foo"
            ARG_LIST@46..54
              L_PAREN@46..47 "("
              LITERAL@47..48
                INT_NUMBER@47..48 "1"
              COMMA@48..49 ","
              WHITESPACE@49..50 " "
              LITERAL@50..51
                INT_NUMBER@50..51 "2"
              COMMA@51..52 ","
              WHITESPACE@52..53 " "
              ERROR@53..54
                AT@53..54 "@"
        ERROR@54..55
          COMMA@54..55 ","
        WHITESPACE@55..56 " "
        IMPL@56..60
          IMPL_KW@56..60 "impl"
        ERROR@60..61
          COMMA@60..61 ","
        WHITESPACE@61..62 " "
        LET_STMT@62..65
          LET_KW@62..65 "let"
        ERROR@65..66
          R_PAREN@65..66 ")"
        WHITESPACE@66..67 " "
        R_CURLY@67..68 "}"
  WHITESPACE@68..69 "\n"
  FN@69..111
    FN_KW@69..71 "fn"
    WHITESPACE@71..72 " "
    NAME@72..73
      IDENT@72..73 "c"
    PARAM_LIST@73..75
      L_PAREN@73..74 "("
      R_PAREN@74..75 ")"
    WHITESPACE@75..76 " "
    BLOCK_EXPR@76..111
      STMT_LIST@76..111
        L_CURLY@76..77 "{"
        WHITESPACE@77..78 " "
        EXPR_STMT@78..93
          METHOD_CALL_EXPR@78..93
            PATH_EXPR@78..81
              PATH@78..81
                PATH_SEGMENT@78..81
                  NAME_REF@78..81
                    IDENT@78..81 "foo"
            DOT@81..82 "."
            NAME_REF@82..85
              IDENT@82..85 "bar"
            ARG_LIST@85..93
              L_PAREN@85..86 "("
              LITERAL@86..87
                INT_NUMBER@86..87 "1"
              COMMA@87..88 ","
              WHITESPACE@88..89 " "
              LITERAL@89..90
                INT_NUMBER@89..90 "2"
              COMMA@90..91 ","
              WHITESPACE@91..92 " "
              ERROR@92..93
                AT@92..93 "@"
        ERROR@93..94
          COMMA@93..94 ","
        WHITESPACE@94..95 " "
        ERROR@95..96
          R_BRACK@95..96 "]"
        ERROR@96..97
          COMMA@96..97 ","
        WHITESPACE@97..98 " "
        TRAIT@98..104
          TRAIT_KW@98..103 "trait"
          ERROR@103..104
            COMMA@103..104 ","
        WHITESPACE@104..105 " "
        LET_STMT@105..108
          LET_KW@105..108 "let"
        ERROR@108..109
          R_PAREN@108..109 ")"
        WHITESPACE@109..110 " "
        R_CURLY@110..111 "}"
  WHITESPACE@111..112 "\n"
error 16..16: expected expression
error 17..17: expected R_BRACK
error 17..17: expected SEMICOLON
error 17..17: expected expression
error 25..25: expected a name
error 26..26: expected `;`, `{`, or `(`
error 30..30: expected pattern
error 31..31: expected SEMICOLON
error 53..53: expected expression
error 54..54: expected SEMICOLON
error 54..54: expected expression
error 60..60: expected type
error 60..60: expected `{`
error 60..60: expected expression
error 65..65: expected pattern
error 65..65: expected SEMICOLON
error 65..65: expected expression
error 92..92: expected expression
error 93..93: expected SEMICOLON
error 93..93: expected expression
error 95..95: expected expression
error 96..96: expected expression
error 103..103: expected a name
error 104..104: expected `{`
error 108..108: expected pattern
error 108..108: expected SEMICOLON
error 108..108: expected expression