summaryrefslogtreecommitdiff
path: root/admin/grammars/make.by
blob: 6cff4716f8234c0da08d18cb551bbcd756a77217 (plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
;;; make.by -- BY notation for Makefiles.

;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
;;
;; Author: Eric M. Ludlam <zappo@gnu.org>
;;         David Ponce <david@dponce.com>
;;         Klaus Berndl <klaus.berndl@sdm.de>
;;
;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

%package semantic-make-by
%provide semantic/bovine/make-by

%languagemode  makefile-mode
%start         Makefile

;; This was always a test case.
%quotemode     backquote

%token IF      "if"
%token IFDEF   "ifdef"
%token IFNDEF  "ifndef"
%token IFEQ    "ifeq"
%token IFNEQ   "ifneq"
%token ELSE    "else"
%token ENDIF   "endif"
%token INCLUDE "include"

%put { IF ELSE ENDIF } summary "Conditional: if (expression) ... else ... endif"
%put IFDEF   summary "Conditional: ifdef (expression) ... else ... endif"
%put IFNDEF  summary "Conditional: ifndef (expression) ... else ... endif"
%put IFEQ    summary "Conditional: ifeq (expression) ... else ... endif"
%put IFNEQ   summary "Conditional: ifneq (expression) ... else ... endif"
%put INCLUDE summary "Macro: include filename1 filename2 ..."

%token <punctuation> COLON     "\\`[:]\\'"
%token <punctuation> PLUS      "\\`[+]\\'"
%token <punctuation> EQUAL     "\\`[=]\\'"
%token <punctuation> DOLLAR    "\\`[$]\\'"
%token <punctuation> BACKSLASH "\\`[\\]\\'"

%%

Makefile : bol newline (nil)
	 | bol variable
	   ( ,@$2 )
	 | bol rule
	   ( ,@$2 )
	 | bol conditional
	   ( ,@$2 )
	 | bol include
	   ( ,@$2 )
	 | whitespace ( nil )
	 | newline ( nil )
	 ;

variable: symbol opt-whitespace equals opt-whitespace element-list
	  (VARIABLE-TAG ,$1 nil ,$5)
	;

rule: targets opt-whitespace colons opt-whitespace element-list commands
      (FUNCTION-TAG ,$1 nil ,$5)
    ;

targets: target opt-whitespace targets
	 ( (car ,$1) (car ,@$3) )
       | target
	 ( (car ,$1) )
       ;

target: sub-target target
	( (concat (car ,$1) (car ,@$3) ) )
      | sub-target
	( (car ,$1) )
      ;

sub-target: symbol
	  | string
	  | varref
	  ;

conditional: IF some-whitespace symbol newline
	     ( nil )
	   | IFDEF some-whitespace symbol newline
	     ( nil )
	   | IFNDEF some-whitespace symbol newline
	     ( nil )
	   | IFEQ some-whitespace expression newline
	     ( nil )
	   | IFNEQ some-whitespace expression newline
	     ( nil )
	   | ELSE newline
	     ( nil )
	   | ENDIF newline
	     ( nil )
	   ;

expression : semantic-list
	   ;

include: INCLUDE some-whitespace element-list
	 (INCLUDE-TAG ,$3 nil)
       ;

equals: COLON EQUAL ()
      | PLUS EQUAL ()
      | EQUAL ()
      ;

colons: COLON COLON ()
      | COLON ()
      ;

element-list: elements newline
	      ( ,@$1 )
	    ;

elements: element some-whitespace elements
	  ( ,@$1 ,@$3 )
	| element
	  ( ,@$1 )
	| ;;EMPTY
	;
  
element: sub-element element
	 ( (concat (car ,$1) (car ,$2)) )
       | ;;EMPTY
       ;

sub-element: symbol
	   | string
	   | punctuation
	   | semantic-list
	     ( (buffer-substring-no-properties
		 (identity start) (identity end)) )
	   ;

varref: DOLLAR semantic-list
	( (buffer-substring-no-properties (identity start) (identity end)) )
      ;

commands: bol shell-command newline commands
	  ( ,$1 ,@$2 )
	| ;;EMPTY
	  ( )
	;

opt-whitespace : some-whitespace ( nil )
	       | ;;EMPTY
	       ;

some-whitespace : whitespace some-whitespace (nil)
		| whitespace (nil)
		;

;;; make.by ends here