Skip to content

Commit

Permalink
fix errors in error printing
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Wilberding <diginux@gmail.com>
  • Loading branch information
ericbmerritt authored and jwilberding committed Feb 17, 2012
1 parent 9bc068a commit 895955f
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/joxa/compiler.jxa
Expand Up @@ -1684,7 +1684,8 @@
(_
(case (intermediate-parse input idx0)
({:fail {:expected expected idx1}}
(add-error-ctx ctx path {:parse-fail expected idx1}))
(add-error-ctx ctx path {:parse-fail expected idx1})
:error)
({intermediate-ast rest idx2}
(case (transform-ast
(traverse-path path)
Expand Down Expand Up @@ -3411,7 +3412,7 @@
(call-macro module function
(runtime-args-to-arity args 1 arity []))))
(_
(add-error-ctx ctx path0 :invalid-definition))))
(add-error-ctx ctx path0 {:invalid-definition-or-macro var}))))
(_
(add-error-ctx ctx path0 :invalid-definition)))))

Expand Down Expand Up @@ -3853,8 +3854,6 @@
(io_lib/format "reference does not exist ~s" [ref]))
({:invalid-reference ref arity}
(io_lib/format "invalid reference ~s/~p" [(format-fun-ref ref) arity]))
({:parse-fail reason {l c}}
(io_lib/format "unable to parse source at ~p:~p ~p" [l c reason]))
({:invalid-use :invalid-fun-spec inv-f}
(io_lib/format "invalid use declaration: invalid function reference (~p)"
[inv-f]))
Expand Down Expand Up @@ -3895,10 +3894,14 @@
"invalid bitstring ")
(:invalid-let-binding
"invalid let binding")
(:no-clauses-provided
"no clauses provided for case statement")
(:invalid-guard
"invalid guard expression")
({:reference-already-defined ref}
(io_lib/format "reference already defined ~s" [(format-fun-ref ref)]))
({:invalid-definition-or-macro name}
(io_lib/format "invalid definition or macro (~s)" [(format-fun-ref name)]))
(:invalid-definition
"invalid definition")
(:invalid-pattern
Expand Down Expand Up @@ -3932,6 +3935,8 @@
(print-erl-errors-or-warnings errors))
({{:system-warnings warnings} _}
(print-erl-errors-or-warnings warnings))
({{:parse-fail expected {line column}} {file-name _}}
(io/format "~s:~p:~p *~p* parsing failed, expected ~p~n" [file-name line column type expected]))
({detail {file-name {line column}}}
(io/format "~s:~p:~p *~p* ~s~n" [file-name line column type (format-detail detail)]))
(msg
Expand Down Expand Up @@ -4004,6 +4009,8 @@
:ok)
(:true
(case (parse ctx input)
(:error
:ok)
({ast0 (= rest {:parse-output _ path _})}
(make-forms (traverse-path path) ctx ast0)
(case (compile-context ctx :intermediate)
Expand Down
71 changes: 71 additions & 0 deletions src/joxa/records.jxa
@@ -0,0 +1,71 @@
;;; The Joxa Core Library
;;; =====================
;;; * author: Eric Merritt
;;; * copyright: Erlware, LLC 2011 - 2012
;;;
;;; Licensed under the Apache License, Version 2.0 you may not use
;;; this file except in compliance with the License. You may obtain a
;;; copy of the License at http://www.apache.org/licenses/LICENSE-2.0
;;;
;;;
;;; This module provides for the definition and abstraction of structs
;;; in joxa.
(module joxa.records
(require (joxa.core :as core)
lists erlang)
(use (erlang :only (+/2
==/2))))

(defn convert-to-record-description (descs)
(case (lists/foldl (fn (desc acc0)
(case acc0
({acc1 count}
(case desc
(d (when (erlang/is_atom d))
{({d count :undefined} . acc1)
(core/incr count)})
({name default}
{({name count default} . acc1)
(core/incr count)})))))
{[], 2} descs)
({acc _}
(lists/reverse acc))))

(defn create-elements (decl descs)
(let (obj (core/gensym)
name (core/gensym)
value (core/gensym))
[`(~decl get-element ( ~obj ~name)
(case ~obj
~@(lists/map (fn (desc)
(case desc
({f-name count _}
`('~f-name
(erlang/element ~count ~obj))))) descs)
(_
(erlang/throw {:invalid-field ~name}))))
`(~decl set-element ( ~obj ~name ~value)
(case ~obj
~@(lists/map (fn (desc)
(case desc
({f-name count _}
`('~f-name
(erlang/setelement ~count ~obj ~value))))) descs)
(_
(erlang/throw {:invalid-field ~name}))))]))

(defn create-record (decl descs)
(let (ells (create-elements decl descs)
; costr (create-constructors decl descs)
; field-info (create-field-info decl descs)
; accessors (create-accessors decl descs)
; t (create-templates decl descs)
; withs (create-withs decl descs)
)
`(do ~@ells)))

(defmacro+ defrecord+ (field-descriptions)
(create-record :defn+ (convert-to-record-description field-descriptions)))

(defmacro+ defrecord (field-descriptions)
(create-record :defn (convert-to-record-description field-descriptions)))
93 changes: 93 additions & 0 deletions test/jxat_records.erl
@@ -0,0 +1,93 @@
-module(jxat_records).

-export([given/3, 'when'/3, then/3]).
-include_lib("eunit/include/eunit.hrl").

given([a,module,that,has,defined,recordss], _State, _) ->
Source1 = <<"
(module jxat-records-def-test)
(defrecords+ my-records (name age {sex male} {address \"unknown\"}))
(defrecords+ other one)
">>,

{ok, Source1};
given([another,module,uses,those,recordss], Source1, _) ->
Source2 = <<"
(module jxat-records-uses-test
(require jxat-records-def-test))
(defn+ create1 ()
{(jxat-records-def-test/my-records
\"Robert\"
1024
:male
\"Somewhere in Ireland\"),
(jxat-records-def-test/my-records
[{:name \"Robert\"}
{:age 1024}
{:sex :male}
{:address \"Somewhere in Ireland\"}])})
(defn+ create2()
{(jxat-records-def-test/other 1)
(jxat-records-def-test/other [{:one 1}])})
(defn+ match1 (one two)
(case one
((jxat-records-def-test/t two [{:name \"Robert\"}])
:matched)
(_
:did-not-match)))
(defn+ match2 (one two)
(case one
((jxat-records-def-test/t two [{:name \"Robert\"}
{:sex :male}])
:matched)
(_
:did-not-match)))
(defn+ match2 (one two)
(case one
((jxat-records-def-test/t two [{:name \"Rob\"}
{:sex :male}])
:matched)
(_
:did-not-match)))
(defn+ with (one)
(jxat-records-def-test/with-fields [{name local-name}
{age local-age}
{address local-address}]
{local-name local-age local-address}))">>,

{ok, {Source1, Source2}}.

'when'([joxa,is,called,on,these,modules], {Source1, Source2}, _) ->
Result1 = joxa.compiler:forms(Source1, []),
Result2 = joxa.compiler:forms(Source2, []),
{ok, {Result1, Result2}}.

then([a,beam,binary,is,produced,for,both], {Ctx1, Ctx2}, _) ->
?assertMatch(true, is_binary(joxa.compiler:'get-context'(result, Ctx1))),
?assertMatch(true, is_binary(joxa.compiler:'get-context'(result, Ctx2))),
?assertMatch(false, joxa.compiler:'has-errors?'(Ctx1)),
?assertMatch(false, joxa.compiler:'has-errors?'(Ctx2)),
{ok, ok};
then([the,described,function,can,be,called,'and',works,correctly], State, _) ->

?assertMatch([{'--joxa-info',1},
{'--joxa-info',2},

{module_info,0},
{module_info,1}],
lists:sort('jxat-records-def-test':module_info(exports))),
{ok, State}.


0 comments on commit 895955f

Please sign in to comment.