1# 2# This file is derived from 3# 4# https://github.com/varlink/rust/blob/master/varlink_parser/src/varlink_grammar.rustpeg 5# 6# Using the file in MIT License is allowed in https://github.com/varlink/rust/issues/20. 7# 8######################################################################## 9# 10# MIT License 11# 12# Copyright (c) 2016 - 2018 Red Hat, Inc. 13# 14# Permission is hereby granted, free of charge, to any person obtaining a copy 15# of this software and associated documentation files (the "Software"), to deal 16# in the Software without restriction, including without limitation the rights 17# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18# copies of the Software, and to permit persons to whom the Software is 19# furnished to do so, subject to the following conditions: 20# 21# The above copyright notice and this permission notice shall be included in all 22# copies or substantial portions of the Software. 23# 24# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30# SOFTWARE. 31# 32######################################################################## 33# 34# This module contains PEG grammer and functions for generating tags 35# for varlink IDL: 36# 37# * https://github.com/varlink 38# * https://varlink.org/Interface-Definition 39# 40# varlink_grammar.rustpeg uses ** and ++ extended operators. 41# peg processor written in Rust can understand the operators. 42# However, packcc doesn't do. So ** and ++ are replaced with 43# rules without ** and ++ operators. 44# 45# This parser is the test-bed for using packcc in ctags. 46# 47# TODO 48# 49# * revise scope field for field value 50# * implement typeref and signature fields 51# 52 53# 54# To avoid conflicting names in code generated by packcc and code written manually, 55# add "p" as prefix to names in generated code. 56# 57%prefix "pvarlink" 58 59%auxil "struct parserCtx *" 60 61%earlysource { 62 #include "general.h" 63} 64 65%header { 66 struct parserCtx; 67} 68 69%source { 70#include "varlink_pre.h" 71} 72 73# 74# Packcc tries to apply the first grammar rule in the input. 75# 76interface 77 <- _* "interface" _+ interface_name eol ( member_list ) _* 78 79# Modeled after ECMA-262, 5th ed., 7.2. \v\f removed 80whitespace 81 <- [ \t\u00A0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000] 82 83# Modeled after ECMA-262, 5th ed., 7.3. 84eol_r 85 <- "\n" 86 / "\r\n" 87 / "\r" 88 / "\u2028" 89 / "\u2029" 90 91comment 92 <- "#" [^\n\r\u2028\u2029]* eol_r 93 94eol 95 <- whitespace* eol_r 96 / comment 97 98_ 99 <- whitespace / comment / eol_r 100 101field_name 102 <- < [A-Za-z]('_'?[A-Za-z0-9])* > { 103 makeVarlinkTag(auxil, $1, $1s); 104} 105 106field_name_list 107 <- field_name (_* ',' _* field_name)* 108 109name 110 <- < [A-Z][A-Za-z0-9]* > { 111 if (PEEK_KIND (auxil) != KIND_GHOST_INDEX) 112 SET_SCOPE(auxil, makeVarlinkTag(auxil, $1, $1s)); 113} 114 115interface_name 116 <- < [a-z]([-]* [a-z0-9])* ( '.' [a-z0-9]([-]*[a-z0-9])* )+ > { 117 SET_SCOPE(auxil, makeVarlinkTag(auxil, $1, $1s)); 118} 119 120dict 121 <- "[string]" 122 123array 124 <- "[]" 125 126maybe 127 <- "?" 128 129element_type 130 <- "bool" 131 / "int" 132 / "float" 133 / "string" 134 / "object" 135 / { PUSH_KIND (auxil, KIND_GHOST_INDEX); } name { POP_KIND (auxil, false); } 136 / venum 137 / vstruct 138 139type 140 <- element_type 141 / maybe element_type 142 / array type 143 / dict type 144 / maybe array type 145 / maybe dict type 146 147venum 148 <- { PUSH_KIND (auxil, K_ENUMERATION); } '(' _* field_name_list? _* ')' { POP_KIND (auxil, false); } 149 150argument 151 <- _* field_name _* ':' _* type 152 153argument_list 154 <- argument (_* ',' _* argument)* 155 156vstruct 157 <- { pushKindContextual (auxil); } '(' _* argument_list? _* ')' { POP_KIND (auxil, false); } 158 159vtypedef 160 <- "type" { PUSH_KIND (auxil, K_STRUCT); } _+ name _* vstruct { POP_KIND (auxil, true); } 161 / "type" { PUSH_KIND (auxil, K_ENUM); } _+ name _* venum { POP_KIND (auxil, true); } 162 163error 164 <- "error" { PUSH_KIND (auxil, K_ERROR); } _+ name _* vstruct { POP_KIND (auxil, true); } 165 166method 167 <- "method" { 168 PUSH_KIND (auxil, K_METHOD); setMethodParamState (auxil, METHOD_PARAM_INPUT); 169 } _+ name _* vstruct _* { 170 setMethodParamState (auxil, METHOD_PARAM_OUTPUT); 171 } "->" _* vstruct { POP_KIND (auxil, true); } 172 173member 174 <- _* m:method 175 / _* t:vtypedef 176 / _* e:error 177 178member_list 179 <- member (eol member)* 180 181%% 182#include "varlink_post.h" 183