aboutsummaryrefslogtreecommitdiff
path: root/source/main.elna
blob: 945e2e648ece4b02ef7a523f35de3bb359c6f6df (plain)
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
(* This Source Code Form is subject to the terms of the Mozilla Public License,
  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/. *)
program()
import sys.ffi, sys.posix.stdio, sys.posix.stdlib, std,
  elna.lexer, elna.ast, elna.parser, elna.source

var
  sample_source_text := "rogram() Here.a few (* documentation block *) or #size if '\\n' `У` \"некоторая строка\" 23 -- End line comment\0"

begin
  elna_lexer_transitions();

  block local_main
  var
    lexer_cursor := elna_lexer_cursor_make(sample_source_text)
    parser := elna_parser_make(@lexer_cursor)
    tree := elna_parser_program(@parser)
    writer := { ElnaSourceStdioWriter; stream: stderr_(), sink: @elna_source_stdio_writer_sink }
  begin
    if std_slist_empty(@parser.diagnostics) then
      fputs("int main(){ return 0; }\n\0".ptr, stdout_());

      exit(cast(0: CInt))
    else
    var
      current_entry := parser.diagnostics.head.value
      current_token := parser.current
    begin
      repeat
        elna_source_diagnostic_print(current_entry^.value, @writer);

        current_entry := current_entry^.next
      until current_entry = parser.diagnostics.head.value;

      while current_token.value^.kind <> ElnaLexerTokenKind.eof do
        elna_lexer_token_dump(current_token.value, stderr_(), @writer);
        current_token := elna_lexer_lex(@lexer_cursor)
      end;

      exit(cast(1: CInt))
    end
  end
end.