module languages/casl/syntax/Lexical

%% written/changed by Bjarke Wedemeijer (January 1998)
%% adapted by Mark van den Brand (June 1999)
%% adapted by Mark van den Brand (November 2000)
%% adapted by Christian Maeder (January 2002)

exports
  sorts
    Ann
    Number Char
    Literal
    Id Mixfix-Id Simple-Id
    Token-Id
    No-Bracket-Token Place Token 
    Path Url Digit Digits

  aliases
    ~[\n]*                -> Text-Line
    (~[\)]|(")" ~[\%]))*  -> Text-Lines
    [\ \t]*               -> White-Space 

  lexical syntax

    [\ \n\t\13]                    -> LAYOUT
    "%[" (~[\]]|("]" ~[\%]))* "]%" -> LAYOUT

    "%%" Text-Line "\n"            -> Comment-Line
    "%{" (~[\}]|("}" ~[\%]))* "}%" -> Comment-Group

%% Annotations
    "%(" Text-Lines ")%"                                    -> Label 
    "%prec" | "%display"|  "%left_assoc" | "%right_assoc"   -> Annote-Word

    Annote-Word Text-Line "\n"                              -> Annote-Line
    "%floating"|"%number"|"%string"|"%list" Text-Line "\n"  -> Annote-Line
    "%cons" | "%def" | "%implies" White-Space "\n"          -> Annote-Line   

    Annote-Word "(" Text-Lines ")%"                         -> Annote-Group

