source: haskell/trunk/ADLParser.hs@ 27

Last change on this file since 27 was 27, checked in by KOBAYASHI, Shinji, 13 years ago

worked on ADLParser

File size: 2.1 KB
Line 
1module ADLParser where
2
3import Text.ParserCombinators.Parsec
4import Text.ParserCombinators.Parsec.Expr
5import Text.ParserCombinators.Parsec.Char
6import Archetype
7
8adl :: Parser Archetype
9adl = many block
10 where
11 block = do version <- try(adlVersion)
12 return version
13 <|> do name <- try(adlName)
14 return name
15 <|> do concept <- try(adlConcept)
16 return concept
17 <|> do language <- try(adlLanguage)
18 return language
19 <|> do description <- try(adlDescription)
20 return description
21 <|> do definition <- try(adlDefinition)
22 return definition
23 <|> do ontology <- try(adlOntology)
24 return ontology
25
26adlVersion :: Parser Version
27adlVersion = do dec1 <- string "archetype (adl_version="
28 ver <- many anyChar
29 end <- char ')'
30 return ver
31
32adlName :: Parser String
33adlName = do spaces
34 name <- many anyChar
35 spaces
36 return name
37
38adlConcept :: Parser Concept
39adlConcept = do spaces
40 head <- string "concept"
41 spaces
42 c1 <- char '['
43 at <- many anyChar
44 c2 <- char ']'
45 spaces
46 c3 <- string "--"
47 desc <- many anyChar
48 end <- char '\r'
49
50 return Concept {at, desc]
51
52adlLanguage :: Parser Language
53adlLanguage = do spaces
54 head <- string "language"
55
56
57
58parseAtoms :: Parser [Atom]
59parseAtoms = many atom
60 where
61 atom :: Parser Atom
62 atom = do spaces
63 name <- string
64 spaces
65 equal <- char '='
66 spaces
67 <|> return []
68
69
70data Language = Original_Laguage String
71 | Translaions [Transpation]
72 deriving Show
73
74data Translation = Symbol String
75 | Language String
76 | Author Author
77
78data Author = Name String
79 | Organisation String
80
81data Atom = Name String
82 | Description String
83
84type Version :: String
Note: See TracBrowser for help on using the repository browser.