File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed
Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -53,18 +53,53 @@ static bool parse_str(struct mrsh_parser *parser, const char *str) {
5353 return true;
5454}
5555
56- static size_t peek_literal (struct mrsh_parser * parser ) {
57- size_t i = 0 ;
56+ static int ishexdigit (char c ) {
57+ return isdigit (c ) || (c >= 'A' && c <= 'F' ) || (c >= 'a' && c <= 'f' );
58+ }
59+
60+ static size_t peek_hex_literal (struct mrsh_parser * parser ) {
61+ size_t i = 2 ; // We already know '0x' prefix is there
62+
5863 while (true) {
5964 parser_peek (parser , NULL , i + 1 );
6065
6166 char c = parser -> buf .data [i ];
62- // TODO: 0x, 0b prefixes
67+ if (!ishexdigit (c )) {
68+ break ;
69+ }
70+
71+ ++ i ;
72+ }
73+
74+ return i ;
75+ }
76+
77+ static size_t peek_literal (struct mrsh_parser * parser ) {
78+ size_t i = 0 ;
79+
80+ parser_peek (parser , NULL , 1 );
81+
82+ char c = parser -> buf .data [0 ];
83+ if (c == '0' ) {
84+ ++ i ;
85+ parser_peek (parser , NULL , 2 );
86+
87+ c = parser -> buf .data [1 ];
88+ // TODO: 0b prefix
89+ if (c == 'x' || c == 'X' ) {
90+ return peek_hex_literal (parser );
91+ }
92+ }
93+
94+ while (true) {
6395 if (!isdigit (c )) {
6496 break ;
6597 }
6698
6799 ++ i ;
100+ parser_peek (parser , NULL , i + 1 );
101+
102+ c = parser -> buf .data [i ];
68103 }
69104
70105 return i ;
Original file line number Diff line number Diff line change 11#! /bin/sh -eu
22
33echo " 1 =" $(( 1 ))
4+ echo " 0x0 = " $(( 0x0 ))
5+ echo " 0x100 = " $(( 0x100 ))
6+ echo " 0xabcd = " $(( 0xabcd ))
47echo " 2*5 =" $(( 2 * 5 ))
58echo " 2/5 =" $(( 2 / 5 ))
69echo " 2%5 =" $(( 2 % 5 ))
You can’t perform that action at this time.
0 commit comments