Debian Codegraph @

src/mod/txt/exp/XTXT001.als

raw
1 # ---------------------------------------------------------------------------
2 # - XTXT001.als -
3 # - afnix:txt module exemple - afnix language scanner -
4 # ---------------------------------------------------------------------------
5 # - This program is free software; you can redistribute it and/or modify -
6 # - it provided that this copyright notice is kept intact. -
7 # - -
8 # - This program is distributed in the hope that it will be useful, but -
9 # - without any warranty; without even the implied warranty of -
10 # - merchantability or fitness for a particular purpose. In no event shall -
11 # - the copyright holder be liable for any direct, indirect, incidental or -
12 # - special damages arising in any way out of the use of this software. -
13 # ---------------------------------------------------------------------------
14 # - copyright (c) 1999-2023 amaury darsch -
15 # ---------------------------------------------------------------------------
16
17 #get the modules
18 interp:library "afnix-txt"
19 interp:library "afnix-sio"
20
21 # create the scanner regex element
22 const REAL (afnix:txt:Pattern "REAL" [[$d+.$d*]|[$d*.$d+]])
23 const REGEX (afnix:txt:Pattern "REGEX" "[" "]" true)
24 const STRING (afnix:txt:Pattern "STRING" "\"" '\\')
25 const CHARACTER (afnix:txt:Pattern "CHARACTER" "'" '\\')
26 const COMMENT (afnix:txt:Pattern "COMMENT" ["#"$E*$e])
27 const SPECIAL (afnix:txt:Pattern "SPECIAL" [<"("")""{""}">])
28 const INTEGER (afnix:txt:Pattern "INTEGER" [[$d+]|[[0x<$x_>+]|[0b<01_>+]]])
29 const LEXICAL (afnix:txt:Pattern "LEXICAL" [$w+])
30 const QUALIFIED (afnix:txt:Pattern "QUALIFIED" [$w+[:$w+]+])
31 const SEPARATOR (afnix:txt:Pattern "SEPARATOR" [<$b$n>+])
32
33 # create a default scanner and add the regex elements
34 const scanner (afnix:txt:Scanner)
35 scanner:add SEPARATOR COMMENT SPECIAL INTEGER REAL REGEX STRING CHARACTER
36 scanner:add LEXICAL QUALIFIED
37
38 # create an input stream
39 const is (afnix:sio:InputFile "XTXT001.als")
40 # loop until we have an eos or a nilp lexeme
41 while (trans valid (is:valid-p)) {
42 trans lexm (scanner:scan is)
43 if (object-p lexm) (println (lexm:get-value))
44 valid:= (and (is:valid-p) (not (nil-p lexm)))
45 }