]> Nishi Git Mirror - gwion.git/commitdiff
:art: Fix build
authorJérémie Astor <fennecdjay@gmail.com>
Mon, 17 May 2021 00:56:11 +0000 (02:56 +0200)
committerJérémie Astor <fennecdjay@gmail.com>
Mon, 17 May 2021 00:56:11 +0000 (02:56 +0200)
scripts/nanorc.sh [new file with mode: 0644]
src/parse/check.c
tests/effects/ctor_effects.gw [new file with mode: 0644]
tests/effects/effect_overload.gw [new file with mode: 0644]
tests/effects/funptr_eff.gw [new file with mode: 0644]
tests/pp/recursive_macro.gw [new file with mode: 0644]
tests/ref/noret.gw [new file with mode: 0644]
tests/regression/recursive_type.gw [new file with mode: 0644]

diff --git a/scripts/nanorc.sh b/scripts/nanorc.sh
new file mode 100644 (file)
index 0000000..909cc3e
--- /dev/null
@@ -0,0 +1,151 @@
+cat << EOC
+## Gwion config for GNU nano
+##
+
+syntax "gwion" "\.gw"
+
+formatter gwion-nano-fmt
+linter gwion -g check
+EOC
+
+scope=0
+while read -r line
+do
+#  echo "$line"
+  comment="$(sed 's/ *#!.*//' <<< "$line")"
+  if [ "$comment" != "$line" ]
+  then continue
+  fi
+  if [ "$(grep operator <<< "$line")" ]
+  then continue
+  fi
+  primitive="$(sed 's/^ *primitive *\([a-zA-Z][a-zA-Z0-9_]*\).*/\1/' <<< "$line")"
+  if [ "$primitive" != "$line" ]
+  then
+    echo "color bold,mauve \"\<${primitive}\>\""
+    continue
+  fi
+  class="$(sed 's/^ *class *\([a-zA-Z][a-zA-Z0-9_]*\).*/\1/' <<< "$line")"
+  if [ "$class" != "$line" ]
+  then
+    echo "color mauve \"\<${class}\>\""
+    scope=$((scope+1))
+    continue
+  fi
+  struct="$(sed 's/^ *struct *\([a-zA-Z][a-zA-Z0-9_]*\).*/\1/' <<< "$line")"
+  if [ "$struct" != "$line" ]
+  then
+    echo "color mauve \"\<${struct}\>\""
+    scope=$((scope+1))
+    continue
+  fi
+  enum="$(sed 's/^ *enum *\([a-zA-Z][a-zA-Z0-9_]*\).*/\1/' <<< "$line")"
+  if [ "$enum" != "$line" ]
+  then
+    echo "color italic,mauve \"\<${enum}\>\""
+    scope=$((scope+1))
+    continue
+  fi
+  fun="$(sed 's/^ *fun *[a-zA-Z][a-zA-Z0-9_]* *\([a-zA-Z][a-zA-Z0-9_]*\).*/\1/' <<< "$line")"
+  if [ "$fun" != "$line" ]
+  then
+    if [ $scope -eq 0 ]
+    then echo "color mint \"\<${fun}\>\""
+    else echo "color mint \".\<${fun}\>\""
+    fi
+    if [ "${line: -1}" != ";" ]
+    then scope=$((scope+1))
+    fi
+    continue
+  fi
+  funptr="$(sed 's/^ *funptr *[a-zA-Z][a-zA-Z0-9_]* *\([a-zA-Z][a-zA-Z0-9_]*\).*/\1/' <<< "$line")"
+  if [ "$funptr" != "$line" ]
+  then
+    echo "color italic,mint \"\<${funptr}\>\""
+    continue
+  fi
+  typedef="$(sed 's/^ *typedef *[a-zA-Z][a-zA-Z0-9_]* *\([a-zA-Z][a-zA-Z0-9_]*\).*/\1/' <<< "$line")"
+  if [ "$typedef" != "$line" ]
+  then
+    echo "color italic,mauve \"\<${typedef}\>\""
+    continue
+  fi
+  ignoreconstspid="$(sed 's/^ *specialid const *@\([a-zA-Z_][a-zA-Z0-9_]*\).*/\1/' <<< "$line")"
+  if [ "$ignoreconstspid" != "$line" ]
+  then
+    continue
+  fi
+  ignorespid="$(sed 's/^ *specialid *@\([a-zA-Z_][a-zA-Z0-9_]*\).*/\1/' <<< "$line")"
+  if [ "$ignorespid" != "$line" ]
+  then
+    continue
+  fi
+  constspid="$(sed 's/^ *specialid *const *\([a-zA-Z_][a-zA-Z0-9_]*\).*/\1/' <<< "$line")"
+  if [ "$constspid" != "$line" ]
+  then
+    echo "color italic,lightyellow \"\<${constspid}\>\""
+    continue
+  fi
+  spid="$(sed 's/^ *specialid *\([a-zA-Z_][a-zA-Z0-9_]*\).*/\1/' <<< "$line")"
+  if [ "$spid" != "$line" ]
+  then
+    echo "color lightyellow \"\<${spid}\>\""
+    continue
+  fi
+  lbrace="$(sed 's/^ *{.*$/@smth/' <<< "$line")"
+  if [ "$lbrace" != "$line" ]
+  then
+    scope=$((scope+1))
+    continue
+  fi
+  rbrace="$(sed 's/^ *}.*$/@smth/' <<< "$line")"
+  if [ "$lbrace" != "$line" ]
+  then scope=$((scope-1))
+    continue
+  fi
+# misses items rn
+done < $1
+
+cat << EOC
+comment "#!"
+
+color italic,red start="#\<(pragma|include|define|ifdef|ifndef|undef|endif|require)\>" end="\$"
+
+color brightred "\<(typeof|spork|fork)\>"
+color lightred "\<(second|ms|day|samp|minute|hour)\>"
+color brightcyan "\<(maybe)\>"
+color cyan "\<(adc|blackhole)\>"
+
+color brightgreen "\<(try|handle|perform|retry|class|struct|trait|union|enum|fun|operator|funptr|typedef|distinct)\>"
+color italic,yellow "extends"
+color italic,brightgreen "\<(final|abstract)\>"
+color lightgreen "@[a-zA-Z]+[a-zA-Z0-9_]*|&[a-zA-Z]+[a-zA-Z0-9_]*"
+color green "\<(static|global)\>"
+color italic,green "\<(protected|private)\>"
+color bold,green "\<(var|late|const)\>"
+color bold,italic,green "\<(const)\>"
+
+color bold,yellow "\<(for|until|if|while|do|else|match|case|when|where|defer)\>"
+color magenta "\<(goto|continue|break|return)\>"
+
+## Comment highlighting
+color italic,lightblue start="#!" end="\$|!#"
+
+color white "\?|:|$||\+|\-||\*|/|%|~|^|&|!||^|@|=|<|>|\+"
+
+color pink "\<(\.[0-9]([0-9]*)|[0-9]+(\.)*)\>"
+
+#String highlighting.  You will in general want your comments and
+## strings to come last, because syntax highlighting rules will be
+## applied in the order they are read in.
+#color brightyellow "(\\.|[^"])*""
+##
+## This string is VERY resource intensive!
+#color italic,brightyellow start=""(\\.|[^"])*\\[[:space:]]*$" end="^(\\.|[^"])*""
+color italic,brightyellow start="\"" end="\""
+color italic,lightyellow start="\`" end="\`"
+
+## Trailing whitespace
+color ,green "[[:space:]]+\$"
+EOC
+
index 39dd52e7942f7d69840d706201a86c32ac6fa5d5..14ede8f49bdb7ae608af185b292d538c63b77851 100644 (file)
@@ -948,15 +948,13 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) {
     const Exp when = cpy_exp(env->gwion->mp, tdef->when);
     when->next = helper;
     const Stmt stmt = new_stmt_exp(env->gwion->mp, ae_stmt_exp, when, when->pos);
-//    const Stmt stmt_return = new_stmt_exp(env->gwion->mp, ae_stmt_return, new_prim_id(env->gwion->mp, insert_symbol("self"), when->pos), when->pos);
-//    const Stmt_List ret_list = new_stmt_list(env->gwion->mp, stmt_return, NULL);//ret_list);
     const Stmt_List body = new_stmt_list(env->gwion->mp, stmt, NULL);//ret_list);
     const Stmt code = new_stmt_code(env->gwion->mp, body, when->pos);
     const Func_Def fdef = new_func_def(env->gwion->mp, fb, code);
     CHECK_BB(traverse_func_def(env, fdef));
     const Exp predicate = stmt->d.stmt_exp.val;
     if(isa(predicate->type, env->gwion->type[et_bool]) < 0) {
-      char explain[strlen(predicate->type->name) + 7];
+      char explain[strlen(predicate->type->name) + 20];
       sprintf(explain, "found `{/+}%s{0}`", predicate->type->name);
       gwerr_basic("Invalid `{/+}when{0}` predicate expression type", explain, "use `{/+}bool{0}`",
         env->name, when->pos, 0);
diff --git a/tests/effects/ctor_effects.gw b/tests/effects/ctor_effects.gw
new file mode 100644 (file)
index 0000000..bded302
--- /dev/null
@@ -0,0 +1,6 @@
+#! [contains] Unhandled SomeEffect
+class C {
+  perform SomeEffect;
+}
+
+const C c;
diff --git a/tests/effects/effect_overload.gw b/tests/effects/effect_overload.gw
new file mode 100644 (file)
index 0000000..0b23a6d
--- /dev/null
@@ -0,0 +1,7 @@
+#! [contains] too much effects in override
+class C {
+  fun void test() {}
+}
+class D extends C {
+  fun void test() { perform Stuff; }
+}
diff --git a/tests/effects/funptr_eff.gw b/tests/effects/funptr_eff.gw
new file mode 100644 (file)
index 0000000..d63774a
--- /dev/null
@@ -0,0 +1,10 @@
+#! [contains] no match found
+funptr void test_t(int)
+  perform SomeEffect;
+
+fun void myfunc(int i) {
+  perform Test;
+}
+
+myfunc @=> const test_t t;
+t(2);
diff --git a/tests/pp/recursive_macro.gw b/tests/pp/recursive_macro.gw
new file mode 100644 (file)
index 0000000..cd17a22
--- /dev/null
@@ -0,0 +1,4 @@
+#define macro1(a) macro3(a)
+#define macro2(a) macro1(a)
+#define macro3(a) macro2(a)
+macro3(a);
diff --git a/tests/ref/noret.gw b/tests/ref/noret.gw
new file mode 100644 (file)
index 0000000..cca8fae
--- /dev/null
@@ -0,0 +1,6 @@
+#! [contains] Can't use type
+fun &int test(&int i) {
+  return i;
+}
+var int i;
+<<< test(i) >>>;
diff --git a/tests/regression/recursive_type.gw b/tests/regression/recursive_type.gw
new file mode 100644 (file)
index 0000000..115ce90
--- /dev/null
@@ -0,0 +1,9 @@
+#! [contains] recursive type
+class C {
+  var D d;
+}
+class D {
+  var C c;
+}
+
+<<< new D >>>;