summaryrefslogtreecommitdiffstats
path: root/editors
diff options
context:
space:
mode:
authorWink Saville <wink@google.com>2010-05-27 16:25:37 -0700
committerWink Saville <wink@google.com>2010-05-27 16:25:37 -0700
commitfbaaef999ba563838ebd00874ed8a1c01fbf286d (patch)
tree24ff5c76344e90abc5b0fe6f07120ea0d2d011ee /editors
parent79a4a60053f74ab71c7c3ec436d2f6caedc5be61 (diff)
downloadexternal_protobuf-fbaaef999ba563838ebd00874ed8a1c01fbf286d.zip
external_protobuf-fbaaef999ba563838ebd00874ed8a1c01fbf286d.tar.gz
external_protobuf-fbaaef999ba563838ebd00874ed8a1c01fbf286d.tar.bz2
Add protobuf 2.2.0a sources
This is the contents of protobuf-2.2.0a.tar.bz2 from http://code.google.com/p/protobuf/downloads/list and is the base code for the javamicro code generator. Change-Id: Ie9a0440a824d615086445b6636944484b3155afa
Diffstat (limited to 'editors')
-rw-r--r--editors/README.txt5
-rw-r--r--editors/proto.vim106
-rw-r--r--editors/protobuf-mode.el218
3 files changed, 329 insertions, 0 deletions
diff --git a/editors/README.txt b/editors/README.txt
new file mode 100644
index 0000000..3e9fc79
--- /dev/null
+++ b/editors/README.txt
@@ -0,0 +1,5 @@
+This directory contains syntax highlighting and configuration files for editors
+to properly display Protocol Buffer files.
+
+See each file's header comment for directions on how to use it with the
+appropriate editor.
diff --git a/editors/proto.vim b/editors/proto.vim
new file mode 100644
index 0000000..42f3307
--- /dev/null
+++ b/editors/proto.vim
@@ -0,0 +1,106 @@
+" Protocol Buffers - Google's data interchange format
+" Copyright 2008 Google Inc. All rights reserved.
+" http://code.google.com/p/protobuf/
+"
+" Redistribution and use in source and binary forms, with or without
+" modification, are permitted provided that the following conditions are
+" met:
+"
+" * Redistributions of source code must retain the above copyright
+" notice, this list of conditions and the following disclaimer.
+" * Redistributions in binary form must reproduce the above
+" copyright notice, this list of conditions and the following disclaimer
+" in the documentation and/or other materials provided with the
+" distribution.
+" * Neither the name of Google Inc. nor the names of its
+" contributors may be used to endorse or promote products derived from
+" this software without specific prior written permission.
+"
+" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+" OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+" This is the Vim syntax file for Google Protocol Buffers.
+"
+" Usage:
+"
+" 1. cp proto.vim ~/.vim/syntax/
+" 2. Add the following to ~/.vimrc:
+"
+" augroup filetype
+" au! BufRead,BufNewFile *.proto setfiletype proto
+" augroup end
+"
+" Or just create a new file called ~/.vim/ftdetect/proto.vim with the
+" previous lines on it.
+
+if version < 600
+ syntax clear
+elseif exists("b:current_syntax")
+ finish
+endif
+
+syn case match
+
+syn keyword pbTodo contained TODO FIXME XXX
+syn cluster pbCommentGrp contains=pbTodo
+
+syn keyword pbSyntax syntax import option
+syn keyword pbStructure package message group
+syn keyword pbRepeat optional required repeated
+syn keyword pbDefault default
+syn keyword pbExtend extend extensions to max
+syn keyword pbRPC service rpc returns
+
+syn keyword pbType int32 int64 uint32 uint64 sint32 sint64
+syn keyword pbType fixed32 fixed64 sfixed32 sfixed64
+syn keyword pbType float double bool string bytes
+syn keyword pbTypedef enum
+syn keyword pbBool true false
+
+syn match pbInt /-\?\<\d\+\>/
+syn match pbInt /\<0[xX]\x+\>/
+syn match pbFloat /\<-\?\d*\(\.\d*\)\?/
+" TODO: .proto also supports C-style block comments;
+" see /usr/share/vim/vim70/syntax/c.vim for how it's done.
+syn region pbComment start="//" skip="\\$" end="$" keepend contains=@pbCommentGrp
+syn region pbString start=/"/ skip=/\\"/ end=/"/
+syn region pbString start=/'/ skip=/\\'/ end=/'/
+
+if version >= 508 || !exists("did_proto_syn_inits")
+ if version < 508
+ let did_proto_syn_inits = 1
+ command -nargs=+ HiLink hi link <args>
+ else
+ command -nargs=+ HiLink hi def link <args>
+ endif
+
+ HiLink pbTodo Todo
+
+ HiLink pbSyntax Include
+ HiLink pbStructure Structure
+ HiLink pbRepeat Repeat
+ HiLink pbDefault Keyword
+ HiLink pbExtend Keyword
+ HiLink pbRPC Keyword
+ HiLink pbType Type
+ HiLink pbTypedef Typedef
+ HiLink pbBool Boolean
+
+ HiLink pbInt Number
+ HiLink pbFloat Float
+ HiLink pbComment Comment
+ HiLink pbString String
+
+ delcommand HiLink
+endif
+
+let b:current_syntax = "proto"
diff --git a/editors/protobuf-mode.el b/editors/protobuf-mode.el
new file mode 100644
index 0000000..3337c1f
--- /dev/null
+++ b/editors/protobuf-mode.el
@@ -0,0 +1,218 @@
+;;; protobuf-mode.el --- major mode for editing protocol buffers.
+
+;; Author: Alexandre Vassalotti <alexandre@peadrop.com>
+;; Created: 23-Apr-2009
+;; Version: 0.3
+;; Keywords: google protobuf languages
+
+;; Redistribution and use in source and binary forms, with or without
+;; modification, are permitted provided that the following conditions are
+;; met:
+;;
+;; * Redistributions of source code must retain the above copyright
+;; notice, this list of conditions and the following disclaimer.
+;; * Redistributions in binary form must reproduce the above
+;; copyright notice, this list of conditions and the following disclaimer
+;; in the documentation and/or other materials provided with the
+;; distribution.
+;; * Neither the name of Google Inc. nor the names of its
+;; contributors may be used to endorse or promote products derived from
+;; this software without specific prior written permission.
+;;
+;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+;;; Commentary:
+
+;; Installation:
+;; - Put `protobuf-mode.el' in your Emacs load-path.
+;; - Add this line to your .emacs file:
+;; (require 'protobuf-mode)
+;;
+;; You can customize this mode just like any mode derived from CC Mode. If
+;; you want to add customizations specific to protobuf-mode, you can use the
+;; `protobuf-mode-hook'. For example, the following would make protocol-mode
+;; use 2-space indentation:
+;;
+;; (defconst my-protobuf-style
+;; '((c-basic-offset . 2)
+;; (indent-tabs-mode . nil)))
+;;
+;; (add-hook 'protobuf-mode-hook
+;; (lambda () (c-add-style "my-style" my-protobuf-style t)))
+;;
+;; Refer to the documentation of CC Mode for more information about
+;; customization details and how to use this mode.
+;;
+;; TODO:
+;; - Make highlighting for enum values work properly.
+;; - Fix the parser to recognize extensions as identifiers and not
+;; as casts.
+;; - Improve the parsing of option assignment lists. For example:
+;; optional int32 foo = 1 [(my_field_option) = 4.5];
+;; - Add support for fully-qualified identifiers (e.g., with a leading ".").
+
+;;; Code:
+
+(require 'cc-mode)
+
+(eval-when-compile
+ (require 'cc-langs)
+ (require 'cc-fonts))
+
+;; This mode does not inherit properties from other modes. So, we do not use
+;; the usual `c-add-language' function.
+(put 'protobuf-mode 'c-mode-prefix "protobuf-")
+
+;; The following code uses of the `c-lang-defconst' macro define syntactic
+;; features of protocol buffer language. Refer to the documentation in the
+;; cc-langs.el file for information about the meaning of the -kwds variables.
+
+(c-lang-defconst c-primitive-type-kwds
+ protobuf '("double" "float" "int32" "int64" "uint32" "uint64" "sint32"
+ "sint64" "fixed32" "fixed64" "sfixed32" "sfixed64" "bool"
+ "string" "bytes" "group"))
+
+(c-lang-defconst c-modifier-kwds
+ protobuf '("required" "optional" "repeated"))
+
+(c-lang-defconst c-class-decl-kwds
+ protobuf '("message" "enum" "service"))
+
+(c-lang-defconst c-constant-kwds
+ protobuf '("true" "false"))
+
+(c-lang-defconst c-other-decl-kwds
+ protobuf '("package" "import"))
+
+(c-lang-defconst c-other-kwds
+ protobuf '("default" "max"))
+
+(c-lang-defconst c-identifier-ops
+ ;; Handle extended identifiers like google.protobuf.MessageOptions
+ protobuf '((left-assoc ".")))
+
+;; The following keywords do not fit well in keyword classes defined by
+;; cc-mode. So, we approximate as best we can.
+
+(c-lang-defconst c-type-list-kwds
+ protobuf '("extensions" "to"))
+
+(c-lang-defconst c-typeless-decl-kwds
+ protobuf '("extend" "rpc" "option" "returns"))
+
+
+;; Here we remove default syntax for loops, if-statements and other C
+;; syntactic features that are not supported by the protocol buffer language.
+
+(c-lang-defconst c-brace-list-decl-kwds
+ ;; Remove syntax for C-style enumerations.
+ protobuf nil)
+
+(c-lang-defconst c-block-stmt-1-kwds
+ ;; Remove syntax for "do" and "else" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-block-stmt-2-kwds
+ ;; Remove syntax for "for", "if", "switch" and "while" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-simple-stmt-kwds
+ ;; Remove syntax for "break", "continue", "goto" and "return" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-paren-stmt-kwds
+ ;; Remove special case for the "(;;)" in for-loops.
+ protobuf nil)
+
+(c-lang-defconst c-label-kwds
+ ;; Remove case label syntax for the "case" and "default" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-before-label-kwds
+ ;; Remove special case for the label in a goto statement.
+ protobuf nil)
+
+(c-lang-defconst c-cpp-matchers
+ ;; Disable all the C preprocessor syntax.
+ protobuf nil)
+
+(c-lang-defconst c-decl-prefix-re
+ ;; Same as for C, except it does not match "(". This is needed for disabling
+ ;; the syntax for casts.
+ protobuf "\\([\{\};,]+\\)")
+
+
+;; Add support for variable levels of syntax highlighting.
+
+(defconst protobuf-font-lock-keywords-1 (c-lang-const c-matchers-1 protobuf)
+ "Minimal highlighting for protobuf-mode.")
+
+(defconst protobuf-font-lock-keywords-2 (c-lang-const c-matchers-2 protobuf)
+ "Fast normal highlighting for protobuf-mode.")
+
+(defconst protobuf-font-lock-keywords-3 (c-lang-const c-matchers-3 protobuf)
+ "Accurate normal highlighting for protobuf-mode.")
+
+(defvar protobuf-font-lock-keywords protobuf-font-lock-keywords-3
+ "Default expressions to highlight in protobuf-mode.")
+
+;; Our syntax table is auto-generated from the keyword classes we defined
+;; previously with the `c-lang-const' macro.
+(defvar protobuf-mode-syntax-table nil
+ "Syntax table used in protobuf-mode buffers.")
+(or protobuf-mode-syntax-table
+ (setq protobuf-mode-syntax-table
+ (funcall (c-lang-const c-make-mode-syntax-table protobuf))))
+
+(defvar protobuf-mode-abbrev-table nil
+ "Abbreviation table used in protobuf-mode buffers.")
+
+(defvar protobuf-mode-map nil
+ "Keymap used in protobuf-mode buffers.")
+(or protobuf-mode-map
+ (setq protobuf-mode-map (c-make-inherited-keymap)))
+
+(easy-menu-define protobuf-menu protobuf-mode-map
+ "Protocol Buffers Mode Commands"
+ (cons "Protocol Buffers" (c-lang-const c-mode-menu protobuf)))
+
+;;;###autoload (add-to-list 'auto-mode-alist '("\\.proto\\'" . protobuf-mode))
+
+;;;###autoload
+(defun protobuf-mode ()
+ "Major mode for editing Protocol Buffers description language.
+
+The hook `c-mode-common-hook' is run with no argument at mode
+initialization, then `protobuf-mode-hook'.
+
+Key bindings:
+\\{protobuf-mode-map}"
+ (interactive)
+ (kill-all-local-variables)
+ (set-syntax-table protobuf-mode-syntax-table)
+ (setq major-mode 'protobuf-mode
+ mode-name "Protocol-Buffers"
+ local-abbrev-table protobuf-mode-abbrev-table
+ abbrev-mode t)
+ (use-local-map protobuf-mode-map)
+ (c-initialize-cc-mode t)
+ (c-make-emacs-variables-local)
+ (c-init-language-vars protobuf-mode)
+ (c-common-init 'protobuf-mode)
+ (easy-menu-add protobuf-menu)
+ (c-run-mode-hooks 'c-mode-common-hook 'protobuf-mode-hook)
+ (c-update-modeline))
+
+(provide 'protobuf-mode)
+
+;;; protobuf-mode.el ends here