%% Words, No-Bracket-Sign
    [\192-\207\209-\214\216-\221]             -> Letter  
    [\223-\239\241-\246\248-\253\255]         -> Letter
    [A-Za-z]                                  -> Letter
    [0-9]				      -> Digit
    Digit Digit+			      -> Digits
    Letter | "'" | Digit                      -> Letter-P-D
    Letter-P-D+                               -> Word {avoid}
    Letter Letter-P-D* ("_" Word)*            -> Words 
    "." Words                                 -> Dot-Words

    [\161-\163\167\169\172\176-\179]          -> No-Bracket-Sign
    [\181-\183\185\191\215\247]               -> No-Bracket-Sign
    [\+\-\*\/\\\&\=\<\>\!\?\:\.\$\@\#\^\~\|]  -> No-Bracket-Sign
    No-Bracket-Sign+                          -> No-Bracket-Signs {avoid}

    [\[\]\{\}]                                -> Bracket

    Digit                       -> Number
    Digits			-> Number
    Number "." Number           -> Fraction
    Number "E" [\+\-]? Number   -> Floating
    Fraction "E" [\+\-]? Number -> Floating


    "\\" [01] [0-9] [0-9]      -> Char
    "\\" "2" [0-4] [0-9]       -> Char
    "\\" "2" "5" [0-5]         -> Char
    "\\" "x" [0-9A-F][0-9A-F]  -> Char
    "\\" "o" [0-3] [0-7] [0-7] -> Char
    "\\" [ntrvbfa\?\\\"\']     -> Char
    ~[\0-\31\"\\]              -> Char    
    [\t\n\13]                  -> Char

    "'" Char|[\"] "'"          -> Quoted-Char
    [\"] Char* [\"]            -> String
              
%% The lexical syntax for libraries.
    "%" [0-9a-fA-F] [0-9a-fA-F]                       -> PChar
    [A-Za-z0-9\:\;\=\$\?\+\\\_\@\.\&\!\~\*\"\'\(\)\,] -> PChar
    [\/] PChar*                                       -> PathWords
    PChar* PathWords*                                 -> Path {avoid}
    "http:" Path                                      -> Url {avoid}
    "ftp:" Path                                       -> Url {avoid}
    "file:" Path                                      -> Url {avoid}

  lexical restrictions
    Words -/- 
	[A-Za-z0-9\'\192-\207\209-\214\216-\221\223-\239\241-\246\248-253\255]

    No-Bracket-Signs -/- [\+\-\*\/\\\&\=\<\>\!\?\:\.\$\@\#\^\~\|\161-\163\167\169\172\176-\179\181-\183\185\191\215\247]

  context-free syntax

    ":"   -> No-Bracket-Signs {reject}
    ":?"  -> No-Bracket-Signs {reject}
    "::=" -> No-Bracket-Signs {reject}
    "="   -> No-Bracket-Signs {reject}
    "=>"  -> No-Bracket-Signs {reject}
    "<=>" -> No-Bracket-Signs {reject}
    "."   -> No-Bracket-Signs {reject}
    "·"   -> No-Bracket-Signs {reject}
    "|"   -> No-Bracket-Signs {reject}
    "|->" -> No-Bracket-Signs {reject}
    "/\\" -> No-Bracket-Signs {reject}
    "\\/" -> No-Bracket-Signs {reject}
    "¬"   -> No-Bracket-Signs {reject}

    "and"       -> Words {reject}
    "arch"      -> Words {reject}
    "as"        -> Words {reject}
    "assoc"     -> Words {reject}
    "axiom"     -> Words {reject}
    "axioms"    -> Words {reject}
    "closed"    -> Words {reject}
    "comm"      -> Words {reject}
    "def"       -> Words {reject}
    "else"      -> Words {reject}
    "end"       -> Words {reject}
    "exists"    -> Words {reject}
    "false"     -> Words {reject}
    "fit"       -> Words {reject}
    "forall"    -> Words {reject}
    "free"      -> Words {reject}
    "from"      -> Words {reject}
    "generated" -> Words {reject}
    "get"       -> Words {reject}
    "given"     -> Words {reject}
    "hide"      -> Words {reject}
    "idem"      -> Words {reject}
    "if"        -> Words {reject}
    "in"        -> Words {reject}
    "lambda"    -> Words {reject}
    "library"   -> Words {reject}
    "local"     -> Words {reject}
    "not"       -> Words {reject}
    "op"        -> Words {reject}
    "ops"       -> Words {reject}
    "pred"      -> Words {reject}
    "preds"     -> Words {reject}
    "result"    -> Words {reject}
    "reveal"    -> Words {reject}
    "sort"      -> Words {reject}
    "sorts"     -> Words {reject}
    "spec"      -> Words {reject}
    "then"      -> Words {reject}
    "to"        -> Words {reject}
    "true"      -> Words {reject}
    "type"      -> Words {reject}
    "types"     -> Words {reject}
    "unit"      -> Words {reject}
    "units"     -> Words {reject}
    "var"       -> Words {reject}
    "vars"      -> Words {reject}
    "version"   -> Words {reject}
    "view"      -> Words {reject}
    "when"      -> Words {reject}
    "with"      -> Words {reject}
    "within"    -> Words {reject}

%% Literal
    String   -> Literal
    Digits   -> Literal
    Fraction -> Literal
    Floating -> Literal

%% Simple-Id
    Words -> Simple-Id

%% Id
    Token-Id  -> Id
    Mixfix-Id -> Id

%% Token-Id
    Token -> Token-Id
    Token "[" {Id ","}+ "]"          -> Token-Id 

%% Mixfix-Id
    Token-Id? Place-Token-Id+  -> Mixfix-Id

%% Place-Token-Id
    Place Token-Id? -> Place-Token-Id

%% Place
    "__" -> Place

%% Token
    Words       -> Token
    Signs       -> Token
    Digit       -> Token
    Quoted-Char -> Token
    Dot-Words   -> Token

%% No-Bracket-Token
    Words            -> No-Bracket-Token
    No-Bracket-Signs -> No-Bracket-Token
    Digit            -> No-Bracket-Token
    Quoted-Char      -> No-Bracket-Token
    Dot-Words        -> No-Bracket-Token

%% Signs
    No-Bracket-Signs? Bracket-Signs?  -> Signs

%% Bracket-Signs
    Bracket Signs? -> Bracket-Signs

%% Annotation and Comment
    (Annote-Line|Annote-Group|Label|Comment-Group|Comment-Line)* -> Ann

  context-free restrictions
	LAYOUT? -/- [\ \n\t\13]
