Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

simple DQL parser

  • Loading branch information...
commit 803d2dabfbc4546046c8ca3487290e2acd6e3e89 1 parent c8a4f1b
@mmikulicic authored
Showing with 63 additions and 0 deletions.
  1. +13 −0 src/ast.clj
  2. +50 −0 src/doroty.clj
View
13 src/ast.clj
@@ -0,0 +1,13 @@
+(ns ast)
+
+(defn make-number-lit [n]
+ {:type 'Lit :value n})
+
+(defn make-string-lit [n]
+ {:type 'Lit :value n})
+
+(defn make-reference [n]
+ {:type 'Ref :name n})
+
+(defn make-struct-def [l v]
+ {:type 'StructDef :label l :value v})
View
50 src/doroty.clj
@@ -0,0 +1,50 @@
+(ns doroty
+ (:gen-class)
+ (:use [clarsec]
+ [ast]
+ [de.kotka.monad])
+)
+
+
+(def stringLit
+ (>>== stringLiteral make-string-lit))
+
+(def number
+ (>>== natural make-number-lit))
+
+(def reference
+ (>>== identifier make-reference))
+
+(def structureDef
+ (let-bind [label identifier
+ _ (symb "=")
+ val expression]
+ (result (make-struct-def label val))))
+
+(def structure
+ (brackets (sepBy structureDef comma)))
+
+(def literal
+ (either structure number stringLit reference))
+
+
+
+
+(def predecl
+ (string "undef"))
+
+(def select
+ (string "ugo"))
+
+(def expression
+ literal)
+
+
+(def statement
+ (either predecl select expression))
+
+(def body
+ (endBy statement semi))
+
+(def source
+ (followedBy body (lexeme eof)))
Please sign in to comment.
Something went wrong with that request. Please try again.