diff options
Diffstat (limited to 'src/lang/parser.clj')
-rw-r--r-- | src/lang/parser.clj | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/lang/parser.clj b/src/lang/parser.clj index 7f1337558..d1bd3dbd8 100644 --- a/src/lang/parser.clj +++ b/src/lang/parser.clj @@ -3,7 +3,8 @@ (lang [util :as &util :refer [exec return* return fail fail* repeat-m try-m try-all-m map-m apply-m]] - [lexer :as &lexer]))) + [lexer :as &lexer] + [type :as &type]))) (declare parse-form) @@ -26,6 +27,11 @@ [::&lexer/float ?float] (return [::float (Double/parseDouble ?float)])) +(defn ident->string [ident] + (match ident + [::&lexer/ident ?ident] + ?ident)) + (defparser ^:private parse-ident [::&lexer/ident ?ident] (return [::ident ?ident])) @@ -124,6 +130,26 @@ =call (apply-m parse-form (list ?call))] (return [::dynamic-access =object =call]))) +(defparser ^:private parse-ann-class + [::&lexer/list ([[::&lexer/ident "ann-class"] [::&lexer/ident ?class] & ?decl] :seq)] + (let [[_ class-data] (reduce (fn [[mode data] event] + (match event + [::&lexer/ident "methods"] + [:methods data] + + [::&lexer/ident "fields"] + [:fields data] + + [::&lexer/list ([[::&lexer/ident ":"] [::&lexer/ident ?field-name] [::&lexer/ident ?field-class]] :seq)] + [mode (assoc-in data [mode ?field-name] [::&type/object ?field-class []])] + + [::&lexer/list ([[::&lexer/ident ":"] [::&lexer/ident ?method-name] [::&lexer/list ([[::&lexer/ident "->"] [::&lexer/tuple ?args*] [::&lexer/ident ?return]] :seq)]] :seq)] + [mode (assoc-in data [mode ?method-name] [::&type/fn (map ident->string ?args*) ?return])] + )) + [nil {}] + ?decl)] + (return [::ann-class ?class class-data]))) + (defparser ^:private parse-string [::&lexer/string ?string] (return [::string ?string])) @@ -153,6 +179,7 @@ parse-remove parse-static-access parse-dynamic-access + parse-ann-class parse-fn-call])) ;; [Interface] |