From b2f8be605d2b79d1d4b1995646e7058bec299a22 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 12 Jul 2026 23:17:06 +0200 Subject: Add fail_compilation tests --- source/common.elna | 15 ++++++++++++--- source/lexer.elna | 20 +++++++++++++++++--- source/main.elna | 18 ++++++++++++++++-- 3 files changed, 45 insertions(+), 8 deletions(-) (limited to 'source') diff --git a/source/common.elna b/source/common.elna index 7790faf..8bba90f 100644 --- a/source/common.elna +++ b/source/common.elna @@ -2,14 +2,17 @@ v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. *) -import cstring, cstdio +import cstring, cstdio, cstdlib type - Identifier = [256]Char - TextLocation* = record + ElnaLocation* = record line: Word; column: Word end + ElnaPosition* = record + start_location: ElnaLocation; + end_location: ElnaLocation + end proc write*(fd: Int; buf: Pointer; Word: Int): Int extern @@ -69,4 +72,10 @@ begin write_i(cast(value: Int)) end +proc free_and_nil*(pointer: Pointer): Pointer +begin + free(pointer); + return nil +end + end. diff --git a/source/lexer.elna b/source/lexer.elna index 3b015ad..318d740 100644 --- a/source/lexer.elna +++ b/source/lexer.elna @@ -30,7 +30,9 @@ type finish ) ElnaLexerToken* = record - kind: ElnaLexerKind + kind: ElnaLexerKind; + start: String; (* DEPRECATED *) + position: ElnaPosition end ElnaLexerBooleanToken* = record(ElnaLexerToken) value: Bool @@ -44,15 +46,27 @@ type ElnaLexerIntegerToken* = record(ElnaLexerToken) value: Int end + TransitionAction = proc(lexer: ^Lexer; token: ^ElnaLexerToken) + (* DEPRECATED should be replaced with TransitionAction (but keeping the type name). *) + ElnaLexerAction = (none, accumulate, skip, single, eof, finalize, composite, key_id, integer, delimited) + ElnaLexerTransition = record - action: TransitionAction; + action: ElnaLexerAction; next_state: ElnaLexerState end + ElnaLexerCursor = record + state: ElnaLexerState; + start: ^Char; + finish: ^Char; + token: ^ElnaLexerToken; + position: ElnaPosition + end + BufferPosition* = record iterator: ^Char; - location: TextLocation + location: ElnaLocation end Lexer* = record input: ^FILE; diff --git a/source/main.elna b/source/main.elna index 781d681..9a43fb8 100644 --- a/source/main.elna +++ b/source/main.elna @@ -17,7 +17,7 @@ type capacity: Word end SourceCode = record - position: TextLocation; + position: ElnaLocation; input: Pointer; empty: proc(stream: Pointer): Bool; @@ -29,6 +29,11 @@ type data: ^^ElnaLexerToken end +var + stdout: ^FILE + stderr: ^FILE + stdin: ^FILE + (* Standard procedures. *) @@ -826,7 +831,7 @@ begin fclose(source_file^.handle) end; - source_code.position := TextLocation(1u, 1u); + source_code.position := ElnaLocation(1u, 1u); source_code.input := source_file; source_code.empty := source_file_empty; source_code.head := source_file_head; @@ -837,5 +842,14 @@ begin return return_code end +proc initialize_global_state() +begin + stdin := fdopen(0, "r\0".ptr); + stdout := fdopen(1, "w\0".ptr); + stderr := fdopen(2, "w\0".ptr) +end + +begin + initialize_global_state(); return process(count, parameters) end. -- cgit v1.2.3