You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

245 lines
6.6 KiB

include standardlib.ysl2
// ----------------------------------------------------------------------
// stdlib candidates
// ----------------------------------------------------------------------
def "func:autocomma" {
result if "position()!=last()" > ,
}
def "func:exists" {
param "xpath";
choose {
when "$xpath"
result "true()";
otherwise
result "false()";
}
}
def "func:repeat_until" {
param "str";
param "count";
choose {
when "string-length($str) < $count" {
result "func:repeat_until(concat($str, $str), $count)";
} otherwise {
result "substring($str, 0, $count+1)";
}
}
}
def "func:indent" {
param "content";
param "indent_count";
param "indent_char", "'\t'";
result > «func:repeat_until($indent_char, $indent_count)»«$content»
}
def "func:paragraph_block" {
param "content";
param "nth", "80";
param "wrap_char", "'\n'";
const "cont_oneline", "translate($content, '\n', ' ')";
result > «func:line_wrap($cont_oneline, $nth, $wrap_char)»
}
def "func:line_wrap" {
param "content";
param "nth", "80";
param "wrap_char", "'\n'";
const "sep_char", "''";
const "nth_minus_dash", "$nth - string-length($sep_char)";
const "ret", "substring($content, 0, $nth_minus_dash)";
const "remainder", "substring($content, $nth_minus_dash)";
choose {
when "string-length($remainder) > $nth_minus_dash" {
result > «$ret»«$sep_char»«$wrap_char»«func:line_wrap($remainder, $nth)»
} otherwise {
result > «$ret»«$sep_char»«$wrap_char»«$remainder»
}
}
}
def "func:column_paragraph" {
param "title";
param "content";
param "max_width";
result call "column_paragraph"
with "title", "$title",
with "content", "$content",
with "max_width", "$max_width";
}
function "column_paragraph" {
param "title";
param "content";
param "max_width";
const "title_width", "string-length($title)";
const "cont_width", "$max_width - $title_width";
const "cont_wrapped", "func:paragraph_block($content, $cont_width)";
for "str:split($cont_wrapped, '\n')" {
const "line", ".";
choose {
when "position() = 1"
| «$title»«func:indent($line,1,' ')»
otherwise
| «func:indent($line, $title_width+1,' ')»
}
}
}
// ----------------------------------------------------------------------
// idl-api (ysl2)
// ----------------------------------------------------------------------
template "/" {
choose {
when "func:idl_static_analysis_is_ok()"
apply "/pEpACIDLang", 0
}
}
def "func:idl_static_analysis_is_ok" {
const "pepacidlang_count", "count(/pEpACIDLang)";
const "idl_count", "count(/pEpACIDLang/idl)";
choose {
when "$pepacidlang_count < 1"
error > idl_static_analysis_is_ok - root node pEpACIDLang not found
when "$idl_count < 1"
error > idl_static_analysis_is_ok - pEpACIDLang idl data not found, include pEpACIDLang.yml2 exactly once.
when "$idl_count < 1"
error > idl_static_analysis_is_ok - ambiguous idl data, include pEpACIDLang.yml2 exactly once.
otherwise
result "true()";
}
}
def "func:idl_get_package_name" {
result "/pEpACIDLang/package/@name"
}
def "func:idl_get_package_version" {
result "/pEpACIDLang/package/version/text()"
}
def "func:idl_get_package_license" {
result "/pEpACIDLang/package/license/text()"
}
def "func:idl_get_basetypes" {
result "/pEpACIDLang/idl/basetypes/*"
};
def "func:idl_typekind_is_defined" {
param "typekind";
result "func:exists(/pEpACIDLang/idl/typekinds//*[name()=$typekind])"
}
def "func:idl_typekind_is_generic" {
param "typekind";
result "func:exists(/pEpACIDLang/idl/typekinds/generics/*[name()=$typekind])"
}
def "func:idl_type_is_defined" {
param "idltype";
choose {
when "func:idl_type_get_typekind_of_type($idltype)"
result "true()";
otherwise
result "false()";
}
}
def "func:idl_type_is_of_typekind_basetype" {
param "idltype";
result "func:exists(/pEpACIDLang/idl/basetypes/*[name()=$idltype])";
}
def "func:idl_type_is_of_typekind_deftype" {
param "idltype";
result "func:exists(//deftype[@name=$idltype])";
}
def "func:idl_type_is_of_typekind_enum" {
param "idltype";
result "func:exists(//enum[@name=$idltype])";
}
def "func:idl_type_is_of_typekind_struct" {
param "idltype";
result "func:exists(//struct[@name=$idltype])";
}
def "func:idl_type_is_generic" {
param "idltype";
result "contains($idltype,'<') and contains($idltype,'>')"
}
// TODO: generic is actually not a typekid, this should return the generic typekind like list/map/pair
def "func:idl_type_get_typekind_of_type" {
param "idltype";
choose {
when "func:idl_type_is_of_typekind_basetype($idltype)"
result > basetype
when "func:idl_type_is_of_typekind_deftype($idltype)"
result > deftype
when "func:idl_type_is_of_typekind_enum($idltype)"
result > enum
when "func:idl_type_is_of_typekind_struct($idltype)"
result > struct
when "func:idl_type_is_generic($idltype)"
result > generic
otherwise
result "false()";
}
}
def "func:idl_type_get_resolved_type" {
param "idltype";
const "idltypekind", "func:idl_type_get_typekind_of_type($idltype)";
choose {
when "$idltypekind = 'deftype'"
result "func:idl_type_get_resolved_type(func:idl_type_get_type_of_deftype($idltype))";
otherwise
result "$idltype";
}
}
def "func:idl_type_get_type_of_deftype" {
param "idltype";
const "deftype", "//deftype[@name=$idltype]";
const "type_or_typekind", "$deftype/as/@type";
choose {
when "func:idl_type_is_of_typekind_deftype($idltype)"
choose {
when "func:idl_typekind_is_generic($type_or_typekind)"
result call "idl_type_of_generic_deftype" with "deftype", "$deftype";
otherwise
result "$type_or_typekind";
}
otherwise
error > idl_resolve_deftype - is not a deftype: «$idltype»;
}
}
function "idl_type_of_generic_deftype" {
param "deftype";
const "generic_type", "$deftype/as/@type";
> «$generic_type»
> <
for "$deftype/as/generic/*" {
const "param_type", "name()";
> «$param_type»«func:autocomma()»
}
> >
}