Mercurial > emacs
annotate lisp/progmodes/ebnf-abn.el @ 54190:6a7a401e1598
Doc fix.
author | Vinicius Jose Latorre <viniciusjl@ig.com.br> |
---|---|
date | Sat, 28 Feb 2004 21:37:17 +0000 |
parents | 8e0088433ac7 |
children | f7bb72b19510 |
rev | line source |
---|---|
54139
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
1 ;;; ebnf-abn.el --- parser for ABNF (Augmented BNF) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
2 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
3 ;; Copyright (C) 2004 Free Sofware Foundation, Inc. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
4 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
5 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
6 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> |
54190 | 7 ;; Time-stamp: <2004/02/28 17:40:41 vinicius> |
54139
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
8 ;; Keywords: wp, ebnf, PostScript |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
9 ;; Version: 1.0 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
10 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
11 ;; This file is part of GNU Emacs. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
12 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
13 ;; GNU Emacs is free software; you can redistribute it and/or modify |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
14 ;; it under the terms of the GNU General Public License as published by |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
15 ;; the Free Software Foundation; either version 2, or (at your option) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
16 ;; any later version. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
17 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
18 ;; GNU Emacs is distributed in the hope that it will be useful, |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
21 ;; GNU General Public License for more details. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
22 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
23 ;; You should have received a copy of the GNU General Public License |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
26 ;; Boston, MA 02111-1307, USA. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
27 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
28 ;;; Commentary: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
29 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
30 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
31 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
32 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
33 ;; This is part of ebnf2ps package. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
34 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
35 ;; This package defines a parser for ABNF (Augmented BNF). |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
36 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
37 ;; See ebnf2ps.el for documentation. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
38 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
39 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
40 ;; ABNF Syntax |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
41 ;; ----------- |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
42 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
43 ;; See the URL: |
54190 | 44 ;; `http://www.ietf.org/rfc/rfc2234.txt' |
45 ;; or | |
54139
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
46 ;; `http://www.faqs.org/rfcs/rfc2234.html' |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
47 ;; or |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
48 ;; `http://www.rnp.br/ietf/rfc/rfc2234.txt' |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
49 ;; ("Augmented BNF for Syntax Specifications: ABNF"). |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
50 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
51 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
52 ;; rulelist = 1*( rule / (*c-wsp c-nl) ) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
53 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
54 ;; rule = rulename defined-as elements c-nl |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
55 ;; ; continues if next line starts with white space |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
56 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
57 ;; rulename = ALPHA *(ALPHA / DIGIT / "-") |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
58 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
59 ;; defined-as = *c-wsp ("=" / "=/") *c-wsp |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
60 ;; ; basic rules definition and incremental |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
61 ;; ; alternatives |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
62 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
63 ;; elements = alternation *c-wsp |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
64 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
65 ;; c-wsp = WSP / (c-nl WSP) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
66 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
67 ;; c-nl = comment / CRLF |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
68 ;; ; comment or newline |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
69 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
70 ;; comment = ";" *(WSP / VCHAR) CRLF |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
71 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
72 ;; alternation = concatenation |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
73 ;; *(*c-wsp "/" *c-wsp concatenation) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
74 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
75 ;; concatenation = repetition *(1*c-wsp repetition) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
76 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
77 ;; repetition = [repeat] element |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
78 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
79 ;; repeat = 1*DIGIT / (*DIGIT "*" *DIGIT) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
80 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
81 ;; element = rulename / group / option / |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
82 ;; char-val / num-val / prose-val |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
83 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
84 ;; group = "(" *c-wsp alternation *c-wsp ")" |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
85 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
86 ;; option = "[" *c-wsp alternation *c-wsp "]" |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
87 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
88 ;; char-val = DQUOTE *(%x20-21 / %x23-7E) DQUOTE |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
89 ;; ; quoted string of SP and VCHAR without DQUOTE |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
90 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
91 ;; num-val = "%" (bin-val / dec-val / hex-val) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
92 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
93 ;; bin-val = "b" 1*BIT |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
94 ;; [ 1*("." 1*BIT) / ("-" 1*BIT) ] |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
95 ;; ; series of concatenated bit values |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
96 ;; ; or single ONEOF range |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
97 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
98 ;; dec-val = "d" 1*DIGIT |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
99 ;; [ 1*("." 1*DIGIT) / ("-" 1*DIGIT) ] |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
100 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
101 ;; hex-val = "x" 1*HEXDIG |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
102 ;; [ 1*("." 1*HEXDIG) / ("-" 1*HEXDIG) ] |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
103 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
104 ;; prose-val = "<" *(%x20-3D / %x3F-7E) ">" |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
105 ;; ; bracketed string of SP and VCHAR without |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
106 ;; ; angles |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
107 ;; ; prose description, to be used as last resort |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
108 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
109 ;; ; Core rules -- the coding depends on the system, here is used 7-bit ASCII |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
110 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
111 ;; ALPHA = %x41-5A / %x61-7A |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
112 ;; ; A-Z / a-z |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
113 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
114 ;; BIT = "0" / "1" |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
115 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
116 ;; CHAR = %x01-7F |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
117 ;; ; any 7-bit US-ASCII character, excluding NUL |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
118 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
119 ;; CR = %x0D |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
120 ;; ; carriage return |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
121 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
122 ;; CRLF = CR LF |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
123 ;; ; Internet standard newline |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
124 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
125 ;; CTL = %x00-1F / %x7F |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
126 ;; ; controls |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
127 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
128 ;; DIGIT = %x30-39 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
129 ;; ; 0-9 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
130 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
131 ;; DQUOTE = %x22 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
132 ;; ; " (Double Quote) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
133 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
134 ;; HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F" |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
135 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
136 ;; HTAB = %x09 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
137 ;; ; horizontal tab |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
138 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
139 ;; LF = %x0A |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
140 ;; ; linefeed |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
141 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
142 ;; LWSP = *(WSP / CRLF WSP) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
143 ;; ; linear white space (past newline) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
144 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
145 ;; OCTET = %x00-FF |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
146 ;; ; 8 bits of data |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
147 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
148 ;; SP = %x20 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
149 ;; ; space |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
150 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
151 ;; VCHAR = %x21-7E |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
152 ;; ; visible (printing) characters |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
153 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
154 ;; WSP = SP / HTAB |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
155 ;; ; white space |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
156 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
157 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
158 ;; NOTES: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
159 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
160 ;; 1. Rules name and terminal strings are case INSENSITIVE. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
161 ;; So, the following rule names are all equals: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
162 ;; Rule-name, rule-Name, rule-name, RULE-NAME |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
163 ;; Also, the following strings are equals: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
164 ;; "abc", "ABC", "aBc", "Abc", "aBC", etc. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
165 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
166 ;; 2. To have a case SENSITIVE string, use the character notation. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
167 ;; For example, to specify the lowercase string "abc", use: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
168 ;; %d97.98.99 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
169 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
170 ;; 3. There are no implicit spaces between elements, for example, the |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
171 ;; following rules: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
172 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
173 ;; foo = %x61 ; a |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
174 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
175 ;; bar = %x62 ; b |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
176 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
177 ;; mumble = foo bar foo |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
178 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
179 ;; Are equivalent to the following rule: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
180 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
181 ;; mumble = %x61.62.61 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
182 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
183 ;; If spaces are needed, it should be explicit specified, like: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
184 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
185 ;; spaces = 1*(%x20 / %x09) ; one or more spaces or tabs |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
186 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
187 ;; mumble = foo spaces bar spaces foo |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
188 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
189 ;; 4. Lines starting with space or tab are considered a continuation line. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
190 ;; For example, the rule: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
191 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
192 ;; rule = foo |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
193 ;; bar |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
194 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
195 ;; Is equivalent to: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
196 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
197 ;; rule = foo bar |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
198 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
199 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
200 ;; Differences Between ABNF And ebnf2ps ABNF |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
201 ;; ----------------------------------------- |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
202 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
203 ;; Besides the characters that ABNF accepts, ebnf2ps ABNF accepts also the |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
204 ;; underscore (_) for rule name and european 8-bit accentuated characters (from |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
205 ;; \240 to \377) for rule name, string and comment. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
206 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
207 ;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
208 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
209 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
210 ;;; Code: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
211 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
212 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
213 (require 'ebnf-otz) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
214 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
215 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
216 (defvar ebnf-abn-lex nil |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
217 "Value returned by `ebnf-abn-lex' function.") |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
218 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
219 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
221 ;; Syntactic analyzer |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
222 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
223 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
224 ;;; rulelist = 1*( rule / (*c-wsp c-nl) ) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
225 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
226 (defun ebnf-abn-parser (start) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
227 "ABNF parser." |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
228 (let ((total (+ (- ebnf-limit start) 1)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
229 (bias (1- start)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
230 (origin (point)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
231 rule-list token rule) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
232 (goto-char start) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
233 (setq token (ebnf-abn-lex)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
234 (and (eq token 'end-of-input) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
235 (error "Invalid ABNF file format")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
236 (while (not (eq token 'end-of-input)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
237 (ebnf-message-float |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
238 "Parsing...%s%%" |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
239 (/ (* (- (point) bias) 100.0) total)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
240 (setq token (ebnf-abn-rule token) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
241 rule (cdr token) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
242 token (car token)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
243 (or (ebnf-add-empty-rule-list rule) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
244 (setq rule-list (cons rule rule-list)))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
245 (goto-char origin) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
246 rule-list)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
247 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
248 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
249 ;;; rule = rulename defined-as elements c-nl |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
250 ;;; ; continues if next line starts with white space |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
251 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
252 ;;; rulename = ALPHA *(ALPHA / DIGIT / "-") |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
253 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
254 ;;; defined-as = *c-wsp ("=" / "=/") *c-wsp |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
255 ;;; ; basic rules definition and incremental |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
256 ;;; ; alternatives |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
257 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
258 ;;; elements = alternation *c-wsp |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
259 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
260 ;;; c-wsp = WSP / (c-nl WSP) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
261 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
262 ;;; c-nl = comment / CRLF |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
263 ;;; ; comment or newline |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
264 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
265 ;;; comment = ";" *(WSP / VCHAR) CRLF |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
266 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
267 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
268 (defun ebnf-abn-rule (token) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
269 (let ((name ebnf-abn-lex) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
270 (action ebnf-action) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
271 elements) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
272 (setq ebnf-action nil) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
273 (or (eq token 'non-terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
274 (error "Invalid rule name")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
275 (setq token (ebnf-abn-lex)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
276 (or (memq token '(equal incremental-alternative)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
277 (error "Invalid rule: missing `=' or `=/'")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
278 (and (eq token 'incremental-alternative) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
279 (setq name (concat name " =/"))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
280 (setq elements (ebnf-abn-alternation)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
281 (or (memq (car elements) '(end-of-rule end-of-input)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
282 (error "Invalid rule: there is no end of rule")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
283 (setq elements (cdr elements)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
284 (ebnf-eps-add-production name) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
285 (cons (ebnf-abn-lex) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
286 (ebnf-make-production name elements action)))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
287 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
288 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
289 ;;; alternation = concatenation |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
290 ;;; *(*c-wsp "/" *c-wsp concatenation) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
291 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
292 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
293 (defun ebnf-abn-alternation () |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
294 (let (body concatenation) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
295 (while (eq (car (setq concatenation |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
296 (ebnf-abn-concatenation (ebnf-abn-lex)))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
297 'alternative) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
298 (setq body (cons (cdr concatenation) body))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
299 (ebnf-token-alternative body concatenation))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
300 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
301 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
302 ;;; concatenation = repetition *(1*c-wsp repetition) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
303 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
304 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
305 (defun ebnf-abn-concatenation (token) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
306 (let ((term (ebnf-abn-repetition token)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
307 seq) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
308 (or (setq token (car term) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
309 term (cdr term)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
310 (error "Empty element")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
311 (setq seq (cons term seq)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
312 (while (setq term (ebnf-abn-repetition token) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
313 token (car term) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
314 term (cdr term)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
315 (setq seq (cons term seq))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
316 (cons token |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
317 (if (= (length seq) 1) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
318 ;; sequence with only one element |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
319 (car seq) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
320 ;; a real sequence |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
321 (ebnf-make-sequence (nreverse seq)))))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
322 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
323 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
324 ;;; repetition = [repeat] element |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
325 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
326 ;;; repeat = 1*DIGIT / (*DIGIT "*" *DIGIT) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
327 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
328 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
329 (defun ebnf-abn-repetition (token) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
330 (let (lower upper) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
331 ;; INTEGER [ "*" [ INTEGER ] ] |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
332 (when (eq token 'integer) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
333 (setq lower ebnf-abn-lex |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
334 token (ebnf-abn-lex)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
335 (or (eq token 'repeat) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
336 (setq upper lower))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
337 ;; "*" [ INTEGER ] |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
338 (when (eq token 'repeat) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
339 ;; only * ==> lower & upper are empty string |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
340 (or lower |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
341 (setq lower "" |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
342 upper "")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
343 (when (eq (setq token (ebnf-abn-lex)) 'integer) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
344 (setq upper ebnf-abn-lex |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
345 token (ebnf-abn-lex)))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
346 (let ((element (ebnf-abn-element token))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
347 (cond |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
348 ;; there is a repetition |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
349 (lower |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
350 (or element |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
351 (error "Missing element repetition")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
352 (setq token (ebnf-abn-lex)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
353 (cond |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
354 ;; one or more |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
355 ((and (string= lower "1") (null upper)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
356 (cons token (ebnf-make-one-or-more element))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
357 ;; zero or more |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
358 ((or (and (string= lower "0") (null upper)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
359 (and (string= lower "") (string= upper ""))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
360 (cons token (ebnf-make-zero-or-more element))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
361 ;; real repetition |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
362 (t |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
363 (ebnf-token-repeat lower (cons token element) upper)))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
364 ;; there is an element |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
365 (element |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
366 (cons (ebnf-abn-lex) element)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
367 ;; something that caller has to deal |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
368 (t |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
369 (cons token nil)))))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
370 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
371 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
372 ;;; element = rulename / group / option / |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
373 ;;; char-val / num-val / prose-val |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
374 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
375 ;;; group = "(" *c-wsp alternation *c-wsp ")" |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
376 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
377 ;;; option = "[" *c-wsp alternation *c-wsp "]" |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
378 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
379 ;;; char-val = DQUOTE *(%x20-21 / %x23-7E) DQUOTE |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
380 ;;; ; quoted string of SP and VCHAR without DQUOTE |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
381 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
382 ;;; num-val = "%" (bin-val / dec-val / hex-val) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
383 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
384 ;;; bin-val = "b" 1*BIT |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
385 ;;; [ 1*("." 1*BIT) / ("-" 1*BIT) ] |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
386 ;;; ; series of concatenated bit values |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
387 ;;; ; or single ONEOF range |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
388 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
389 ;;; dec-val = "d" 1*DIGIT |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
390 ;;; [ 1*("." 1*DIGIT) / ("-" 1*DIGIT) ] |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
391 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
392 ;;; hex-val = "x" 1*HEXDIG |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
393 ;;; [ 1*("." 1*HEXDIG) / ("-" 1*HEXDIG) ] |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
394 ;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
395 ;;; prose-val = "<" *(%x20-3D / %x3F-7E) ">" |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
396 ;;; ; bracketed string of SP and VCHAR without |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
397 ;;; ; angles |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
398 ;;; ; prose description, to be used as last resort |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
399 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
400 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
401 (defun ebnf-abn-element (token) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
402 (cond |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
403 ;; terminal |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
404 ((eq token 'terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
405 (ebnf-make-terminal ebnf-abn-lex)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
406 ;; non-terminal |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
407 ((eq token 'non-terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
408 (ebnf-make-non-terminal ebnf-abn-lex)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
409 ;; group |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
410 ((eq token 'begin-group) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
411 (let ((body (ebnf-abn-alternation))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
412 (or (eq (car body) 'end-group) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
413 (error "Missing `)'")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
414 (cdr body))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
415 ;; optional |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
416 ((eq token 'begin-optional) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
417 (let ((body (ebnf-abn-alternation))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
418 (or (eq (car body) 'end-optional) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
419 (error "Missing `]'")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
420 (ebnf-token-optional (cdr body)))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
421 ;; no element |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
422 (t |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
423 nil) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
424 )) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
425 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
426 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
428 ;; Lexical analyzer |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
429 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
430 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
431 (defconst ebnf-abn-token-table (make-vector 256 'error) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
432 "Vector used to map characters to a lexical token.") |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
433 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
434 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
435 (defun ebnf-abn-initialize () |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
436 "Initialize EBNF token table." |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
437 ;; control character & control 8-bit character are set to `error' |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
438 (let ((char ?\060)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
439 ;; digits: 0-9 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
440 (while (< char ?\072) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
441 (aset ebnf-abn-token-table char 'integer) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
442 (setq char (1+ char))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
443 ;; printable character: A-Z |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
444 (setq char ?\101) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
445 (while (< char ?\133) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
446 (aset ebnf-abn-token-table char 'non-terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
447 (setq char (1+ char))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
448 ;; printable character: a-z |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
449 (setq char ?\141) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
450 (while (< char ?\173) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
451 (aset ebnf-abn-token-table char 'non-terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
452 (setq char (1+ char))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
453 ;; European 8-bit accentuated characters: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
454 (setq char ?\240) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
455 (while (< char ?\400) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
456 (aset ebnf-abn-token-table char 'non-terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
457 (setq char (1+ char))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
458 ;; Override end of line characters: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
459 (aset ebnf-abn-token-table ?\n 'end-of-rule) ; [NL] linefeed |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
460 (aset ebnf-abn-token-table ?\r 'end-of-rule) ; [CR] carriage return |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
461 ;; Override space characters: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
462 (aset ebnf-abn-token-table ?\013 'space) ; [VT] vertical tab |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
463 (aset ebnf-abn-token-table ?\t 'space) ; [HT] horizontal tab |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
464 (aset ebnf-abn-token-table ?\ 'space) ; [SP] space |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
465 ;; Override form feed character: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
466 (aset ebnf-abn-token-table ?\f 'form-feed) ; [FF] form feed |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
467 ;; Override other lexical characters: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
468 (aset ebnf-abn-token-table ?< 'non-terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
469 (aset ebnf-abn-token-table ?% 'terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
470 (aset ebnf-abn-token-table ?\" 'terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
471 (aset ebnf-abn-token-table ?\( 'begin-group) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
472 (aset ebnf-abn-token-table ?\) 'end-group) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
473 (aset ebnf-abn-token-table ?* 'repeat) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
474 (aset ebnf-abn-token-table ?= 'equal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
475 (aset ebnf-abn-token-table ?\[ 'begin-optional) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
476 (aset ebnf-abn-token-table ?\] 'end-optional) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
477 (aset ebnf-abn-token-table ?/ 'alternative) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
478 ;; Override comment character: |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
479 (aset ebnf-abn-token-table ?\; 'comment))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
480 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
481 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
482 ;; replace the range "\240-\377" (see `ebnf-range-regexp'). |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
483 (defconst ebnf-abn-non-terminal-chars |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
484 (ebnf-range-regexp "-_0-9A-Za-z" ?\240 ?\377)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
485 (defconst ebnf-abn-non-terminal-letter-chars |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
486 (ebnf-range-regexp "A-Za-z" ?\240 ?\377)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
487 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
488 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
489 (defun ebnf-abn-lex () |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
490 "Lexical analyser for ABNF. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
491 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
492 Return a lexical token. |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
493 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
494 See documentation for variable `ebnf-abn-lex'." |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
495 (if (>= (point) ebnf-limit) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
496 'end-of-input |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
497 (let (token) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
498 ;; skip spaces and comments |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
499 (while (if (> (following-char) 255) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
500 (progn |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
501 (setq token 'error) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
502 nil) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
503 (setq token (aref ebnf-abn-token-table (following-char))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
504 (cond |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
505 ((eq token 'space) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
506 (skip-chars-forward " \013\t" ebnf-limit) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
507 (< (point) ebnf-limit)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
508 ((eq token 'comment) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
509 (ebnf-abn-skip-comment)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
510 ((eq token 'form-feed) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
511 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
512 (setq ebnf-action 'form-feed)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
513 ((eq token 'end-of-rule) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
514 (ebnf-abn-skip-end-of-rule)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
515 (t nil) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
516 ))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
517 (cond |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
518 ;; end of input |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
519 ((>= (point) ebnf-limit) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
520 'end-of-input) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
521 ;; error |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
522 ((eq token 'error) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
523 (error "Illegal character")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
524 ;; end of rule |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
525 ((eq token 'end-of-rule) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
526 'end-of-rule) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
527 ;; integer |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
528 ((eq token 'integer) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
529 (setq ebnf-abn-lex (ebnf-buffer-substring "0-9")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
530 'integer) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
531 ;; terminal: "string" or %[bdx]NNN((.NNN)+|-NNN)? |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
532 ((eq token 'terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
533 (setq ebnf-abn-lex |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
534 (if (= (following-char) ?\") |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
535 (ebnf-abn-string) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
536 (ebnf-abn-character))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
537 'terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
538 ;; non-terminal: NAME or <NAME> |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
539 ((eq token 'non-terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
540 (let ((prose-p (= (following-char) ?<))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
541 (when prose-p |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
542 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
543 (or (looking-at ebnf-abn-non-terminal-letter-chars) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
544 (error "Invalid prose value"))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
545 (setq ebnf-abn-lex |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
546 (ebnf-buffer-substring ebnf-abn-non-terminal-chars)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
547 (when prose-p |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
548 (or (= (following-char) ?>) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
549 (error "Invalid prose value")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
550 (setq ebnf-abn-lex (concat "<" ebnf-abn-lex ">")))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
551 'non-terminal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
552 ;; equal: =, =/ |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
553 ((eq token 'equal) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
554 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
555 (if (/= (following-char) ?/) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
556 'equal |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
557 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
558 'incremental-alternative)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
559 ;; miscellaneous: (, ), [, ], /, * |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
560 (t |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
561 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
562 token) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
563 )))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
564 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
565 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
566 (defun ebnf-abn-skip-end-of-rule () |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
567 (let (eor-p) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
568 (while (progn |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
569 ;; end of rule ==> 2 or more consecutive end of lines |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
570 (setq eor-p (or (> (skip-chars-forward "\r\n" ebnf-limit) 1) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
571 eor-p)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
572 ;; skip spaces |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
573 (skip-chars-forward " \013\t" ebnf-limit) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
574 ;; skip comments |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
575 (and (= (following-char) ?\;) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
576 (ebnf-abn-skip-comment)))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
577 (not eor-p))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
578 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
579 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
580 ;; replace the range "\177-\237" (see `ebnf-range-regexp'). |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
581 (defconst ebnf-abn-comment-chars |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
582 (ebnf-range-regexp "^\n\000-\010\016-\037" ?\177 ?\237)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
583 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
584 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
585 (defun ebnf-abn-skip-comment () |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
586 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
587 (cond |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
588 ;; open EPS file |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
589 ((and ebnf-eps-executing (= (following-char) ?\[)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
590 (ebnf-eps-add-context (ebnf-abn-eps-filename))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
591 ;; close EPS file |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
592 ((and ebnf-eps-executing (= (following-char) ?\])) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
593 (ebnf-eps-remove-context (ebnf-abn-eps-filename))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
594 ;; any other action in comment |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
595 (t |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
596 (setq ebnf-action (aref ebnf-comment-table (following-char))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
597 (skip-chars-forward ebnf-abn-comment-chars ebnf-limit)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
598 ) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
599 ;; check for a valid end of comment |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
600 (cond ((>= (point) ebnf-limit) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
601 nil) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
602 ((= (following-char) ?\n) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
603 t) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
604 (t |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
605 (error "Illegal character")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
606 )) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
607 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
608 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
609 (defun ebnf-abn-eps-filename () |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
610 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
611 (ebnf-buffer-substring ebnf-abn-comment-chars)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
612 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
613 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
614 ;; replace the range "\240-\377" (see `ebnf-range-regexp'). |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
615 (defconst ebnf-abn-string-chars |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
616 (ebnf-range-regexp " -!#-~" ?\240 ?\377)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
617 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
618 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
619 (defun ebnf-abn-string () |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
620 (buffer-substring-no-properties |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
621 (progn |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
622 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
623 (point)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
624 (progn |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
625 (skip-chars-forward ebnf-abn-string-chars ebnf-limit) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
626 (or (= (following-char) ?\") |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
627 (error "Missing `\"'")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
628 (prog1 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
629 (point) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
630 (forward-char))))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
631 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
632 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
633 (defun ebnf-abn-character () |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
634 ;; %[bdx]NNN((-NNN)|(.NNN)+)? |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
635 (buffer-substring-no-properties |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
636 (point) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
637 (progn |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
638 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
639 (let* ((char (following-char)) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
640 (chars (cond ((or (= char ?B) (= char ?b)) "01") |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
641 ((or (= char ?D) (= char ?d)) "0-9") |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
642 ((or (= char ?X) (= char ?x)) "0-9A-Fa-f") |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
643 (t (error "Invalid terminal value"))))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
644 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
645 (or (> (skip-chars-forward chars ebnf-limit) 0) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
646 (error "Invalid terminal value")) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
647 (if (= (following-char) ?-) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
648 (progn |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
649 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
650 (or (> (skip-chars-forward chars ebnf-limit) 0) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
651 (error "Invalid terminal value range"))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
652 (while (= (following-char) ?.) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
653 (forward-char) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
654 (or (> (skip-chars-forward chars ebnf-limit) 0) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
655 (error "Invalid terminal value"))))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
656 (point)))) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
657 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
658 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
659 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
660 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
661 |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
662 (provide 'ebnf-abn) |
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
663 |
54141 | 664 ;;; arch-tag: 8d1b3c4d-4226-4393-b9ae-b7ccf07cf779 |
54139
3aff710a91c0
ABNF parser (ebnf2ps)
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
diff
changeset
|
665 ;;; ebnf-abn.el ends here |