Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use the java AST, fix parser ast creation

  • Loading branch information...
commit 33a3422b2a31c07f8b6db1dcecf2ccd05087ac1b 1 parent 3da79d4
@mmikulicic authored
Showing with 29 additions and 17 deletions.
  1. +18 −12 src/eu/dnetlib/dlms/ast.clj
  2. +11 −5 src/eu/dnetlib/dlms/parser.clj
View
30 src/eu/dnetlib/dlms/ast.clj
@@ -1,8 +1,11 @@
(ns eu.dnetlib.dlms.ast
(:import (eu.dnetlib.dlms.jdbc.ast
- Assign BinaryPredicate Call DeclInit Expression Inst Lit NumberLit Predicate Ref RunExpr Select SimplePredicate StringLit Struct XPathComponent XPathExpr XPath
+ Assign BinaryPredicate Call DeclInit Expression Inst Lit NumberLit Predicate Ref RunExpr Select SimplePredicate StringLit Struct
+ StructKeyValue XPathComponent XPathExpr XPath
)))
+(defn make-run-expr [e]
+ (new RunExpr e))
(defn make-number-lit [n]
(new NumberLit n))
@@ -13,35 +16,38 @@
(defn make-reference [n]
(new Ref n))
+(defn make-struct [defs]
+ (new Struct defs))
+
(defn make-struct-def [l v]
- {:type 'StructDef :label l :value v})
+ (new StructKeyValue l v))
(defn make-instantiation [set args]
- {:type 'Inst :set set :args args})
+ (new Inst set args))
(defn make-call [target method args]
- {:type 'Call :target target :method method :args args})
+ (new Call target method args))
(defn make-select [fields xp]
- {:type 'Select :fields fields :xpath xp})
+ (new Select fields xp))
(defn make-xpath [comps]
- {:type 'XPath :components comps})
+ (new XPath comps))
(defn make-tagexp [axis tag pred]
- {:type 'XPathComponent :axis axis :tag tag :pred pred})
+ (new XPathComponent tag pred axis))
(defn make-simple-predicate [xp]
- {:type 'SimplePredicate :xpath xp})
+ (new SimplePredicate xp))
(defn make-binary-predicate [op xp expr]
- {:type 'BinaryPredicate :op op :xpath xp :expression expr})
+ (new BinaryPredicate op xp expr))
(defn make-xpath-expression [ex]
- {:type 'XPathPredicate :expression ex})
+ (new XPathExpr ex))
(defn make-decl-init [typ name e]
- {:type 'DeclInit :type typ :name name :expression e})
+ (new DeclInit typ name e))
(defn make-assign [name e]
- {:type 'Assign :name name :expression e})
+ (new Assign name e))
View
16 src/eu/dnetlib/dlms/parser.clj
@@ -13,7 +13,10 @@
(def expression
- (delay (either instantiation invocation literal)))
+ (delay (either
+ instantiation
+ invocation
+ literal)))
(def stringLit
(>>== stringLiteral make-string-lit))
@@ -31,7 +34,8 @@
(result (make-struct-def label val))))
(def structure
- (brackets (sepBy structureDef comma)))
+ (>>== (brackets (sepBy structureDef comma))
+ make-struct))
(def literal
(either structure number stringLit reference))
@@ -80,7 +84,7 @@
(delay
(let-bind [xp xpath
op (symb "=")
- expr (either (>>== expression make-xpath-expression) xpath)]
+ expr (either xpath (>>== expression make-xpath-expression))]
(result (make-binary-predicate op xp expr)))))
(def predicate (delay (either binaryPredicate (>>== xpath make-simple-predicate))))
@@ -109,7 +113,9 @@
(result (make-select fields xp))))
(def statement
- (either predecl select expression))
+ (either predecl
+ select
+ (>>== expression make-run-expr)))
(def body
(followedBy (sepBy1 statement semi) (optional semi)))
@@ -120,5 +126,5 @@
(defn -main []
(println (parse source "1")))
-(defn -parse [strn]
+(defn -parse [this strn]
(:value (parse source strn)))
Please sign in to comment.
Something went wrong with that request. Please try again.