Browse Source

Term documentation; Autodoc: parse of external procedures

Arthur Yefimov 2 years ago
parent
commit
d292bd9042
3 changed files with 48 additions and 38 deletions
  1. 9 2
      src/Autodoc/AutodocHtml.Mod
  2. 16 10
      src/Autodoc/AutodocParser.Mod
  3. 23 26
      src/Term.Mod

+ 9 - 2
src/Autodoc/AutodocHtml.Mod

@@ -503,7 +503,9 @@ BEGIN
     WriteLn(')');
     WriteLn('    </span>')
   END;
-  Write   ('    <span class="name">'); Write(p.name);
+  Write('    ');
+  IF p.external THEN Write('-') END;
+  Write('<span class="name">'); Write(p.name);
   Write('</span>'); WriteExport(p); Write('<span class="params">');
   x := p.params.first;
   IF (x # NIL) OR (p.returnType # NIL) THEN Write('(');
@@ -517,7 +519,12 @@ BEGIN
   IF p.returnType # NIL THEN
     Write(': '); PrintType(p.returnType, indent, TRUE)
   END;
-  WriteLn(';</span></div>');
+  Write(';</span>');
+  IF p.external THEN
+    WriteLn(''); Write('<div class="value"><i>&nbsp; ');
+    Write("'"); Write(p.code); Write("'"); WriteLn('</i></div>')
+  END;
+  WriteLn('</div>');
   PrintComment(p.comment, FALSE);
   WriteLn('</article>')
 END PrintProcedure;

+ 16 - 10
src/Autodoc/AutodocParser.Mod

@@ -125,7 +125,9 @@ TYPE
     returnType*: Type;
     params*: List;
     receiver*: Param;
-    modifier*: Str
+    modifier*: Str;
+    code*: Str; (** Code of the procedure as string, when external is TRUE *)
+    external*: BOOLEAN; (* TRUE if has a minus after the word PROCEDURE *)
   END;
 
   Module* = POINTER TO ModuleDesc;
@@ -153,8 +155,7 @@ VAR
   id: ARRAY 256 OF CHAR; (** Identifier read *)
   len: INTEGER; (** Actual length of id *)
 
-  sval: Str; (** String read, when sym = string *)
-  ival: INTEGER;
+  ival: INTEGER; (** Integer value read *)
 
   writingDoc: BOOLEAN; (** TRUE when inside a doc comment *)
   docNewLine: BOOLEAN; (** 0AX reached and no non-spaces after it yet *)
@@ -1374,7 +1375,7 @@ BEGIN
   WHILE sym = procedure DO UpdateCurGroup(M.procedures);
     NEW(P); InitObject(P); SaveComment(P, -1); GetSym; foreign := FALSE;
     forward := FALSE; P.params := NewList(); P.exported := FALSE;
-    P.modifier[0] := 0X;
+    P.external := FALSE; P.modifier[0] := 0X; P.code[0] := 0X;
     IF sym = lparen THEN NEW(P.receiver); InitObject(P.receiver); GetSym;
       NEW(P.receiver.type); InitObject(P.receiver.type);
       IF sym = var THEN GetSym; P.receiver.passed := byVar
@@ -1391,7 +1392,8 @@ BEGIN
       END;
       IF sym = rparen THEN GetSym ELSE MarkExp(')') END
     END;
-    IF (sym = minus) OR (sym = arrow) THEN GetSym; forward := TRUE;
+    IF sym = minus THEN GetSym; P.external := TRUE
+    ELSIF sym = arrow THEN GetSym; forward := TRUE
     ELSIF sym = times THEN GetSym
     END;
     IF sym = ident THEN Strings.Copy(id, P.name); GetSym
@@ -1401,7 +1403,9 @@ BEGIN
     IF sym = times THEN GetSym; P.exported := TRUE END;
     IF sym = lbrak THEN GetSym; (* Foreign name *)
       foreign := TRUE;
-      IF sym = string THEN GetSym ELSE MarkExp('foreign name of procedure') END;
+      IF sym = string THEN GetSym
+      ELSE MarkExp('foreign name of procedure')
+      END;
       IF sym = rbrak THEN GetSym ELSE MarkExp(']') END
     END;
     IF sym = lparen THEN GetSym;
@@ -1414,15 +1418,17 @@ BEGIN
     IF (sym = comma) & (P.receiver # NIL) THEN GetSym;
       IF sym = ident THEN Strings.Copy(id, P.modifier); GetSym END
     END;
-    IF sym = string THEN GetSym END; (* Foreign code *)
+    IF P.external & (sym = string) THEN Strings.Copy(id, P.code); GetSym END;
     IF sym = semicol THEN GetSym ELSE MarkExp(';') END;
-    IF ~forward & ~foreign THEN
+    IF ~forward & ~foreign & ~P.external THEN
       ReachEndOf(P.name); SaveComment(P, -1);
       IF sym = ident THEN GetSym;
         IF sym = semicol THEN GetSym ELSE MarkExp(';') END
       ELSE (* sym = eot *) MarkEnd('Procedure', P.name)
-      END;
-      IF P.exported OR ~exportedOnly THEN AddToList(M.procedures.last(List), P) END
+      END
+    END;
+    IF P.exported OR ~exportedOnly THEN
+      AddToList(M.procedures.last(List), P)
     END
   END
 END ParseProcedureDecl;

+ 23 - 26
src/Term.Mod

@@ -18,38 +18,35 @@ along with Free Oberon.  If not, see <http://www.gnu.org/licenses/>.
 *)
 IMPORT SYSTEM;
 (** Crossplatform Pipe Support
-
-This tiny library is created for crossplatform pipe support. It is needed
-by the virtual terminal of Free Oberon. When a program is being run in
-the IDE, Free Oberon creates a child process and attaches a pipe to its
-stdin and stdout. This way a program may run both in real terminal and
-inside Free Oberon IDE, which itself acts as a terminal emulator.
-
-When you run `./make.sh` or `make.bat` in directory `src`, one of
-the two files is automatically selected for compilation: `term_win32.c`
-or `term_linux.c`:
- * `term_linux.c` is a GNU/Linux version (tested on Debian), it uses fork,
-dup2, execl, fcntl and waitpid.
- * `term_win32.c` is a Windows version, it uses WinAPI (CreateNamedPipeA and
-other functions).
-
-Term.Mod is an Oberon binding for this library, the binding is used
-as a cross-platform module. *)
-
-TYPE CHAR = SHORTCHAR;
+     This tiny library is created for crossplatform pipe support. It is needed
+    by the virtual terminal of Free Oberon. When a program is being run in
+    the IDE, Free Oberon creates a child process and attaches a pipe to its
+    stdin and stdout. This way a program may run both in real terminal and
+    inside Free Oberon IDE, which itself acts as a terminal emulator.
+     When you run `./make.sh` or `make.bat` in directory `src`, one of
+    the two files is automatically selected for compilation: `term_win32.c`
+    or `term_linux.c`:
+     - `term_linux.c` is a GNU/Linux version (tested on Debian, Ubuntu, Mint),
+    it uses fork, dup2, execl, fcntl and waitpid.
+     - `term_win32.c` is a Windows version, it uses WinAPI (CreateNamedPipeA
+    and other functions).
+     Term.Mod is an Oberon binding for this library, the binding is used
+    as a cross-platform module. *)
+
+TYPE CHAR8* = SHORTCHAR;
 
 PROCEDURE -AAIncludeTermh* '#include "term/term.h"';
 
 (** Starts a process with the given path to the executable.
     Returns TRUE process has been started successfully *)
 PROCEDURE -StartProcess*
