1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
# This file is part of GNU Rush.
# Copyright (C) 2019-2024 Sergey Poznyakoff
#
# GNU Rush is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Rush is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Rush. If not, see <http://www.gnu.org/licenses/>.
AT_BANNER([Lexical structure])
m4_pushdef([LEXTEST],
[AT_SETUP([$1])
AT_KEYWORDS([lex])
AT_CHECK(
[rush -T <<'EOT'
$2[]dnl
EOT
],
[0],
[$3])
AT_CLEANUP
])
LEXTEST([identifier],
[rule test
],
[state 2, stdin:1.1-4: 'rule'
state 2, stdin:1.6-9: IDENT test
state 1, stdin:1.10-2: EOL
])
LEXTEST([unquoted string],
[rule /un.quoted,string&()
],
[state 2, stdin:1.1-4: 'rule'
state 2, stdin:1.6-22: STRING "/un.quoted,string"
state 2, stdin:1.23: '&'
state 2, stdin:1.24: '('
state 2, stdin:1.25: ')'
state 1, stdin:1.26-2: EOL
])
LEXTEST([number],
[rule 10
rule +10
rule -10
],
[state 2, stdin:1.1-4: 'rule'
state 2, stdin:1.6-7: NUMBER 10
state 1, stdin:1.8-2: EOL
state 2, stdin:2.1-4: 'rule'
state 2, stdin:2.6-8: NUMBER +10
state 1, stdin:2.9-3: EOL
state 2, stdin:3.1-4: 'rule'
state 2, stdin:3.6-8: NUMBER -10
state 1, stdin:3.9-4: EOL
])
LEXTEST([quoted string],
[rule "input string"
],
[state 2, stdin:1.1-4: 'rule'
state 2, stdin:1.6-19: STRING "input string"
state 1, stdin:1.20-2: EOL
])
LEXTEST([escapes in quoted string],
[rule "simple\btext\040with e\163capes \%3"
],
[state 2, stdin:1.1-4: 'rule'
state 2, stdin:1.6-42: STRING "simple\btext with escapes \\%3"
state 1, stdin:1.43-2: EOL
])
LEXTEST([multiline string],
[rule "multiline\
text\
"
],
[state 2, stdin:1.1-4: 'rule'
state 2, stdin:1.6-3.1: STRING "multiline text"
state 1, stdin:3.2-4: EOL
])
LEXTEST([complex multiline string],
[rule "a \"com\x70lex\r\n\
multiline\"\r\n\
text"
],
[state 2, stdin:1.1-4: 'rule'
state 2, stdin:1.6-3.5: STRING "a \"complex\r\nmultiline\"\r\ntext"
state 1, stdin:3.6-4: EOL
])
LEXTEST([invalid escape sequence],
[rule "bad \&escape"
],
[state 2, stdin:1.1-4: 'rule'
state 2, stdin:1.6-19: STRING "bad \\&escape"
state 1, stdin:1.20-2: EOL
])
LEXTEST([unquoted variable],
[rule $VAR
],
[state 2, stdin:1.1-4: 'rule'
state 2, stdin:1.6-9: STRING "$VAR"
state 1, stdin:1.10-2: EOL
])
LEXTEST([unquoted variable with defaults],
[rule ${VAR:-"string\
\145\x6et ${SUBVAR=:} \"test\""}
],
[state 2, stdin:1.1-4: 'rule'
state 2, stdin:1.6-2.32: STRING "${VAR:-\"string\\145\\x6et ${SUBVAR=:} \\\"test\\\"\"}"
state 1, stdin:2.33-3: EOL
])
|