Skip to content

Commit

Permalink
Initial commit for version Apr 3 17:22:18 UTC 2014 in Hackage
Browse files Browse the repository at this point in the history
Initial version from Hackage by uploaded Thu Apr 3 17:22:18 UTC
2014 by fphh in Hackage.
  • Loading branch information
xie-dongping committed Sep 20, 2015
0 parents commit f681eef
Show file tree
Hide file tree
Showing 49 changed files with 3,896 additions and 0 deletions.
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2013, Heinrich Hördegen

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Heinrich Hördegen nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
111 changes: 111 additions & 0 deletions modelicaparser.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
-- Initial modelicaparser.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/

name: modelicaparser
version: 0.1.0.0
synopsis: A parser for the modelica language
description: According to the Modelica Language Specification 3.3, Apendix B: <https://modelica.org/documents/ModelicaSpec33.pdf>.
The main interface of the parser is in 'Language.Modelica.Parser'. The main entry point to the parser is 'stored_definition'.
license: BSD3
license-file: LICENSE
author: Heinrich Hördegen
maintainer: Heinrich Hördegen <[email protected]>
copyright: Ingenieurbüro Guttenberg & Hördegen <http://www.energiefluss.info>
category: Language
build-type: Simple
cabal-version: >=1.8

data-dir: test/tests

Extra-Source-Files:
caf1.mo
caf2.mo
capacitator.mo
comment2.mo
comment.mo
connector.mo
M.mo
MotorDrive.mo
Pendulum.mo
spatialDistribution.mo
test2.mo
test3.mo
test4.mo
test5.mo
test.mo
ThrowingBall.mo
TwoPin.mo
vehicle.mo
vehicle_parallelHybrid.mo


Flag buildTests
Description: build test suite (makes trouble with TemplateHaskell and dynamic linking)
Default: True



library
build-depends:
base ==4.5.*,
parsec ==3.1.*,
containers ==0.4.*
GHC-Options: -Wall -fwarn-incomplete-uni-patterns -fwarn-tabs
Hs-source-dirs: src
exposed-modules:
Language.Modelica.Parser
Language.Modelica.Parser.Parser
Language.Modelica.Parser.Option
Language.Modelica.Parser.Basic
Language.Modelica.Parser.ClassDefinition
Language.Modelica.Parser.ComponentClause
Language.Modelica.Parser.Equation
Language.Modelica.Parser.Expression
Language.Modelica.Parser.Lexer
Language.Modelica.Parser.Modification
Language.Modelica.Parser.Programme
Language.Modelica.Parser.Utility

Language.Modelica.Syntax.Modelica
Language.Modelica.Syntax.Programme
Language.Modelica.Syntax.ToString

Test-Suite test-parsers
type: exitcode-stdio-1.0
Main-Is: Main.hs
GHC-Options: -Wall -fwarn-incomplete-uni-patterns -fwarn-tabs -fwarn-missing-import-lists
Hs-source-dirs: test
If flag(buildTests)
Build-Depends:
modelicaparser,
base,
containers,
ansi-terminal,
QuickCheck,
parsec
Else
Buildable: False
Other-Modules:
Language.Modelica.Test.Basic
Language.Modelica.Test.ClassDefinition
Language.Modelica.Test.ComponentClause
Language.Modelica.Test.Equation
Language.Modelica.Test.Expression
Language.Modelica.Test.Lexer
Language.Modelica.Test.Modification
Language.Modelica.Test.Programme
Language.Modelica.Test.Utility

Test-Suite test-real-code
type: exitcode-stdio-1.0
Main-Is: Main2.hs
GHC-Options: -Wall -fwarn-incomplete-uni-patterns -fwarn-tabs -fwarn-missing-import-lists
Hs-source-dirs: test
If flag(buildTests)
Build-Depends:
modelicaparser,
base,
containers,
ansi-terminal,
filepath,
parsec
37 changes: 37 additions & 0 deletions src/Language/Modelica/Parser.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@


module Language.Modelica.Parser where


import Language.Modelica.Syntax.Programme
import Language.Modelica.Syntax.Modelica
import Language.Modelica.Syntax.ToString (toString)

import Language.Modelica.Parser.ClassDefinition
import Language.Modelica.Parser.Programme
import Language.Modelica.Parser.Option (OptionSet, defaultOptions)
import Language.Modelica.Parser.Utility (stringParser)

import Text.Parsec.Prim (runP)


commentsAndCode ::
OptionSet -> FilePath -> String -> [TextSegment]
commentsAndCode opts file str =
case runP (stringParser modelica_programme) opts file str of
Right x -> x
Left err -> error (show err)

simple :: FilePath -> String -> StoredDefinition
simple = withOptions defaultOptions

withOptions :: OptionSet -> FilePath -> String -> StoredDefinition
withOptions opts file str =
let txt = concatMap f $ commentsAndCode opts file str
f xs@(Str _) = toString xs
f xs@(Code _) = toString xs
f (LineComment _) = "\n"
f (BlockComment xs) = filter (== '\n') xs
in case runP stored_definition opts file txt of
Right ast -> ast
Left err -> error $ show err
60 changes: 60 additions & 0 deletions src/Language/Modelica/Parser/Basic.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@


module Language.Modelica.Parser.Basic where


import Language.Modelica.Syntax.Modelica

import Language.Modelica.Parser.Parser (Parser)
import Language.Modelica.Parser.Lexer
import Language.Modelica.Parser.Expression


import Text.ParserCombinators.Parsec ((<|>), try, optionMaybe)

import Control.Applicative (liftA, liftA2, liftA3, (<*))



class_prefixes :: Parser ClassPrefixes
class_prefixes = liftA2 ClassPrefixes
(optionMaybe partial_)
( class_
<|> model_
<|> block_
<|> type_
<|> package_
<|> class_prefixes_connector
<|> try class_prefixes_function
<|> try class_prefixes_record
<|> operator_)


class_prefixes_function :: Parser Prefix
class_prefixes_function = liftA2 FunctionPrefix
(optionMaybe (pure_ <|> impure_))
(optionMaybe operatorfunction_ <* function_)

class_prefixes_record :: Parser Prefix
class_prefixes_record =
liftA Record (optionMaybe operatorrecord_ <* record_)

class_prefixes_connector :: Parser Prefix
class_prefixes_connector =
liftA Connector (optionMaybe expandable_ <* connector_)

type_prefix :: Parser TypePrefix
type_prefix = liftA3 TypePrefix
(optionMaybe (flow_ <|> stream_))
(optionMaybe (discrete_ <|> parameter_ <|> constant_))
(optionMaybe (input_ <|> output_))

type_specifier :: Parser Name
type_specifier = name

base_prefix :: Parser BasePrefix
base_prefix = type_prefix

string_comment :: Parser StringComment
string_comment = liftA StringComment $
optionMaybe (liftA2 (,) unicode_string (plusList unicode_string))
Loading

0 comments on commit f681eef

Please sign in to comment.