xref: /Universal-ctags/parsers/dts.c (revision d00bddf924a65af2169f33a172990e5419cafaf9)
1 /*
2 *   Copyright (c) 2015, André Rivotti Casimiro <andre.r.casimiro@gmail.com>
3 *
4 *   This source code is released for free distribution under the terms of the
5 *   GNU General Public License version 2 or (at your option) any later version.
6 *
7 *   This module contains functions for generating tags for DTS language files.
8 */
9 
10 /*
11 *   INCLUDE FILES
12 */
13 #include "general.h"
14 #include "cpreprocessor.h"
15 #include "field.h"
16 #include "kind.h"
17 #include "parse.h"
18 #include "routines.h"
19 
20 static tagRegexTable dtsTagRegexTable [] = {
21 	/* phandle = <0x00> */
22 	{"^[ \t]*phandle[ \t]+=[ \t]+<(0x[a-fA-F0-9]+)>", "\\1",
23 	 "p,phandler,phandlers", "{scope=ref}"},
24 
25 	/* label: */
26 	{"^[ \t]*([a-zA-Z][a-zA-Z0-9_]*)[ \t]*:", "\\1",
27 	 "l,label,labels", "{scope=push}"},
28 
29 	/* extras for tracking scopes  */
30 	{"^[ \t]*([a-zA-Z][a-zA-Z0-9_]*)[ \t]*\\{", "",
31 	 "", "{scope=push}{placeholder}"},
32 	{"\\}[ \t]*;", "",
33 	 "", "{scope=pop}{exclusive}"},
34 };
35 
36 /*
37 *   FUNCTION DEFINITIONS
38 */
runCppGetc(void)39 static void runCppGetc (void)
40 {
41 	cppInit (false, false, false, false,
42 			 KIND_GHOST_INDEX, 0, 0,
43 			 KIND_GHOST_INDEX,
44 			 KIND_GHOST_INDEX, 0, 0,
45 			 FIELD_UNKNOWN);
46 
47 	findRegexTagsMainloop (cppGetc);
48 
49 	cppTerminate ();
50 }
51 
DTSParser(void)52 extern parserDefinition* DTSParser (void)
53 {
54 	static const char *const extensions [] = { "dts", "dtsi", NULL };
55 	parserDefinition* const def = parserNew ("DTS");
56 	def->extensions = extensions;
57 	def->parser     = runCppGetc;
58 	def->tagRegexTable = dtsTagRegexTable;
59 	def->tagRegexCount = ARRAY_SIZE (dtsTagRegexTable);
60 	def->method     = METHOD_REGEX;
61 	def->requestAutomaticFQTag = true;
62 	return def;
63 }
64