-  (cmd: ARRAY OF CHAR): BOOLEAN
+  (cmd: ARRAY OF CHAR8): BOOLEAN
   "StartProcessIn(cmd, (char *)0)";
 
 (** Starts a process with the path `cmd` to the executable, but
     starts it from a directory `dir`. Returns TRUE on success *)
 PROCEDURE -StartProcessIn*
-  (cmd, dir: ARRAY OF CHAR): BOOLEAN
+  (cmd, dir: ARRAY OF CHAR8): BOOLEAN
   "StartProcessIn(cmd, dir)";
 
 (** Returns TRUE if the process has finished. In this case puts in `err`
@@ -62,7 +59,7 @@ PROCEDURE -ProcessFinished*(VAR err: INTEGER): BOOLEAN
      The process must first have been started with StartProcess or
     StartProcessIn *)
 PROCEDURE -WriteToProcess*
-  (buf: ARRAY OF CHAR; len: INTEGER)
+  (buf: ARRAY OF CHAR8; len: INTEGER)
   "WriteToProcess(buf, len)";
 
 (** Reads at most `limit` 1-byte characters (bytes) from the standard output
@@ -71,7 +68,7 @@ PROCEDURE -WriteToProcess*
      The process must first have been started with StartProcess or
     StartProcessIn *)
 PROCEDURE -ReadFromProcess*
-  (VAR buf: ARRAY OF CHAR; VAR len: INTEGER; limit: INTEGER)
+  (VAR buf: ARRAY OF CHAR8; VAR len: INTEGER; limit: INTEGER)
   "ReadFromProcess(buf, len, limit)";
 
 (** Starts a process with the given path `cmd` to the executable, waits for
@@ -80,7 +77,7 @@ PROCEDURE -ReadFromProcess*
     exit code of the finished process. Does not add 0X in the end of `buf`.
      Returns 1 on success, 0 on failure. *)
 PROCEDURE -RunProcess*
-  (cmd: ARRAY OF CHAR; VAR buf: ARRAY OF CHAR;
+  (cmd: ARRAY OF CHAR8; VAR buf: ARRAY OF CHAR8;
   limit: INTEGER; VAR len, err: INTEGER): INTEGER
   "(int)RunProcessIn((char *)cmd, (char *)0, (char *)buf, limit, len, err)";
 
@@ -92,7 +89,7 @@ PROCEDURE -RunProcess*
      Returns 1 on success, 0 on failure.
      On Unix/Linux `dir` is ignored *)
 PROCEDURE -RunProcessIn*
-  (cmd, dir: ARRAY OF CHAR; VAR buf: ARRAY OF CHAR;
+  (cmd, dir: ARRAY OF CHAR8; VAR buf: ARRAY OF CHAR8;
   limit: INTEGER; VAR len, err: INTEGER): INTEGER
   "(int)RunProcessIn((char *)cmd, (char *)dir, (char *)buf, limit, len, err)";
 
@@ -101,7 +98,7 @@ PROCEDURE -RunProcessIn*
     on Windows. Returns 1 on success, 0 on failure.
      On Unix/Linux just copies filename to result and returns 1 *)
 PROCEDURE -SearchPath*
-  (filename: ARRAY OF CHAR; VAR result: ARRAY OF CHAR): LONGINT
+  (filename: ARRAY OF CHAR8; VAR result: ARRAY OF CHAR8): LONGINT
   "(int)MySearchPath((char *)filename, (char *)result, result__len)";
 
 END Term.