#       Mode file for StrongED 4
#
#       Forthmacs environment editor
#       Hanno Schwalm, schwalm@bre.winnet.de
#       Org: Schwalm Forthware

# Note: the next lines should be included in the !StrongED.modewhen file
# Forth
# fff,**.!Forthmacs.**

# Forthmacs - as all Forths - uses ONLY and ALL whitespaces as 'word-limiting'
# characters. ALL other characters belong to a word.
# So I would prefer the ID_ lines to be defined like {'~\x00-\x20\x7F\xa0'}+
# but Icouldn't find out, how to do it and if it's possible.
Search
        _MarkWord       {'~\x00-\x20\x7F\xa0'}+
End

ID_FirstChar    A-Za-z_0-9.:,;\-\_#'\+*~\?\/&%$"!^@|[](){}<>
ID_Middle       A-Za-z_0-9.:,;\-\_#'\+*~\?\/&%$"!^@|[](){}<>


# These seem to be used for defining quote-meanings, there is no real
# use in Forth.
SyntaxOptions
        SingleQuote     No
        DoubleQuote     No
        QuoteQuote      No
        SplitString     No
        HexPrefix       $
        BinPrefix       %
End

# There a 4 Forth comment types available.
# 1-2 The words (s and ( both start comments. These comments can be multiline
# and end at the next available ) character. This character can be anywhere
# in the same file and can be found in ANY character combination
# 3 The word \ begins a comment the comment ends at the end-of-line
# 4 fexit begins a comment, the comment ends at the end-of-file. This is used
# very rarely, so no need to implement.
# So far, Multiline comments 1-2 are not accepted, but this is also almost
# never used in practice
SyntaxComment 1
        Type            Multiline
        StartWith       (
        EndWith         )
End
SyntaxComment 2
        Type            Multiline
        StartWith       (s
        EndWith         )
End

# The first four syntax groups define commoon Forth keywords

# control words
SyntaxWords Group1 EndNonID case
        do ?do loop +loop leave ?leave if else then ?exit exit unnest
        begin until again repeat while
        of case endof endcase 
End

# defining words
SyntaxWords Group2 EndNonID case
        : constant variable create code label nuser auser tuser
        user value locals| 2variable 2constant defer vocabulary
        pointer buffer: field struct task: action: action-name
        mlabel syscall: alias libcall: environment:
End

# conditional compilation words
SyntaxWords Group3 EndNonID case
        needs \needs [ifdef] [else] [then] [ifndef] [if]
        headers headerless headerless0
End

# others
SyntaxWords Group4 EndNonID case
        does> ; ;code end-code c; code[ ]code next return immediate
        decimal hex
End

# all other groups are defined to allow the above comment types.
# So the coloring should be like this:
# Text -    black on white
# Carret -  red on red
# block -   black on grey
# mark -    white on red
# control - red on white
# id -      black on white
# strings - black on white
#   strings can't be safely defined as the syntax varies very much
# comm -    light grey on white
# numbers - black on white
#   numbers can be in any number base so ...
# punct. -  black on white . no use in Forth
# 1 -       lightblue on white
# 2 -       green on white
# 3 -       red on white
# 4 -       orange on white
# 5 -       black on white, this defines non-comment \ combinations
# 6 -       grey on white - comment
# 7 -       black on white, non-comment ( combinations
# 8 -       black on white, non comment (s combinations

SyntaxWords Group5 EndofID case
        \a \b \c \d \e \f \g \h \i \j \k \l \m
        \n \o \p \q \r \s \t \u \v \w \x \y \z
        \A \B \C \D \E \F \G \H \I \J \K \L \M
        \N \O \P \Q \R \S \T \U \V \W \X \Y \Z
        \1 \2 \3 \4 \5 \6 \7 \8 \9 \0 \= \+ \- \_
        \? \! \" \$ \% \* \/ \~ \# \' \( \) \[ \]
        \{ \} \< \> \| \; \: \. \,
End

SyntaxWords Group6 EndofLine
        \
End

SyntaxWords Group7 EndofID case
        (a (b (c (d (e (f (g (h (i (j (k (l (m
        (n (o (p (q (r (t (u (v (w (x (y (z
        (A (B (C (D (E (F (G (H (I (J (K (L (M
        (N (O (P (Q (R (S (T (U (V (W (X (Y (Z
        (1 (2 (3 (4 (5 (6 (7 (8 (9 (0 (= (+ (- (_
        (? (! (" ($ (% (* (/ (~ (# (' (( () ([ (]
        ({ (} (< (> (| (; (: (. (,
End
SyntaxWords Group8 EndofID case
        (sa (sb (sc (sd (se (sf (sg (sh (si (sj (sk (sl (sm
        (sn (so (sp (sq (sr (st (su (sv (sw (sx (sy (sz
        (sA (sB (sC (sD (sE (sF (sG (sH (sI (sJ (sK (sL (sM
        (sN (sO (sP (sQ (sR (sS (sT (sU (sV (sW (sX (sY (sZ
        (s1 (s2 (s3 (s4 (s5 (s6 (s7 (s8 (s9 (s0 (s= (s+ (s- (s_
        (s? (s! (s" (s$ (s% (s* (s/ (s~ (s# (s' (s(s (s) (s[ (s]
        (s{ (s} (s< (s> (s| (s; (s: (s. (s,
End

Functions
        Key     ^H
        Menu    Help Search
        Icon    sm!Help
        Help    Online help about word under cursor
        Select  SetTmp() Run ("Forthmacs:bin.search") DClick ("Forthmacs:docs.html.targetfile")

        Key     ^H
        Menu    Load *.fth
        Icon    save
        Help    Click to load the source file under cursor.
        Select  SetTmp() LoadOne ("Forthmacs:<tmp$word>")

        Key     F10
        Menu    Save & fload      F10
        Icon    Run
        Select  SaveRun ("Forthmacs:bin.run.forth <Tmp$Path>.<Tmp$Leaf>")
        Help    Click to save file and fload it.
End
