eolian: support complex monospace syntax $[...]

This is to allow monospace bits with periods, commas and other
non-alphabetical characters. Newlines are not supported (they end
the block) and escapes are supported (for ]).

Fixes T8213.
This commit is contained in:
Daniel Kolesa 2019-09-13 16:56:43 +02:00
parent bc8c432841
commit 266fd9bb36
2 changed files with 70 additions and 6 deletions

View File

@ -126,7 +126,6 @@ _append_section(const Eolian_State *state, const char *desc, int ind, int curl,
Eina_Bool try_note = EINA_TRUE;
while (*desc)
{
eina_strbuf_reset(wbuf);
while (*desc && isspace(*desc) && (*desc != '\n'))
eina_strbuf_append_char(wbuf, *desc++);
if (try_note)
@ -155,6 +154,8 @@ _append_section(const Eolian_State *state, const char *desc, int ind, int curl,
#undef CHECK_NOTE
try_note = EINA_FALSE;
}
int limit = DOC_LIMIT(ind);
int wlen;
if (*desc == '\\')
{
desc++;
@ -180,7 +181,47 @@ _append_section(const Eolian_State *state, const char *desc, int ind, int curl,
}
else if (*desc == '$')
{
desc++;
if (*++desc == '[')
{
++desc;
eina_strbuf_append(wbuf, "<tt>");
wlen = eina_strbuf_length_get(wbuf);
while ((*desc != '\0') && (*desc != ']') && (*desc != '\n'))
{
if (*desc == ' ')
{
eina_strbuf_append_char(wbuf, ' ');
wlen = eina_strbuf_length_get(wbuf);
if ((int)(curl + wlen) > limit)
{
curl = 3;
eina_strbuf_append_char(buf, '\n');
curl += _indent_line(buf, ind);
eina_strbuf_append(buf, " * ");
if (*eina_strbuf_string_get(wbuf) == ' ')
eina_strbuf_remove(wbuf, 0, 1);
}
curl += eina_strbuf_length_get(wbuf);
eina_strbuf_append(buf, eina_strbuf_string_get(wbuf));
eina_strbuf_reset(wbuf);
++desc;
continue;
}
/* skip escape */
if (*desc == '\\')
{
++desc;
if ((*desc == '\0') || (*desc == '\n'))
break;
}
eina_strbuf_append_char(wbuf, *desc++);
}
if (*desc == ']')
++desc;
eina_strbuf_append(wbuf, "</tt>");
curl += 5;
goto split;
}
if (isalpha(*desc))
eina_strbuf_append(wbuf, "@c ");
else
@ -188,8 +229,8 @@ _append_section(const Eolian_State *state, const char *desc, int ind, int curl,
}
while (*desc && !isspace(*desc))
eina_strbuf_append_char(wbuf, *desc++);
int limit = DOC_LIMIT(ind);
int wlen = eina_strbuf_length_get(wbuf);
split:
wlen = eina_strbuf_length_get(wbuf);
if ((int)(curl + wlen) > limit)
{
curl = 3;
@ -201,6 +242,7 @@ _append_section(const Eolian_State *state, const char *desc, int ind, int curl,
}
curl += eina_strbuf_length_get(wbuf);
eina_strbuf_append(buf, eina_strbuf_string_get(wbuf));
eina_strbuf_reset(wbuf);
if (*desc == '\n')
{
desc++;

View File

@ -314,7 +314,6 @@ eolian_documentation_tokenize(const char *doc, Eolian_Doc_Token *ret)
#undef CMP_MARK_NOTE
mloop:
/* monospace markup ($foo) */
if ((doc[0] == '$') && ((doc[1] == '_') || isalpha(doc[1])))
{
@ -326,6 +325,28 @@ mloop:
return ret->text_end;
}
/* complex monospace markup ($[...]) */
if ((doc[0] == '$') && (doc[1] == '['))
{
doc += 2;
ret->text = doc;
ret->text_end = ret->text;
while ((ret->text_end[0] != '\0') && (ret->text_end[0] != ']') &&
(ret->text_end[0] != '\n'))
{
/* escape: skip backslash */
if ((ret->text_end[0] == '\\') && (ret->text_end[1] != '\0') &&
(ret->text_end[1] != '\n'))
++ret->text_end;
++ret->text_end;
}
ret->type = EOLIAN_DOC_TOKEN_MARKUP_MONOSPACE;
/* return past the ending bracket as that's markup syntax */
if (ret->text_end[0] == ']')
return ret->text_end + 1;
return ret->text_end;
}
/* references */
Eolian_Doc_Token_Type rtp = _get_ref_token(doc, &ret->text_end);
if (rtp != EOLIAN_DOC_TOKEN_UNKNOWN)
@ -349,7 +370,8 @@ mloop:
continue;
}
/* monospace markup */
if ((schr[0] == '$') && ((schr[1] == '_') || isalpha(schr[1])))
if ((schr[0] == '$') && (
(schr[1] == '_') || (schr[1] == '[') || isalpha(schr[1])))
{
pschr = schr;
break;