1 | /* $NetBSD: syntax.c,v 1.1 2004/01/17 17:38:12 dsl Exp $ */
|
---|
2 |
|
---|
3 | #include "shell.h"
|
---|
4 | #include "syntax.h"
|
---|
5 | #include "parser.h"
|
---|
6 |
|
---|
7 | #if CWORD != 0
|
---|
8 | #error initialisation assumes 'CWORD' is zero
|
---|
9 | #endif
|
---|
10 |
|
---|
11 | #define ndx(ch) (ch + 1 - CHAR_MIN)
|
---|
12 | #define set(ch, val) [ndx(ch)] = val,
|
---|
13 | #define set_range(s, e, val) [ndx(s) ... ndx(e)] = val,
|
---|
14 |
|
---|
15 | /* syntax table used when not in quotes */
|
---|
16 | const char basesyntax[257] = { CEOF,
|
---|
17 | set_range(CTL_FIRST, CTL_LAST, CCTL)
|
---|
18 | set('\n', CNL)
|
---|
19 | set('\\', CBACK)
|
---|
20 | set('\'', CSQUOTE)
|
---|
21 | set('"', CDQUOTE)
|
---|
22 | set('`', CBQUOTE)
|
---|
23 | set('$', CVAR)
|
---|
24 | set('}', CENDVAR)
|
---|
25 | set('<', CSPCL)
|
---|
26 | set('>', CSPCL)
|
---|
27 | set('(', CSPCL)
|
---|
28 | set(')', CSPCL)
|
---|
29 | set(';', CSPCL)
|
---|
30 | set('&', CSPCL)
|
---|
31 | set('|', CSPCL)
|
---|
32 | set(' ', CSPCL)
|
---|
33 | set('\t', CSPCL)
|
---|
34 | };
|
---|
35 |
|
---|
36 | /* syntax table used when in double quotes */
|
---|
37 | const char dqsyntax[257] = { CEOF,
|
---|
38 | set_range(CTL_FIRST, CTL_LAST, CCTL)
|
---|
39 | set('\n', CNL)
|
---|
40 | set('\\', CBACK)
|
---|
41 | set('"', CDQUOTE)
|
---|
42 | set('`', CBQUOTE)
|
---|
43 | set('$', CVAR)
|
---|
44 | set('}', CENDVAR)
|
---|
45 | /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
|
---|
46 | set('!', CCTL)
|
---|
47 | set('*', CCTL)
|
---|
48 | set('?', CCTL)
|
---|
49 | set('[', CCTL)
|
---|
50 | set('=', CCTL)
|
---|
51 | set('~', CCTL)
|
---|
52 | set(':', CCTL)
|
---|
53 | set('/', CCTL)
|
---|
54 | set('-', CCTL)
|
---|
55 | };
|
---|
56 |
|
---|
57 | /* syntax table used when in single quotes */
|
---|
58 | const char sqsyntax[257] = { CEOF,
|
---|
59 | set_range(CTL_FIRST, CTL_LAST, CCTL)
|
---|
60 | set('\n', CNL)
|
---|
61 | set('\'', CSQUOTE)
|
---|
62 | /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
|
---|
63 | set('!', CCTL)
|
---|
64 | set('*', CCTL)
|
---|
65 | set('?', CCTL)
|
---|
66 | set('[', CCTL)
|
---|
67 | set('=', CCTL)
|
---|
68 | set('~', CCTL)
|
---|
69 | set(':', CCTL)
|
---|
70 | set('/', CCTL)
|
---|
71 | set('-', CCTL)
|
---|
72 | };
|
---|
73 |
|
---|
74 | /* syntax table used when in arithmetic */
|
---|
75 | const char arisyntax[257] = { CEOF,
|
---|
76 | set_range(CTL_FIRST, CTL_LAST, CCTL)
|
---|
77 | set('\n', CNL)
|
---|
78 | set('\\', CBACK)
|
---|
79 | set('`', CBQUOTE)
|
---|
80 | set('\'', CSQUOTE)
|
---|
81 | set('"', CDQUOTE)
|
---|
82 | set('$', CVAR)
|
---|
83 | set('}', CENDVAR)
|
---|
84 | set('(', CLP)
|
---|
85 | set(')', CRP)
|
---|
86 | };
|
---|
87 |
|
---|
88 | /* character classification table */
|
---|
89 | const char is_type[257] = { 0,
|
---|
90 | set_range('0', '9', ISDIGIT)
|
---|
91 | set_range('a', 'z', ISLOWER)
|
---|
92 | set_range('A', 'Z', ISUPPER)
|
---|
93 | set('_', ISUNDER)
|
---|
94 | set('#', ISSPECL)
|
---|
95 | set('?', ISSPECL)
|
---|
96 | set('$', ISSPECL)
|
---|
97 | set('!', ISSPECL)
|
---|
98 | set('-', ISSPECL)
|
---|
99 | set('*', ISSPECL)
|
---|
100 | set('@', ISSPECL)
|
---|
101 | };
|
---|