0 | module Parser.Rule.Package
  1 |
  2 | import public Parser.Lexer.Package
  3 |
  4 | import Data.List1
  5 |
  6 | import Core.Name.Namespace
  7 |
  8 | %default total
  9 |
 10 | public export
 11 | Rule : Type -> Type
 12 | Rule = Grammar () Token True
 13 |
 14 | public export
 15 | EmptyRule : Type -> Type
 16 | EmptyRule = Grammar () Token False
 17 |
 18 | export
 19 | equals : Rule ()
 20 | equals = terminal "Expected equals" $
 21 |                   \case
 22 |                     Equals => Just ()
 23 |                     _ => Nothing
 24 |
 25 | export
 26 | lte : Rule ()
 27 | lte = terminal "Expected <=" $
 28 |                \case
 29 |                  LTE => Just ()
 30 |                  _ => Nothing
 31 |
 32 | export
 33 | gte : Rule ()
 34 | gte = terminal "Expected >=" $
 35 |                \case
 36 |                  GTE => Just ()
 37 |                  _ => Nothing
 38 |
 39 | export
 40 | lt : Rule ()
 41 | lt = terminal "Expected <=" $
 42 |               \case
 43 |                 LT => Just ()
 44 |                 _ => Nothing
 45 |
 46 | export
 47 | gt : Rule ()
 48 | gt = terminal "Expected >=" $
 49 |               \case
 50 |                 GT => Just ()
 51 |                 _ => Nothing
 52 |
 53 | export
 54 | eqop : Rule ()
 55 | eqop = terminal "Expected ==" $
 56 |                 \case
 57 |                   EqOp => Just ()
 58 |                   _ => Nothing
 59 |
 60 | export
 61 | andop : Rule ()
 62 | andop = terminal "Expected &&" $
 63 |                  \case
 64 |                    AndOp => Just ()
 65 |                    _ => Nothing
 66 |
 67 | export
 68 | eoi : Rule ()
 69 | eoi = terminal "Expected end of input" $
 70 |                \case
 71 |                  EndOfInput => Just ()
 72 |                  _ => Nothing
 73 |
 74 | export
 75 | exactProperty : String -> Rule String
 76 | exactProperty p = terminal ("Expected property " ++ p) $
 77 |                            \case
 78 |                              DotSepIdent Nothing p' =>
 79 |                                if p == p' then Just p else Nothing
 80 |                              _ => Nothing
 81 |
 82 | export
 83 | stringLit : Rule String
 84 | stringLit = terminal "Expected string" $
 85 |                      \case
 86 |                        StringLit str => Just str
 87 |                        _ => Nothing
 88 |
 89 | export
 90 | integerLit : Rule Integer
 91 | integerLit = terminal "Expected integer" $
 92 |                       \case
 93 |                         IntegerLit i => Just i
 94 |                         _ => Nothing
 95 |
 96 | export
 97 | namespacedIdent : Rule (Maybe Namespace, String)
 98 | namespacedIdent = terminal "Expected namespaced identifier" $
 99 |                            \case
100 |                              DotSepIdent ns n => Just (ns, n)
101 |                              _ => Nothing
102 |
103 | export
104 | moduleIdent : Rule ModuleIdent
105 | moduleIdent = terminal "Expected module identifier" $
106 |                        \case
107 |                          DotSepIdent ns m =>
108 |                            Just $ nsAsModuleIdent $
109 |                                   mkNestedNamespace ns m
110 |                          _ => Nothing
111 |
112 | export
113 | packageName : Rule String
114 | packageName = terminal "Expected package name" $
115 |                        \case
116 |                          DotSepIdent Nothing str =>
117 |                            if isIdent AllowDashes str
118 |                               then Just str
119 |                               else Nothing
120 |                          _ => Nothing
121 |
122 | export
123 | dot' : Rule ()
124 | dot' = terminal "Expected dot" $
125 |                 \case
126 |                   Dot => Just ()
127 |                   _ => Nothing
128 |
129 | sep' : Rule ()
130 | sep' = terminal "Expected separator" $
131 |                 \case
132 |                   Separator => Just ()
133 |                   _ => Nothing
134 |
135 | export
136 | sep : Rule t -> Rule (List t)
137 | sep rule = forget <$> sepBy1 sep' rule
138 |