SHi.SyntaxHighlight es una libreria con funciones que permiten
construir generadores de sintaxis realzada (syntax highlight).
Por ejemplo, el programa Dct.Write, que genera contenidos para el sitio web
lazytol.com, esta basado, entre otras, en esta libreria.
Esta libreria de funciones esta fundamentalmente orientada para el realce
de sintaxis del lenguaje de programacion Tol (Time Oriented Language),
pero tambien sirve para otros lenguajes como por ejemplo:
a) Sql (Structured Query Language),
b) el lenguaje de los ficheros de especificacion de Gnuplot,
c) el de los ficheros de mandatos de Windows de Microsoft,
d) Css (Cascading Style Sheets),
e) Html (HyperText Markup Language),
f) Xml (eXtensible Markup Language) y
g) Javascript.
Para el realce de la sintaxis emplea los colores de los textos:
a) negro para el codigo fuente,
b) verde para los comentarios y
c) azul para los textos.
SHi.SyntaxHighlight tambien es capaz de realzar sintaxis de algunos
lenguajes embebidos en otros, en este caso lo que emplea es el color de
fondo del texto, backgraound, en especial el rosa.
Ejemplos de lenguajes embebidos en otros cuya sintaxis se puede realzar
son:
a) el lenguaje Javascript embebido dentro de codigo fuente Html o
b) el propio lenguaje Tol embevido dentro de Html.
En otros casos la forma de embeber un codigo de un lenguaje en otro
lenguaje es mediante textos, por ejemplo, como cuando se introducen
sentencias Sql dentro del lenguaje Tol que se ponen como textos.
En estos casos el codigo embebido aparece den color azul de los textos.
Se trata de un realce de sintaxis basico orientado a generar la
documentacion de los programas Tol, de su codigo fuente, ficheros
auxiliares y de otros lenguajes de programacion que conviven con Tol,
como Slq, Html, Xml, etc. en 2 formatos diferentes:
a) como paginas web en Html y
b) como documentos en formato Pdf.
Este programa SHi.SyntaxHighlight realiza:
a) una serie de pruebas de las funciones de sintaxsis realzada de su
libreria y
b) tambien permiten comprender como es la informacion que retorna la
funcion Parse() del lenguaje Tol, si bien esta funcion es realmente
empleada en otros programas que pueden basarse en esta libreria,
como por ejemplo, Dct.Writer.
SHi.SyntaxHighlight funciones de sintaxis realzada de codigo
//////////////////////////////////////////////////////////////////////////////
Set allInc = Include("tol/inc.tol");
//////////////////////////////////////////////////////////////////////////////
PutDescription("Inclusion de las funciones comunes y de aplicacion.", allInc);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Real timIni = Copy(Time);
//////////////////////////////////////////////////////////////////////////////
PutDescription("Para controlar tiempos.", timIni);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set tstSpl = {
Text WriteLn("\nTxtSplitBy1Tag() test incluyendo correctos+incorrectos:");
Set View(SetOfSet(
TxtSplitBy1Tag("alfa|beta|alfa|beta|alfa", "|"),
TxtSplitBy1Tag("alfa|beta|alfa|beta|", "|"),
TxtSplitBy1Tag("alfa|beta|alfa|beta", "|"),
TxtSplitBy1Tag("alfa|beta|alfa|", "|"),
TxtSplitBy1Tag("alfa|beta|alfa", "|"),
TxtSplitBy1Tag("alfa|beta|", "|"),
TxtSplitBy1Tag("alfa|beta", "|"),
TxtSplitBy1Tag("|beta|", "|"),
TxtSplitBy1Tag("|beta", "|"),
TxtSplitBy1Tag("alfa", "|")), "");
Text WriteLn("\nTxtSplitBy2Tag() test incluyedo correctos+incorrectos:");
Set View(SetOfSet(
TxtSplitBy2Tag("alfa<beta>alfa<beta>alfa", "<", ">"),
TxtSplitBy2Tag("alfa<beta>alfa<beta>", "<", ">"),
TxtSplitBy2Tag("alfa<beta>alfa<beta", "<", ">"),
TxtSplitBy2Tag("alfa<beta>alfa<", "<", ">"),
TxtSplitBy2Tag("alfa<beta>alfa", "<", ">"),
TxtSplitBy2Tag("alfa<beta>", "<", ">"),
TxtSplitBy2Tag("alfa<beta", "<", ">"),
TxtSplitBy2Tag("<beta>", "<", ">"),
TxtSplitBy2Tag("<beta", "<", ">"),
TxtSplitBy2Tag("alfa", "<", ">")), "");
Text WriteLn("\nTxtSplitBy2Fast() test incluyendo correctos+incorrectos:");
Set View(SetOfSet(
TxtSplitBy2Fast("alfa<beta>alfa<beta>alfa", "<", ">"),
TxtSplitBy2Fast("alfa<beta>alfa<beta>", "<", ">"),
TxtSplitBy2Fast("alfa<beta>alfa<beta", "<", ">"),
TxtSplitBy2Fast("alfa<beta>alfa<", "<", ">"),
TxtSplitBy2Fast("alfa<beta>alfa", "<", ">"),
TxtSplitBy2Fast("alfa<beta>", "<", ">"),
TxtSplitBy2Fast("alfa<beta", "<", ">"),
TxtSplitBy2Fast("<beta>", "<", ">"),
TxtSplitBy2Fast("<beta", "<", ">"),
TxtSplitBy2Fast("alfa", "<", ">")), "")
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Test de las funciones TxtSplitBy1Tag(), TxtSplitBy2Tag() y
TxtSplitBy2Fast().",
tstSpl);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text tstShi =
{
Text WriteLn("\nSHiRemStrCodSet() test:");
Text tolCod = ReadFile("code.inp/gpl.tol");
Text tolSql = ReadFile("code.inp/sql.tol");
Text sqlCod = ReadFile("code.inp/edi.sql");
Text gplCod = ReadFile("code.inp/gif.gpl");
Text cmdCod = ReadFile("code.inp/pdf.bat");
Text cssCod = ReadFile("code.inp/cmm.css");
Text xmlCod = ReadFile("code.inp/map.xml");
Text htmCod = ReadFile("code.inp/see.htm");
Text jscCod = ReadFile("code.inp/arr.js");
Text htmSee = ReadFile("code.out/codeseed.htm");
Text WriteFile("code.out/codetest.htm", Replace(htmSee, "_COD_",
SHiTolPre(tolCod)+"\n<hr />\n"+
SHiTolPre(tolSql)+"\n<hr />\n"+
SHiSqlPre(sqlCod)+"\n<hr />\n"+
SHiGplPre(gplCod)+"\n<hr />\n"+
SHiCmdPre(cmdCod)+"\n<hr />\n"+
SHiCssPre(cssCod)+"\n<hr />\n"+
SHiJscPre(jscCod)+"\n<hr />\n"+
SHiXmlPre(xmlCod)+"\n<hr />\n"+
SHiEmbPre(htmCod)+"\n<hr />\n"+
" "))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Prueba de la funcion SHiTolPre() con codigo de Tol, Sql, Gnuplot, ficheros
de mandatos, Css, Html, Xml y Javascript.",
tstShi);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Real tstPar =
{
Text WriteLn("\nparse: begin\n");
Text varCod = "
////////////////////////////////////////////////////////////////////////////
Text XxxMiniVariable = 1;
////////////////////////////////////////////////////////////////////////////
PutDescription(\"Vale 1, variable minima.\", XxxMiniVariable);
////////////////////////////////////////////////////////////////////////////
";
Set varPar = Parse(varCod)[3]; // Acesso al arbol del parse
Real varChk = varPar[1][1] == "="; // Comprobar que es variable
Text varCla = If(varChk, "variable", "no es variable");
Text varTyp = varPar[1][3][1][1]; // Tipo
Text varNam = varPar[1][3][1][3][1][1]; // Nombre
Text varDes = varPar[2][3][1][1]; // Descripcion
Text WriteLn(varTyp+" "+varNam+" = ...; // "+varDes+" ["+varCla+"]");
Set varTre = // Arbol similar al del parse, pero creado a mano
[[
[[ "=", "binary",
[[
[[ "Text", "type",
[[
[[ "XxxMiniVariable", "argument", Empty ]]
]]
]],
[[ "1", "argument", Empty ]]
]]
]],
[[ "PutDescription", "function",
[[
[[ "Vale 1, variable minima.", "argument", Empty ]] ,
[[ "XxxMiniVariable", "argument", Empty ]]
]]
]]
]];
Text funCod = "
////////////////////////////////////////////////////////////////////////////
Real XxxMiniFunction(Text argOne, Real argTwo)
////////////////////////////////////////////////////////////////////////////
{ 1 };
////////////////////////////////////////////////////////////////////////////
PutDescription(\"Retorna 1, funcion minima.\", XxxMiniFunction);
////////////////////////////////////////////////////////////////////////////
";
Set funPar = Parse(funCod)[3]; // Acesso al arbol del parse
Real funChk = funPar[1][1] == "#F#"; // Comprobar que es funcion
Text funCla = If(funChk, "funcion", "no es funcion");
Text funTyp = funPar[1][3][1][1]; // Tipo
Text funNam = funPar[1][3][1][3][1][1]; // Nombre
Text funDes = funPar[2][3][1][1]; // Descripcion
Text WriteLn(funTyp+" "+funNam+"(...) {...}; // "+funDes+" ["+funCla+"]");
Set argSet = funPar[1][3][1][3][1][3]; // Conjunto de argumentos
Real argNum = Card(argSet); // Numero de argumentos
Set argCic = For(1, argNum, Text(Real argPos)
{
Set argInf = argSet[argPos]; // Informacion del argumento
Text argTyp = argInf[1];
Text argNam = argInf[3][1][1];
Case(EQ(argPos, 1), "("+argTyp+" "+argNam+", ",
EQ(argPos, argNum), argTyp+" "+argNam+")",
TRUE, argTyp+" "+argNam+", ")
});
Text argTxt = SetSum(argCic);
Text WriteLn(funTyp+" "+funNam+argTxt+" {...}; // "+funDes+" ["+funCla+"]");
Set funTre = // Arbol similar al del parse, pero creado a mano
[[
[[ "#F#", "binary",
[[
[[ "Real", "type",
[[
[[ "XxxMiniFunction", "function",
[[
[[ "Text", "type",
[[
[[ "argOne", "argument", Empty ]]
]]
]],
[[ "Real", "type",
[[
[[ "argTwo", "argument", Empty ]]
]]
]]
]]
]]
]]
]],
[[ "1", "argument", Empty ]]
]]
]] ,
[[ "PutDescription", "function",
[[
[[ "Retorna 1, funcion minima.", "argument", Empty ]] ,
[[ "XxxMiniFunction", "argument", Empty ]]
]]
]]
]];
TRUE
};
//////////////////////////////////////////////////////////////////////////////
PutDescription("Pruebas con la funcion Parse().",tstPar);
//////////////////////////////////////////////////////////////////////////////
Text WriteLn("\nXls.Reader make: end ["+
FormatReal((Time-timIni)/60,"%.2lf")+" m].");
//////////////////////////////////////////////////////////////////////////////
// FILE : make.tol
// AUTHOR : http://www.asolver.com
// CLASS : Metaprogramación; Hipertexto
// VERSION : Tol 1.1.5; Tol 1.1.6; Tol 2.0.1
// PURPOSE : SHi.SyntaxHighlight es una libreria con funciones que permiten
// construir generadores de sintaxis realzada (syntax highlight).
//
// Por ejemplo, el programa Dct.Write, que genera contenidos para el sitio web
// lazytol.com, esta basado, entre otras, en esta libreria.
//
// Esta libreria de funciones esta fundamentalmente orientada para el realce
// de sintaxis del lenguaje de programacion Tol (Time Oriented Language),
// pero tambien sirve para otros lenguajes como por ejemplo:
// a) Sql (Structured Query Language),
// b) el lenguaje de los ficheros de especificacion de Gnuplot,
// c) el de los ficheros de mandatos de Windows de Microsoft,
// d) Css (Cascading Style Sheets),
// e) Html (HyperText Markup Language),
// f) Xml (eXtensible Markup Language) y
// g) Javascript.
//
// Para el realce de la sintaxis emplea los colores de los textos:
// a) negro para el codigo fuente,
// b) verde para los comentarios y
// c) azul para los textos.
// _
// SHi.SyntaxHighlight tambien es capaz de realzar sintaxis de algunos
// lenguajes embebidos en otros, en este caso lo que emplea es el color de
// fondo del texto, backgraound, en especial el rosa.
//
// Ejemplos de lenguajes embebidos en otros cuya sintaxis se puede realzar
// son:
// a) el lenguaje Javascript embebido dentro de codigo fuente Html o
// b) el propio lenguaje Tol embevido dentro de Html.
//
// En otros casos la forma de embeber un codigo de un lenguaje en otro
// lenguaje es mediante textos, por ejemplo, como cuando se introducen
// sentencias Sql dentro del lenguaje Tol que se ponen como textos.
// En estos casos el codigo embebido aparece den color azul de los textos.
// _
// Se trata de un realce de sintaxis basico orientado a generar la
// documentacion de los programas Tol, de su codigo fuente, ficheros
// auxiliares y de otros lenguajes de programacion que conviven con Tol,
// como Slq, Html, Xml, etc. en 2 formatos diferentes:
// a) como paginas web en Html y
// b) como documentos en formato Pdf.
//
// Este programa SHi.SyntaxHighlight realiza:
// a) una serie de pruebas de las funciones de sintaxsis realzada de su
// libreria y
// b) tambien permiten comprender como es la informacion que retorna la
// funcion Parse() del lenguaje Tol, si bien esta funcion es realmente
// empleada en otros programas que pueden basarse en esta libreria,
// como por ejemplo, Dct.Writer.
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// INCLUDE
//////////////////////////////////////////////////////////////////////////////
Text WriteLn("\nSHi.SyntaxHighlight make: begin");
//////////////////////////////////////////////////////////////////////////////
Set allInc = Include("tol/inc.tol");
//////////////////////////////////////////////////////////////////////////////
PutDescription("Inclusion de las funciones comunes y de aplicacion.", allInc);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// TEST
//////////////////////////////////////////////////////////////////////////////
Text WriteLn("\nSHi.SyntaxHighlight make: test");
//////////////////////////////////////////////////////////////////////////////
Real timIni = Copy(Time);
//////////////////////////////////////////////////////////////////////////////
PutDescription("Para controlar tiempos.", timIni);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set tstSpl = {
Text WriteLn("\nTxtSplitBy1Tag() test incluyendo correctos+incorrectos:");
Set View(SetOfSet(
TxtSplitBy1Tag("alfa|beta|alfa|beta|alfa", "|"),
TxtSplitBy1Tag("alfa|beta|alfa|beta|", "|"),
TxtSplitBy1Tag("alfa|beta|alfa|beta", "|"),
TxtSplitBy1Tag("alfa|beta|alfa|", "|"),
TxtSplitBy1Tag("alfa|beta|alfa", "|"),
TxtSplitBy1Tag("alfa|beta|", "|"),
TxtSplitBy1Tag("alfa|beta", "|"),
TxtSplitBy1Tag("|beta|", "|"),
TxtSplitBy1Tag("|beta", "|"),
TxtSplitBy1Tag("alfa", "|")), "");
Text WriteLn("\nTxtSplitBy2Tag() test incluyedo correctos+incorrectos:");
Set View(SetOfSet(
TxtSplitBy2Tag("alfa<beta>alfa<beta>alfa", "<", ">"),
TxtSplitBy2Tag("alfa<beta>alfa<beta>", "<", ">"),
TxtSplitBy2Tag("alfa<beta>alfa<beta", "<", ">"),
TxtSplitBy2Tag("alfa<beta>alfa<", "<", ">"),
TxtSplitBy2Tag("alfa<beta>alfa", "<", ">"),
TxtSplitBy2Tag("alfa<beta>", "<", ">"),
TxtSplitBy2Tag("alfa<beta", "<", ">"),
TxtSplitBy2Tag("<beta>", "<", ">"),
TxtSplitBy2Tag("<beta", "<", ">"),
TxtSplitBy2Tag("alfa", "<", ">")), "");
Text WriteLn("\nTxtSplitBy2Fast() test incluyendo correctos+incorrectos:");
Set View(SetOfSet(
TxtSplitBy2Fast("alfa<beta>alfa<beta>alfa", "<", ">"),
TxtSplitBy2Fast("alfa<beta>alfa<beta>", "<", ">"),
TxtSplitBy2Fast("alfa<beta>alfa<beta", "<", ">"),
TxtSplitBy2Fast("alfa<beta>alfa<", "<", ">"),
TxtSplitBy2Fast("alfa<beta>alfa", "<", ">"),
TxtSplitBy2Fast("alfa<beta>", "<", ">"),
TxtSplitBy2Fast("alfa<beta", "<", ">"),
TxtSplitBy2Fast("<beta>", "<", ">"),
TxtSplitBy2Fast("<beta", "<", ">"),
TxtSplitBy2Fast("alfa", "<", ">")), "")
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Test de las funciones TxtSplitBy1Tag(), TxtSplitBy2Tag() y
TxtSplitBy2Fast().",
tstSpl);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text tstShi =
{
Text WriteLn("\nSHiRemStrCodSet() test:");
Text tolCod = ReadFile("code.inp/gpl.tol");
Text tolSql = ReadFile("code.inp/sql.tol");
Text sqlCod = ReadFile("code.inp/edi.sql");
Text gplCod = ReadFile("code.inp/gif.gpl");
Text cmdCod = ReadFile("code.inp/pdf.bat");
Text cssCod = ReadFile("code.inp/cmm.css");
Text xmlCod = ReadFile("code.inp/map.xml");
Text htmCod = ReadFile("code.inp/see.htm");
Text jscCod = ReadFile("code.inp/arr.js");
Text htmSee = ReadFile("code.out/codeseed.htm");
Text WriteFile("code.out/codetest.htm", Replace(htmSee, "_COD_",
SHiTolPre(tolCod)+"\n<hr />\n"+
SHiTolPre(tolSql)+"\n<hr />\n"+
SHiSqlPre(sqlCod)+"\n<hr />\n"+
SHiGplPre(gplCod)+"\n<hr />\n"+
SHiCmdPre(cmdCod)+"\n<hr />\n"+
SHiCssPre(cssCod)+"\n<hr />\n"+
SHiJscPre(jscCod)+"\n<hr />\n"+
SHiXmlPre(xmlCod)+"\n<hr />\n"+
SHiEmbPre(htmCod)+"\n<hr />\n"+
" "))
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Prueba de la funcion SHiTolPre() con codigo de Tol, Sql, Gnuplot, ficheros
de mandatos, Css, Html, Xml y Javascript.",
tstShi);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Real tstPar =
{
Text WriteLn("\nparse: begin\n");
Text varCod = "
////////////////////////////////////////////////////////////////////////////
Text XxxMiniVariable = 1;
////////////////////////////////////////////////////////////////////////////
PutDescription(\"Vale 1, variable minima.\", XxxMiniVariable);
////////////////////////////////////////////////////////////////////////////
";
Set varPar = Parse(varCod)[3]; // Acesso al arbol del parse
Real varChk = varPar[1][1] == "="; // Comprobar que es variable
Text varCla = If(varChk, "variable", "no es variable");
Text varTyp = varPar[1][3][1][1]; // Tipo
Text varNam = varPar[1][3][1][3][1][1]; // Nombre
Text varDes = varPar[2][3][1][1]; // Descripcion
Text WriteLn(varTyp+" "+varNam+" = ...; // "+varDes+" ["+varCla+"]");
Set varTre = // Arbol similar al del parse, pero creado a mano
[[
[[ "=", "binary",
[[
[[ "Text", "type",
[[
[[ "XxxMiniVariable", "argument", Empty ]]
]]
]],
[[ "1", "argument", Empty ]]
]]
]],
[[ "PutDescription", "function",
[[
[[ "Vale 1, variable minima.", "argument", Empty ]] ,
[[ "XxxMiniVariable", "argument", Empty ]]
]]
]]
]];
Text funCod = "
////////////////////////////////////////////////////////////////////////////
Real XxxMiniFunction(Text argOne, Real argTwo)
////////////////////////////////////////////////////////////////////////////
{ 1 };
////////////////////////////////////////////////////////////////////////////
PutDescription(\"Retorna 1, funcion minima.\", XxxMiniFunction);
////////////////////////////////////////////////////////////////////////////
";
Set funPar = Parse(funCod)[3]; // Acesso al arbol del parse
Real funChk = funPar[1][1] == "#F#"; // Comprobar que es funcion
Text funCla = If(funChk, "funcion", "no es funcion");
Text funTyp = funPar[1][3][1][1]; // Tipo
Text funNam = funPar[1][3][1][3][1][1]; // Nombre
Text funDes = funPar[2][3][1][1]; // Descripcion
Text WriteLn(funTyp+" "+funNam+"(...) {...}; // "+funDes+" ["+funCla+"]");
Set argSet = funPar[1][3][1][3][1][3]; // Conjunto de argumentos
Real argNum = Card(argSet); // Numero de argumentos
Set argCic = For(1, argNum, Text(Real argPos)
{
Set argInf = argSet[argPos]; // Informacion del argumento
Text argTyp = argInf[1];
Text argNam = argInf[3][1][1];
Case(EQ(argPos, 1), "("+argTyp+" "+argNam+", ",
EQ(argPos, argNum), argTyp+" "+argNam+")",
TRUE, argTyp+" "+argNam+", ")
});
Text argTxt = SetSum(argCic);
Text WriteLn(funTyp+" "+funNam+argTxt+" {...}; // "+funDes+" ["+funCla+"]");
Set funTre = // Arbol similar al del parse, pero creado a mano
[[
[[ "#F#", "binary",
[[
[[ "Real", "type",
[[
[[ "XxxMiniFunction", "function",
[[
[[ "Text", "type",
[[
[[ "argOne", "argument", Empty ]]
]]
]],
[[ "Real", "type",
[[
[[ "argTwo", "argument", Empty ]]
]]
]]
]]
]]
]]
]],
[[ "1", "argument", Empty ]]
]]
]] ,
[[ "PutDescription", "function",
[[
[[ "Retorna 1, funcion minima.", "argument", Empty ]] ,
[[ "XxxMiniFunction", "argument", Empty ]]
]]
]]
]];
TRUE
};
//////////////////////////////////////////////////////////////////////////////
PutDescription("Pruebas con la funcion Parse().",tstPar);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// END
//////////////////////////////////////////////////////////////////////////////
Text WriteLn("\nXls.Reader make: end ["+
FormatReal((Time-timIni)/60,"%.2lf")+" m].");
2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio