Files
zeekay d9c73505fa Finish build-system rebrand (capnp->zap) and fix whitespace-desugar bugs
Build system (autotools/CMake/Bazel) capnp->zap rebrand completed so the
c++/ tree configures cleanly: `autoreconf -i && ./configure` succeeds,
emitting Makefile, all zap*.pc / kj*.pc and the Zap CMake config. configure.ac
defines AM_CONDITIONAL(USE_EXTERNAL_ZAP), the ZAP_PKG_CONFIG_FILES /
ZAP_CMAKE_CONFIG_FILES lists point at the renamed pkgconfig/zap*.pc.in and
cmake/Zap*.cmake.in, and Makefile.am's `if USE_EXTERNAL_ZAP` matches. Bazel
loads @zap-cpp//src/zap:cc_zap_library.bzl. Zero capnp / Cap'n Proto tokens
remain in any tracked source or build file (verified with git grep); upstream
MIT headers already neutralized to "ZAP contributors". quick-test.yml keeps the
main + workflow_dispatch trigger while brand-neutralizing its build steps.

Whitespace-significant schema desugar (compiler/desugar.c++) — fix three HIGH
correctness bugs and make the preprocessor total:

  * Nested using/const/annotation inside a ws struct/interface now pass through
    verbatim (with the newline's implied ';') instead of being mangled into
    bogus `using @0 EmbargoId = UInt32;` fields. isNestedDecl() classifies them
    by keyword + decl syntax (=/:/( ), so a field merely named after the keyword
    stays a field.
  * Ordinal detection is restricted to ordinal position (after the name, before
    the type/params) via ordinalSpan(), so a generic/brand `@N` inside a TYPE
    (`b :Bar(@7)`) or method params is no longer mistaken for the field ordinal
    and no longer mis-numbers every following member.
  * Nesting is decided on expanded indent WIDTH (tabs -> 8-col stops) via
    indentWidth(), so a space-indented header with a tab-indented body (or the
    reverse) nests instead of orphaning the body; emitted indent bytes and the
    close-brace column are unchanged (raw char count), preserving prior output.
  * Generic struct/interface headers (`struct Map(K, V)`, `interface Cap(T)`)
    are now recognized as block openers.
  * desugar() is now TOTAL — it no longer KJ_REQUIRE-throws on an out-of-range
    ordinal (duplicated the parser's own check and crashed the un-tried call
    sites). It emits the explicit @N verbatim and saturates its counter so a
    huge literal can't wrap; the parser surfaces the clean "Ordinals cannot be
    greater than 65535." diagnostic at the right file:line:col. Removed the now
    redundant validateAutoOrdinal and the dead kj/debug.h include. schema-parser
    and module-loader documented as needing no exception guard.

desugar-test.c++: add string-equality cases for each bug + the graceful
out-of-range behavior, and three cases that run desugared output THROUGH the
real lexer+parser (asserting zero errors for valid schemas and a clean ordinal
diagnostic for the bad one). Brace back-compat proven byte-identical over the
18-file corpus; sample.ws.zap still desugars to sample.brace.zap exactly.
2026-06-20 00:02:20 -07:00

69 lines
1.8 KiB
EmacsLisp

;;; zap-mode.el --- Major mode for editing Capn' Proto Files
;; This is free and unencumbered software released into the public domain.
;; Author: Brian Taylor <[email protected]>
;; Version: 1.0.0
;; URL: https://github.com/zap/zap
;;; Commentary:
;; Provides basic syntax highlighting for zap files.
;;
;; To use:
;;
;; Add something like this to your .emacs file:
;;
;; (add-to-list 'load-path "~/src/zap/highlighting/emacs")
;; (require 'zap-mode)
;;
;;; Code:
(defvar zap--syntax-table
(let ((syn-table (make-syntax-table)))
;; bash style comment: “# …”
(modify-syntax-entry ?# "< b" syn-table)
(modify-syntax-entry ?\n "> b" syn-table)
syn-table)
"Syntax table for `zap-mode'.")
(defvar zap--keywords
'("struct" "enum" "interface" "union" "import"
"using" "const" "annotation" "extends" "in"
"of" "on" "as" "with" "from" "fixed")
"Keywords in `zap-mode'.")
(defvar zap--types
'("union" "group" "Void" "Bool" "Int8" "Int16"
"Int32" "Int64" "UInt8" "UInt16" "UInt32"
"UInt64" "Float32" "Float64" "Text" "Data"
"AnyPointer" "AnyStruct" "Capability" "List")
"Types in `zap-mode'.")
(defvar zap--font-lock-keywords
`(
(,(regexp-opt zap--keywords 'words) . font-lock-keyword-face)
(,(regexp-opt zap--types 'words) . font-lock-type-face)
("@\\w+" . font-lock-constant-face))
"Font lock definitions in `zap-mode'.")
;;;###autoload
(define-derived-mode zap-mode prog-mode
"capn-mode is a major mode for editing zap protocol files"
:syntax-table zap--syntax-table
(setq-local comment-start "# ")
(setq-local comment-start-skip "#+\\s-*")
(setq font-lock-defaults '((zap--font-lock-keywords)))
(setq mode-name "zap"))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.zap\\'" . zap-mode))
(provide 'zap-mode)
;;; zap-mode.el ends here