Browse Source

throw exceptions on demand

IPS-67
Volker Birk 3 months ago
parent
commit
b82b5250e2
3 changed files with 50 additions and 3 deletions
  1. +2
    -0
      .gitignore
  2. +3
    -0
      src/Makefile
  3. +45
    -3
      src/gen_cs.ysl2

+ 2
- 0
.gitignore View File

@ -166,6 +166,8 @@ src/transport_status_code.h
src/transport_status_code.c
src/TransportStatusCode.kt
src/TransportStatusCode.cs
src/*.xml
src/*.xsl
# Local configuration
src/local.conf


+ 3
- 0
src/Makefile View File

@ -27,6 +27,9 @@ TransportStatusCode.kt: gen_kotlin.ysl2 transport_status_code.yml2 $(TSC)
TransportStatusCode.cs: gen_cs.ysl2 transport_status_code.yml2 $(TSC)
$(YML2_PROC) -y $< -o $@ transport_status_code.yml2
transport_status_code.xml: transport_status_code.yml2 $(TSC)
$(YML2_PROC) -P -o $@ $<
install: $(TARGET)
mkdir -p $(PREFIX)/include/pEp
mkdir -p $(PREFIX)/lib


+ 45
- 3
src/gen_cs.ysl2 View File

@ -3,17 +3,41 @@ include yslt.yml2
tstylesheet {
include standardlib.ysl2
function "isError"
{
param "tsc";
param "hexdigits", 8;
const "hex", "yml:dec2hex($tsc,$hexdigits)";
value "yml:hex2dec(substring($hex,3,2))";
}
template "/enum"
||
import System;
namespace pEp {
enum «yml:CamelCase(@name)»
{
`` apply "item|doc", 2
`` apply "item|doc", 2, mode=enum
}
`` apply "item", mode=exception
class UnknownErrorException : Exception { }
class «yml:CamelCase(@name)»Converter {
public static void throwTSCError(TransportStatusCode tsc) {
switch (tsc) {
``apply "item", 4, mode=case
default:
throw new UnknownErrorException();
}
}
}
}
||
template "item" {
template "item", mode=enum {
param "hexdigits", 8;
indent 0;
choose {
@ -27,7 +51,25 @@ tstylesheet {
> \n
}
template "doc"
template "item", mode=exception {
const "isError" call "isError" with "tsc", ".";
if "$isError > 127"
| class «yml:CamelCase(@name)»Exception : Exception { }
}
template "item", mode=case {
| case «yml:CamelCase(@name)»:
const "isError" call "isError" with "tsc", ".";
choose {
when "$isError > 127"
|> throw new «yml:CamelCase(@name)»Exception();
otherwise
|> break;
}
|
}
template "doc", mode=enum
||
// «.»


Loading…
Cancel
Save