summaryrefslogtreecommitdiffabout
path: root/lib/sitecing_parser.ll
Side-by-side diff
Diffstat (limited to 'lib/sitecing_parser.ll') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/sitecing_parser.ll13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/sitecing_parser.ll b/lib/sitecing_parser.ll
index 4fd6709..8dd8d5f 100644
--- a/lib/sitecing_parser.ll
+++ b/lib/sitecing_parser.ll
@@ -1,105 +1,106 @@
%{
/*
* XXX: I have a strong feeling that this parser should be completely rewritten.
*/
#include <iostream>
#include <fstream>
#include <cassert>
#include <stdexcept>
using namespace std;
+#include <konforka/util.h>
#include "sitecing/sitecing_util.h"
#include "sitecing/sitecing_exception.h"
using namespace sitecing;
#define sitecing_parser_flexlexer_once
#include "sitecing/sitecing_parser.h"
#include "sitecing/sitecing_enflesher.h"
#undef yyFlexLexer
#define yyFlexLexer sitecing_parserFlexLexer
%}
%x SLASHSTAR_COMMENT SLASHSLASH_COMMENT STRING
%x CODELINE CLASSLINE DECLLINE IMPLLINE DECLBLOCK IMPLBLOCK VARLINE VARINIT
%x IMPORTLINE IMPORTCOMPONENT
%x IMPORTTYPELINE IMPORTTYPECOMPONENT
%x DERIVELINE DERIVECOMPONENT
%x CONSTRUCTOR DESTRUCTOR CODEMETHODLINE CODEMETHODARGS
%x CODEMETHODBLOCK INLINE METHODLINE METHODARGS METHODBLOCK CODEBLOCK OUTPUTBLOCK
%x PRAGMALINE
%option 8bit c++ verbose noyywrap yyclass="sitecing_parser" prefix="sitecing_parser" stack yylineno
WHITESPACE [ \t]
ID [A-Za-z_][A-Za-z0-9_]*
NOIDCHAR [^A-Za-z0-9_]
%%
<INITIAL>{
^\%\%class{WHITESPACE}+ {
// TODO: signal error if we already have class name acquired from source.
modi.push_front(modus_operandi(modus_operandi::flag_devour_comments|modus_operandi::flag_devour_whitespace));
BEGIN(CLASSLINE);
}
^\%\%decl{WHITESPACE}+ {
modi.push_front(modus_operandi(0));
anchor();
BEGIN(DECLLINE);
}
^\%\%impl{WHITESPACE}+ {
modi.push_front(modus_operandi(0));
anchor();
BEGIN(IMPLLINE);
}
\<\%decl\> {
modi.push_front(modus_operandi(0));
anchor();
BEGIN(DECLBLOCK);
}
\<\%impl\> {
modi.push_front(modus_operandi(0));
anchor();
BEGIN(IMPLBLOCK);
}
^\%\%var{WHITESPACE}+ {
modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
anchor();
BEGIN(VARLINE);
}
^\%\%import{WHITESPACE}+ {
modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
BEGIN(IMPORTLINE);
}
^\%\%import_type{WHITESPACE}+ {
modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
BEGIN(IMPORTTYPELINE);
}
^\%\%derive{WHITESPACE}+ {
modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
BEGIN(DERIVELINE);
}
\<\%constructor\> {
modi.push_front(modus_operandi());
anchor();
BEGIN(CONSTRUCTOR);
}
\<\%destructor\> {
modi.push_front(modus_operandi());
anchor();
BEGIN(DESTRUCTOR);
}
\<\%codemethod{WHITESPACE}+ {
modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
anchor();
BEGIN(CODEMETHODLINE);
}
\<\%method{WHITESPACE}+ {
modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
anchor();
BEGIN(METHODLINE);
}
^\%\%pragma{WHITESPACE}+ {
modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
BEGIN(PRAGMALINE);
}
<<EOF>> {
assert(modi.size()==1);
M().modify(modus_operandi::modus_preop);
LexerOutput(";",1);
@@ -204,262 +205,262 @@ NOIDCHAR [^A-Za-z0-9_]
M().modify(modus_operandi::modus_code);
anchor();
yy_push_state(CODELINE);
}
\<\%code\> {
M().modify(modus_operandi::modus_code);
anchor();
yy_push_state(CODEBLOCK);
}
"</%output>" {
if(YY_START!=OUTPUTBLOCK) throw preprocessor_error(CODEPOINT,"unexpected tag",lineno());
M().modify(modus_operandi::modus_code);
anchor();
yy_pop_state();
}
}
<INLINE>\%\> LexerOutput(")",1); M().modus=modus_operandi::modus_preop; yy_pop_state();
<CODELINE>\n yy_pop_state();
<CODEMETHODLINE>{
{WHITESPACE}+ {
modus_operandi& m = M();
if(!m.output.empty()) {
if(!m._lastid.empty()) {
if(!m._type.empty()) m._type += ' ';
m._type += m._lastid;
}
m._lastid = m.output;
m.output.clear();
}
}
\* {
modus_operandi& m = M();
ECHO;
if(!m._lastid.empty()) {
if(!m._type.empty()) m._type += ' ';
m._type += m._lastid;
}
m._lastid = m.output;
m.output.clear();
}
\( {
modus_operandi& m = M();
if(m.output.empty()) {
m._name=m._lastid;
}else{
if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy...
if(!m._type.empty()) m._type += ' ';
m._type += m._lastid;
}
m._name = m.output;
m.output.clear();
}
ECHO;
BEGIN(CODEMETHODARGS);
}
}
<CODEMETHODARGS>{
\%\> {
modus_operandi& m = M();
m._args = m.output;
m.output.clear();
m.flags=0;
anchor();
BEGIN(CODEMETHODBLOCK);
}
}
<IMPORTLINE>{
{WHITESPACE}+ { }
{ID} {
modus_operandi& m = M();
if(!m._name.empty())
throw preprocessor_error(CODEPOINT,"syntax error",lineno());
m._name = yytext;
}
\= {
M().output.clear();
BEGIN(IMPORTCOMPONENT);
}
}
<IMPORTCOMPONENT>{
{WHITESPACE}+ { }
\n {
modus_operandi& m = M();
string::size_type t = m.output.find_first_not_of(" \t");
if(t!=string::npos)
m.output.erase(0,t);
t = m.output.find_last_not_of(" \t;");
if(t!=string::npos)
m.output.erase(t+1);
if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') {
m.output.erase(0,1);
m.output.erase(m.output.length()-1);
}
- string c = combine_path(component_basename,m.output);
- member_variables.push_back(member_variable(m._type,m._name,normalize_path(c,strip_leading_slash),true));
+ string c = konforka::combine_path(component_basename,m.output);
+ member_variables.push_back(member_variable(m._type,m._name,konforka::normalize_path(c,konforka::strip_leading_slash),true));
modi.pop_front();
BEGIN(INITIAL);
}
}
<IMPORTTYPELINE>{
{WHITESPACE}+ { }
{ID} {
modus_operandi& m = M();
if(!m._name.empty())
throw preprocessor_error(CODEPOINT,"syntax error",lineno());
m._name = yytext;
}
\= {
M().output.clear();
BEGIN(IMPORTTYPECOMPONENT);
}
}
<IMPORTTYPECOMPONENT>{
{WHITESPACE}+ { }
\n {
modus_operandi& m = M();
string::size_type t = m.output.find_first_not_of(" \t");
if(t!=string::npos)
m.output.erase(0,t);
t = m.output.find_last_not_of(" \t;");
if(t!=string::npos)
m.output.erase(t+1);
if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') {
m.output.erase(0,1);
m.output.erase(m.output.length()-1);
}
- string c = combine_path(component_basename,m.output);
- member_variables.push_back(member_variable(m._type,m._name,normalize_path(c,strip_leading_slash),true,true));
+ string c = konforka::combine_path(component_basename,m.output);
+ member_variables.push_back(member_variable(m._type,m._name,konforka::normalize_path(c,konforka::strip_leading_slash),true,true));
modi.pop_front();
BEGIN(INITIAL);
}
}
<DERIVELINE>{
{WHITESPACE}+ { }
{ID} {
modus_operandi& m = M();
if(!m._name.empty())
throw preprocessor_error(CODEPOINT,"syntax_error",lineno());
m._name = yytext;
}
\= {
M().output.clear();
BEGIN(DERIVECOMPONENT);
}
}
<DERIVECOMPONENT>{
{WHITESPACE}+ { }
\n {
modus_operandi& m = M();
string::size_type t = m.output.find_first_not_of(" \t");
if(t!=string::npos)
m.output.erase(0,t);
t = m.output.find_last_not_of(" \t;");
if(t!=string::npos)
m.output.erase(t+1);
if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') {
m.output.erase(0,1);
m.output.erase(m.output.length()-1);
}
- string c = combine_path(component_basename,m.output);
- ancestor_classes.push_back(ancestor_class(m._name,normalize_path(c,strip_leading_slash)));
+ string c = konforka::combine_path(component_basename,m.output);
+ ancestor_classes.push_back(ancestor_class(m._name,konforka::normalize_path(c,konforka::strip_leading_slash)));
modi.pop_front();
BEGIN(INITIAL);
}
}
<VARLINE>{
{WHITESPACE}+ {
modus_operandi& m = M();
if(!m.output.empty()) {
if(!m._lastid.empty()) {
if(!m._type.empty()) m._type += ' ';
m._type += m._lastid;
}
m._lastid = m.output;
m.output.clear();
}
}
\* {
modus_operandi& m = M();
ECHO;
if(!m._lastid.empty()) {
if(!m._type.empty()) m._type += ' ';
m._type += m._lastid;
}
m._lastid = m.output;
m.output.clear();
}
\;|\n|\= {
modus_operandi& m = M();
if(m.output.empty()) {
m._name=m._lastid;
}else{
if(!m._lastid.empty()) { // XXX: lastid should never be emtpy, I believe?
if(!m._type.empty()) m._type += ' ';
m._type += m._lastid;
}
m._name=m.output;
m.output.clear();
}
BEGIN(VARINIT);
if(*yytext!='=')
unput('\n');
}
}
<VARINIT>{
\n {
modus_operandi& m = M();
string::size_type t = m.output.find_first_not_of(" \t");
if(t!=string::npos)
m.output.erase(0,t);
t = m.output.find_last_not_of(" \t;");
if(t!=string::npos)
m.output.erase(t+1);
member_variables.push_back(member_variable(m._type,m._name,m.output));
if(!m.output.empty())
have_initializers=true;
modi.pop_front();
BEGIN(INITIAL);
}
}
<DECLLINE>\n {
ECHO;
decl += M().output;
modi.pop_front();
BEGIN(INITIAL);
}
<IMPLLINE>\n {
ECHO;
impl += M().output;
modi.pop_front();
BEGIN(INITIAL);
}
<CLASSLINE>\n {
class_name = M().output;
modi.pop_front();
BEGIN(INITIAL);
}
<CLASSLINE,DECLLINE,IMPLLINE,VARLINE,VARINIT,IMPORTLINE,IMPORTCOMPONENT,CODEMETHODLINE,CODEMETHODARGS,INLINE,METHODLINE,METHODARGS,DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,CODELINE,CODEBLOCK,PRAGMALINE,DERIVELINE,DERIVECOMPONENT>{
"/*" {
yy_push_state(SLASHSTAR_COMMENT);
if(!M().devour_comments()) {
ECHO;
}
}
"//" {
yy_push_state(SLASHSLASH_COMMENT);
if(!M().devour_comments()) {
ECHO;
}
}
\" {
yy_push_state(STRING);
ECHO;
}
\'\\.\' {
ECHO;