Shorten the module declaration
This commit is contained in:
@ -324,4 +324,126 @@ BEGIN
|
||||
|
||||
RETURN result
|
||||
END parse_variable_part;
|
||||
PROCEDURE parse_constant_declaration(lexer: PLexer): PAstConstantDeclaration;
|
||||
VAR
|
||||
token: LexerToken;
|
||||
result: PAstConstantDeclaration;
|
||||
BEGIN
|
||||
ALLOCATE(result, TSIZE(AstConstantDeclaration));
|
||||
|
||||
token := lexer_current(lexer);
|
||||
result^.constant_name := token.identifierKind;
|
||||
|
||||
token := transpiler_lex(lexer);
|
||||
|
||||
token := transpiler_lex(lexer);
|
||||
result^.constant_value := token.integerKind;
|
||||
|
||||
token := transpiler_lex(lexer);
|
||||
|
||||
RETURN result
|
||||
END parse_constant_declaration;
|
||||
PROCEDURE parse_constant_part(lexer: PLexer): PPAstConstantDeclaration;
|
||||
VAR
|
||||
token: LexerToken;
|
||||
result: PPAstConstantDeclaration;
|
||||
current_declaration: PPAstConstantDeclaration;
|
||||
declaration_count: CARDINAL;
|
||||
BEGIN
|
||||
token := lexer_current(lexer);
|
||||
|
||||
ALLOCATE(result, TSIZE(PAstConstantDeclaration));
|
||||
current_declaration := result;
|
||||
declaration_count := 0;
|
||||
|
||||
IF token.kind = lexerKindConst THEN
|
||||
token := transpiler_lex(lexer);
|
||||
|
||||
WHILE token.kind = lexerKindIdentifier DO
|
||||
INC(declaration_count);
|
||||
|
||||
REALLOCATE(result, TSIZE(PAstConstantDeclaration) * (declaration_count + 1));
|
||||
current_declaration := result;
|
||||
INC(current_declaration, TSIZE(PAstConstantDeclaration) * (declaration_count - 1));
|
||||
|
||||
current_declaration^ := parse_constant_declaration(lexer);
|
||||
token := transpiler_lex(lexer)
|
||||
END
|
||||
END;
|
||||
IF declaration_count <> 0 THEN
|
||||
INC(current_declaration, TSIZE(PAstConstantDeclaration))
|
||||
END;
|
||||
current_declaration^ := NIL;
|
||||
|
||||
RETURN result
|
||||
END parse_constant_part;
|
||||
PROCEDURE parse_import_statement(lexer: PLexer): PAstImportStatement;
|
||||
VAR
|
||||
result: PAstImportStatement;
|
||||
token: LexerToken;
|
||||
symbol_count: CARDINAL;
|
||||
current_symbol: PIdentifier;
|
||||
BEGIN
|
||||
ALLOCATE(result, TSIZE(AstImportStatement));
|
||||
symbol_count := 1;
|
||||
|
||||
token := transpiler_lex(lexer);
|
||||
result^.package := token.identifierKind;
|
||||
|
||||
token := transpiler_lex(lexer);
|
||||
ALLOCATE(result^.symbols, TSIZE(Identifier) * 2);
|
||||
|
||||
current_symbol := result^.symbols;
|
||||
|
||||
token := transpiler_lex(lexer);
|
||||
current_symbol^ := token.identifierKind;
|
||||
|
||||
token := transpiler_lex(lexer);
|
||||
WHILE token.kind <> lexerKindSemicolon DO
|
||||
token := transpiler_lex(lexer);
|
||||
INC(symbol_count);
|
||||
|
||||
REALLOCATE(result^.symbols, TSIZE(Identifier) * (symbol_count + 1));
|
||||
current_symbol := result^.symbols;
|
||||
INC(current_symbol, TSIZE(Identifier) * (symbol_count - 1));
|
||||
|
||||
current_symbol^ := token.identifierKind;
|
||||
token := transpiler_lex(lexer)
|
||||
END;
|
||||
INC(current_symbol, TSIZE(Identifier));
|
||||
MemZero(current_symbol, TSIZE(Identifier));
|
||||
|
||||
token := transpiler_lex(lexer);
|
||||
|
||||
RETURN result
|
||||
END parse_import_statement;
|
||||
PROCEDURE parse_import_part(lexer: PLexer): PPAstImportStatement;
|
||||
VAR
|
||||
token: LexerToken;
|
||||
import_statement: PPAstImportStatement;
|
||||
result: PPAstImportStatement;
|
||||
import_count: CARDINAL;
|
||||
BEGIN
|
||||
token := lexer_current(lexer);
|
||||
ALLOCATE(result, TSIZE(PAstImportStatement));
|
||||
import_statement := result;
|
||||
import_count := 0;
|
||||
|
||||
WHILE token.kind = lexerKindFrom DO
|
||||
INC(import_count);
|
||||
|
||||
REALLOCATE(result, TSIZE(PAstImportStatement) * (import_count + 1));
|
||||
import_statement := result;
|
||||
INC(import_statement, TSIZE(PAstImportStatement) * (import_count - 1));
|
||||
|
||||
import_statement^ := parse_import_statement(lexer);
|
||||
token := lexer_current(lexer)
|
||||
END;
|
||||
IF import_count > 0 THEN
|
||||
INC(import_statement, TSIZE(PAstImportStatement))
|
||||
END;
|
||||
import_statement^ := NIL;
|
||||
|
||||
RETURN result
|
||||
END parse_import_part;
|
||||
END Parser.
|
||||
|
Reference in New Issue
Block a user