mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Separate multiple instructions per line with :: (#1210)
This commit is contained in:
@@ -1759,11 +1759,8 @@ static int yylex_SKIP_TO_ENDC(void); // forward declaration for yylex_NORMAL
|
||||
|
||||
static int yylex_NORMAL(void)
|
||||
{
|
||||
uint32_t num = 0;
|
||||
|
||||
for (;;) {
|
||||
int c = nextChar();
|
||||
char secondChar;
|
||||
|
||||
switch (c) {
|
||||
// Ignore whitespace and comments
|
||||
@@ -1910,15 +1907,19 @@ static int yylex_NORMAL(void)
|
||||
return T_OP_LOGICGT;
|
||||
}
|
||||
|
||||
// Handle colon, which may begin an anonymous label ref
|
||||
|
||||
case ':':
|
||||
case ':': // Either :, ::, or an anonymous label ref
|
||||
c = peek();
|
||||
if (c != '+' && c != '-')
|
||||
switch (c) {
|
||||
case ':':
|
||||
shiftChar();
|
||||
return T_DOUBLE_COLON;
|
||||
case '+':
|
||||
case '-':
|
||||
readAnonLabelRef(c);
|
||||
return T_ANON;
|
||||
default:
|
||||
return T_COLON;
|
||||
|
||||
readAnonLabelRef(c);
|
||||
return T_ANON;
|
||||
}
|
||||
|
||||
// Handle numbers
|
||||
|
||||
@@ -1931,36 +1932,37 @@ static int yylex_NORMAL(void)
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
num = readNumber(10, c - '0');
|
||||
case '9': {
|
||||
uint32_t n = readNumber(10, c - '0');
|
||||
|
||||
if (peek() == '.') {
|
||||
shiftChar();
|
||||
yylval.constValue = readFractionalPart(num);
|
||||
} else {
|
||||
yylval.constValue = num;
|
||||
n = readFractionalPart(n);
|
||||
}
|
||||
yylval.constValue = n;
|
||||
return T_NUMBER;
|
||||
}
|
||||
|
||||
case '&': // Either &=, binary AND, logical AND, or an octal constant
|
||||
secondChar = peek();
|
||||
if (secondChar == '=') {
|
||||
c = peek();
|
||||
if (c == '=') {
|
||||
shiftChar();
|
||||
return T_POP_ANDEQ;
|
||||
} else if (secondChar == '&') {
|
||||
} else if (c == '&') {
|
||||
shiftChar();
|
||||
return T_OP_LOGICAND;
|
||||
} else if (secondChar >= '0' && secondChar <= '7') {
|
||||
} else if (c >= '0' && c <= '7') {
|
||||
yylval.constValue = readNumber(8, 0);
|
||||
return T_NUMBER;
|
||||
}
|
||||
return T_OP_AND;
|
||||
|
||||
case '%': // Either %=, MOD, or a binary constant
|
||||
secondChar = peek();
|
||||
if (secondChar == '=') {
|
||||
c = peek();
|
||||
if (c == '=') {
|
||||
shiftChar();
|
||||
return T_POP_MODEQ;
|
||||
} else if (secondChar == binDigits[0] || secondChar == binDigits[1]) {
|
||||
} else if (c == binDigits[0] || c == binDigits[1]) {
|
||||
yylval.constValue = readBinaryNumber();
|
||||
return T_NUMBER;
|
||||
}
|
||||
|
||||
@@ -542,7 +542,7 @@ enum {
|
||||
|
||||
%token T_PERIOD "."
|
||||
%token T_COMMA ","
|
||||
%token T_COLON ":"
|
||||
%token T_COLON ":" T_DOUBLE_COLON "::"
|
||||
%token T_LBRACK "[" T_RBRACK "]"
|
||||
%token T_LPAREN "(" T_RPAREN ")"
|
||||
%token T_NEWLINE "newline"
|
||||
@@ -817,7 +817,7 @@ else : T_POP_ELSE T_NEWLINE {
|
||||
;
|
||||
|
||||
plain_directive : label
|
||||
| label cpu_command
|
||||
| label cpu_commands
|
||||
| label macro
|
||||
| label directive
|
||||
| assignment_directive
|
||||
@@ -844,7 +844,9 @@ redef_id : T_POP_REDEF {
|
||||
}
|
||||
;
|
||||
|
||||
scoped_id : T_ID | T_LOCAL_ID;
|
||||
// T_LABEL covers identifiers followed by a double colon (e.g. `call Function::ret`,
|
||||
// to be read as `call Function :: ret`). This should not conflict with anything.
|
||||
scoped_id : T_ID | T_LOCAL_ID | T_LABEL;
|
||||
scoped_anon_id : scoped_id | T_ANON;
|
||||
|
||||
label : %empty
|
||||
@@ -860,11 +862,11 @@ label : %empty
|
||||
| T_LABEL T_COLON {
|
||||
sym_AddLabel($1);
|
||||
}
|
||||
| T_LOCAL_ID T_COLON T_COLON {
|
||||
| T_LOCAL_ID T_DOUBLE_COLON {
|
||||
sym_AddLocalLabel($1);
|
||||
sym_Export($1);
|
||||
}
|
||||
| T_LABEL T_COLON T_COLON {
|
||||
| T_LABEL T_DOUBLE_COLON {
|
||||
sym_AddLabel($1);
|
||||
sym_Export($1);
|
||||
}
|
||||
@@ -1776,6 +1778,9 @@ sectattrs : %empty {
|
||||
}
|
||||
;
|
||||
|
||||
cpu_commands : cpu_command
|
||||
| cpu_command T_DOUBLE_COLON cpu_commands
|
||||
;
|
||||
|
||||
cpu_command : z80_adc
|
||||
| z80_add
|
||||
|
||||
Reference in New Issue
Block a user