comparison lisp/progmodes/ebnf-iso.el @ 38436:b174db545cfd

Some fixes to follow coding conventions.
author Pavel Janík <Pavel@Janik.cz>
date Mon, 16 Jul 2001 12:23:00 +0000
parents aef14b635283
children ad17cb15119e
comparison
equal deleted inserted replaced
38435:a9102b5472f0 38436:b174db545cfd
1 ;;; ebnf-iso --- Parser for ISO EBNF 1 ;;; ebnf-iso.el --- parser for ISO EBNF
2 2
3 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc. 3 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
4 4
5 ;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br> 5 ;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br>
6 ;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br> 6 ;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br>
7 ;; Keywords: wp, ebnf, PostScript 7 ;; Keywords: wp, ebnf, PostScript
8 ;; Time-stamp: <2000/12/19 15:25:16 vinicius> 8 ;; Time-stamp: <2001-07-15 01:03:20 pavel>
9 ;; Version: 1.5 9 ;; Version: 1.5
10 10
11 ;; This file is part of GNU Emacs. 11 ;; This file is part of GNU Emacs.
12 12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify 13 ;; GNU Emacs is free software; you can redistribute it and/or modify
115 ;; european 8-bit accentuated characters (from \240 to \377). 115 ;; european 8-bit accentuated characters (from \240 to \377).
116 ;; 116 ;;
117 ;; 117 ;;
118 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 118 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119 119
120 ;;; code: 120 ;;; Code:
121 121
122 122
123 (require 'ebnf-otz) 123 (require 'ebnf-otz)
124 124
125 125
143 (origin (point)) 143 (origin (point))
144 syntax-list token rule) 144 syntax-list token rule)
145 (goto-char start) 145 (goto-char start)
146 (setq token (ebnf-iso-lex)) 146 (setq token (ebnf-iso-lex))
147 (and (eq token 'end-of-input) 147 (and (eq token 'end-of-input)
148 (error "Invalid ISO EBNF file format.")) 148 (error "Invalid ISO EBNF file format"))
149 (while (not (eq token 'end-of-input)) 149 (while (not (eq token 'end-of-input))
150 (ebnf-message-float 150 (ebnf-message-float
151 "Parsing...%s%%" 151 "Parsing...%s%%"
152 (/ (* (- (point) bias) 100.0) total)) 152 (/ (* (- (point) bias) 100.0) total))
153 (setq token (ebnf-iso-syntax-rule token) 153 (setq token (ebnf-iso-syntax-rule token)
165 (let ((header ebnf-iso-lex) 165 (let ((header ebnf-iso-lex)
166 (action ebnf-action) 166 (action ebnf-action)
167 body) 167 body)
168 (setq ebnf-action nil) 168 (setq ebnf-action nil)
169 (or (eq token 'non-terminal) 169 (or (eq token 'non-terminal)
170 (error "Invalid meta identifier syntax rule.")) 170 (error "Invalid meta identifier syntax rule"))
171 (or (eq (ebnf-iso-lex) 'equal) 171 (or (eq (ebnf-iso-lex) 'equal)
172 (error "Invalid syntax rule: missing `='.")) 172 (error "Invalid syntax rule: missing `='"))
173 (setq body (ebnf-iso-definition-list)) 173 (setq body (ebnf-iso-definition-list))
174 (or (eq (car body) 'period) 174 (or (eq (car body) 'period)
175 (error "Invalid syntax rule: missing `;' or `.'.")) 175 (error "Invalid syntax rule: missing `;' or `.'"))
176 (setq body (cdr body)) 176 (setq body (cdr body))
177 (ebnf-eps-add-production header) 177 (ebnf-eps-add-production header)
178 (cons (ebnf-iso-lex) 178 (cons (ebnf-iso-lex)
179 (ebnf-make-production header body action)))) 179 (ebnf-make-production header body action))))
180 180
231 231
232 (defun ebnf-iso-factor (token) 232 (defun ebnf-iso-factor (token)
233 (if (eq token 'integer) 233 (if (eq token 'integer)
234 (let ((times ebnf-iso-lex)) 234 (let ((times ebnf-iso-lex))
235 (or (eq (ebnf-iso-lex) 'repeat) 235 (or (eq (ebnf-iso-lex) 'repeat)
236 (error "Missing `*'.")) 236 (error "Missing `*'"))
237 (ebnf-token-repeat times (ebnf-iso-primary (ebnf-iso-lex)))) 237 (ebnf-token-repeat times (ebnf-iso-primary (ebnf-iso-lex))))
238 (ebnf-iso-primary token))) 238 (ebnf-iso-primary token)))
239 239
240 240
241 ;;; primary = optional sequence | repeated sequence | special sequence 241 ;;; primary = optional sequence | repeated sequence | special sequence
271 (ebnf-make-special ebnf-iso-lex)) 271 (ebnf-make-special ebnf-iso-lex))
272 ;; grouped sequence 272 ;; grouped sequence
273 ((eq token 'begin-group) 273 ((eq token 'begin-group)
274 (let ((body (ebnf-iso-definition-list))) 274 (let ((body (ebnf-iso-definition-list)))
275 (or (eq (car body) 'end-group) 275 (or (eq (car body) 'end-group)
276 (error "Missing `)'.")) 276 (error "Missing `)'"))
277 (cdr body))) 277 (cdr body)))
278 ;; optional sequence 278 ;; optional sequence
279 ((eq token 'begin-optional) 279 ((eq token 'begin-optional)
280 (let ((body (ebnf-iso-definition-list))) 280 (let ((body (ebnf-iso-definition-list)))
281 (or (eq (car body) 'end-optional) 281 (or (eq (car body) 'end-optional)
282 (error "Missing `]' or `/)'.")) 282 (error "Missing `]' or `/)'"))
283 (ebnf-token-optional (cdr body)))) 283 (ebnf-token-optional (cdr body))))
284 ;; repeated sequence 284 ;; repeated sequence
285 ((eq token 'begin-zero-or-more) 285 ((eq token 'begin-zero-or-more)
286 (let* ((body (ebnf-iso-definition-list)) 286 (let* ((body (ebnf-iso-definition-list))
287 (repeat (cdr body))) 287 (repeat (cdr body)))
288 (or (eq (car body) 'end-zero-or-more) 288 (or (eq (car body) 'end-zero-or-more)
289 (error "Missing `}' or `:)'.")) 289 (error "Missing `}' or `:)'"))
290 (ebnf-make-zero-or-more repeat))) 290 (ebnf-make-zero-or-more repeat)))
291 ;; empty 291 ;; empty
292 (t 292 (t
293 nil) 293 nil)
294 ))) 294 )))
424 ;; end of input 424 ;; end of input
425 ((>= (point) ebnf-limit) 425 ((>= (point) ebnf-limit)
426 'end-of-input) 426 'end-of-input)
427 ;; error 427 ;; error
428 ((eq token 'error) 428 ((eq token 'error)
429 (error "Illegal character.")) 429 (error "Illegal character"))
430 ;; integer 430 ;; integer
431 ((eq token 'integer) 431 ((eq token 'integer)
432 (setq ebnf-iso-lex (ebnf-buffer-substring "0-9")) 432 (setq ebnf-iso-lex (ebnf-buffer-substring "0-9"))
433 'integer) 433 'integer)
434 ;; special: ?special? 434 ;; special: ?special?
449 ((eq token 'non-terminal) 449 ((eq token 'non-terminal)
450 (setq ebnf-iso-lex (ebnf-iso-normalize 450 (setq ebnf-iso-lex (ebnf-iso-normalize
451 (ebnf-trim-right 451 (ebnf-trim-right
452 (ebnf-buffer-substring " 0-9A-Za-z\240-\377")))) 452 (ebnf-buffer-substring " 0-9A-Za-z\240-\377"))))
453 (and ebnf-no-meta-identifier 453 (and ebnf-no-meta-identifier
454 (error "Exception sequence should not contain a meta identifier.")) 454 (error "Exception sequence should not contain a meta identifier"))
455 'non-terminal) 455 'non-terminal)
456 ;; begin optional, begin list or begin group 456 ;; begin optional, begin list or begin group
457 ((eq token 'left-parenthesis) 457 ((eq token 'left-parenthesis)
458 (forward-char) 458 (forward-char)
459 (cond ((= (following-char) ?/) 459 (cond ((= (following-char) ?/)
509 ) 509 )
510 (let ((pair 1)) 510 (let ((pair 1))
511 (while (> pair 0) 511 (while (> pair 0)
512 (skip-chars-forward ebnf-iso-comment-chars ebnf-limit) 512 (skip-chars-forward ebnf-iso-comment-chars ebnf-limit)
513 (cond ((>= (point) ebnf-limit) 513 (cond ((>= (point) ebnf-limit)
514 (error "Missing end of comment: `*)'.")) 514 (error "Missing end of comment: `*)'"))
515 ((= (following-char) ?*) 515 ((= (following-char) ?*)
516 (skip-chars-forward "*" ebnf-limit) 516 (skip-chars-forward "*" ebnf-limit)
517 (when (= (following-char) ?\)) 517 (when (= (following-char) ?\))
518 ;; end of comment 518 ;; end of comment
519 (forward-char) 519 (forward-char)
523 (when (= (following-char) ?*) 523 (when (= (following-char) ?*)
524 ;; beginning of comment 524 ;; beginning of comment
525 (forward-char) 525 (forward-char)
526 (setq pair (1+ pair)))) 526 (setq pair (1+ pair))))
527 (t 527 (t
528 (error "Illegal character.")) 528 (error "Illegal character"))
529 )))) 529 ))))
530 530
531 531
532 (defun ebnf-iso-eps-filename () 532 (defun ebnf-iso-eps-filename ()
533 (forward-char) 533 (forward-char)