tools/PascalUnitSyntaxTree.hs
author unc0rr
Wed, 07 Dec 2011 08:01:18 +0300
changeset 6512 0df7f6697939
parent 6489 e1f0058cfedd
child 6618 2d3232069c4b
permissions -rw-r--r--
"System" unit to help converter
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6467
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
     1
module PascalUnitSyntaxTree where
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
     2
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
     3
import Data.Traversable
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
     4
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
     5
data PascalUnit =
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
     6
    Program Identifier Implementation Phrase
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
     7
    | Unit Identifier Interface Implementation (Maybe Initialize) (Maybe Finalize)
6512
0df7f6697939 "System" unit to help converter
unc0rr
parents: 6489
diff changeset
     8
    | System [TypeVarDeclaration]
6467
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
     9
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    10
data Interface = Interface Uses TypesAndVars
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    11
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    12
data Implementation = Implementation Uses TypesAndVars
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    13
    deriving Show
6489
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
    14
data Identifier = Identifier String BaseType
6467
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    15
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    16
data TypesAndVars = TypesAndVars [TypeVarDeclaration]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    17
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    18
data TypeVarDeclaration = TypeDeclaration Identifier TypeDecl
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    19
    | VarDeclaration Bool ([Identifier], TypeDecl) (Maybe InitExpression)
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    20
    | FunctionDeclaration Identifier TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase))
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    21
    | OperatorDeclaration String Identifier TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase))
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    22
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    23
data TypeDecl = SimpleType Identifier
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    24
    | RangeType Range
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    25
    | Sequence [Identifier]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    26
    | ArrayDecl (Maybe Range) TypeDecl
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    27
    | RecordType [TypeVarDeclaration] (Maybe [[TypeVarDeclaration]])
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    28
    | PointerTo TypeDecl
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    29
    | String Integer
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    30
    | Set TypeDecl
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    31
    | FunctionType TypeDecl [TypeVarDeclaration]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    32
    | UnknownType
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    33
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    34
data Range = Range Identifier
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    35
           | RangeFromTo InitExpression InitExpression
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    36
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    37
data Initialize = Initialize String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    38
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    39
data Finalize = Finalize String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    40
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    41
data Uses = Uses [Identifier]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    42
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    43
data Phrase = ProcCall Reference [Expression]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    44
        | IfThenElse Expression Phrase (Maybe Phrase)
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    45
        | WhileCycle Expression Phrase
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    46
        | RepeatCycle Expression [Phrase]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    47
        | ForCycle Identifier Expression Expression Phrase
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    48
        | WithBlock Reference Phrase
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    49
        | Phrases [Phrase]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    50
        | SwitchCase Expression [([InitExpression], Phrase)] (Maybe [Phrase])
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    51
        | Assignment Reference Expression
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    52
        | NOP
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    53
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    54
data Expression = Expression String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    55
    | BuiltInFunCall [Expression] Reference
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    56
    | PrefixOp String Expression
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    57
    | PostfixOp String Expression
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    58
    | BinOp String Expression Expression
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    59
    | StringLiteral String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    60
    | CharCode String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    61
    | HexCharCode String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    62
    | NumberLiteral String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    63
    | FloatLiteral String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    64
    | HexNumber String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    65
    | Reference Reference
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    66
    | SetExpression [Identifier]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    67
    | Null
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    68
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    69
data Reference = ArrayElement [Expression] Reference
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    70
    | FunCall [Expression] Reference
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    71
    | TypeCast Identifier Expression
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    72
    | SimpleReference Identifier
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    73
    | Dereference Reference
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    74
    | RecordField Reference Reference
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    75
    | Address Reference
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    76
    | RefExpression Expression
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    77
    deriving Show
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    78
data InitExpression = InitBinOp String InitExpression InitExpression
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    79
    | InitPrefixOp String InitExpression
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    80
    | InitReference Identifier
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    81
    | InitArray [InitExpression]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    82
    | InitRecord [(Identifier, InitExpression)]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    83
    | InitFloat String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    84
    | InitNumber String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    85
    | InitHexNumber String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    86
    | InitString String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    87
    | InitChar String
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    88
    | BuiltInFunction String [InitExpression]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    89
    | InitSet [InitExpression]
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    90
    | InitAddress InitExpression
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    91
    | InitNull
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    92
    | InitRange Range
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    93
    | InitTypeCast Identifier InitExpression
090269e528df - Improve parsing of prefix operators
unc0rr
parents:
diff changeset
    94
    deriving Show
6489
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
    95
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
    96
data BaseType = Unknown
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
    97
    | BTChar
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
    98
    | BTString
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
    99
    | BTInt
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
   100
    | BTRecord
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
   101
    | BTArray
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
   102
    | BTFunction
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
   103
    | BTPointerTo BaseType
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
   104
    | BTSet
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
   105
    | BTEnum [String]
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
   106
    | Void
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
   107
    deriving Show
e1f0058cfedd Add base type tags to identifiers
unc0rr
parents: 6467
diff changeset
   108