diff --git a/shared/tools/sdf2bgf b/shared/tools/sdf2bgf index 38139af7..e883ef4e 100755 --- a/shared/tools/sdf2bgf +++ b/shared/tools/sdf2bgf @@ -3,7 +3,7 @@ # Get our hands on basedir LOCAL1=${PWD} cd `dirname $0` -cd ../../topics/extraction/sdf2bgf +cd ../../topics/extraction/sdf XTR=${PWD} cd ${LOCAL1} @@ -32,6 +32,23 @@ else else echo ")" >> _.def cat _.def | sglr -p ${XTR}/Main.tbl | asfe -e ${XTR}/Main.eqs | unparsePT > $i + # a fix for -> + perl -pi -w -e 's/strcon2chardata\(\"\-\>\"\)/\-\>/g;' $i + # a fix for <= + perl -pi -w -e 's/strcon2chardata\(\"\<\=\"\)/\<\=/g;' $i + perl -pi -w -e "s/sqstrcon2chardata\(\'\<\=\'\)/\<\=/g;" $i + # a fix for << + perl -pi -w -e 's/strcon2chardata\(\"\<\<\"\)/\<\</g;' $i + # a fix for <<= + perl -pi -w -e 's/strcon2chardata\(\"\<\<\=\"\)/\<\<\=/g;' $i + # a fix for >> + perl -pi -w -e 's/strcon2chardata\(\"\>\>\"\)/\>\>/g;' $i + # a fix for &= + perl -pi -w -e 's/strcon2chardata\(\"\&\=\"\)/\&\=/g;' $i + # a fix for >= + perl -pi -w -e 's/\\>\=\<\/terminal\>/\\>\=\<\/terminal\>/g;' $i + # a fix for >>= + perl -pi -w -e 's/\\>\>\=\<\/terminal\>/\\>\>\=\<\/terminal\>/g;' $i fi done rm -f _.def diff --git a/topics/extraction/sdf2bgf/Main.asf b/topics/extraction/sdf/Main.asf similarity index 90% rename from topics/extraction/sdf2bgf/Main.asf rename to topics/extraction/sdf/Main.asf index 6ab92bb8..790b7082 100644 --- a/topics/extraction/sdf2bgf/Main.asf +++ b/topics/extraction/sdf/Main.asf @@ -93,7 +93,7 @@ trafoSymbol(&N1) = &C1 -[terminal] +[terminal-1] &C1 := strcon2chardata(&Z1) ================== trafoSymbol(&Z1) = @@ -101,6 +101,14 @@ trafoSymbol(&Z1) = &C1 +[terminal-2] +&C1 := sqstrcon2chardata(&Y1) +================== +trafoSymbol(&Y1) = + + &C1 + + equations [plus] @@ -175,6 +183,16 @@ trafoSymbol((&S1 &S2 &S+1)) = +[selector-1] +&E1 := trafoSymbol(&N1) +================ +trafoSymbol(&I1:&N1) = + + + idcon2chardata(&I1) + &E1 + + [cons-to-label-only-cons] guessLabel({cons(&I1)}) = diff --git a/topics/extraction/sdf2bgf/Main.sdf b/topics/extraction/sdf/Main.sdf similarity index 97% rename from topics/extraction/sdf2bgf/Main.sdf rename to topics/extraction/sdf/Main.sdf index 1cf39e54..b39841db 100644 --- a/topics/extraction/sdf2bgf/Main.sdf +++ b/topics/extraction/sdf/Main.sdf @@ -49,4 +49,5 @@ module Main "&S+" [0-9]+ -> Symbol+ "&Ss" [0-9]+ -> Symbols "&Z" [0-9]+ -> StrCon + "&Y" [0-9]+ -> SingleQuotedStrCon "&I" [0-9]+ -> IdCon diff --git a/topics/extraction/sdf2bgf/Main.trm b/topics/extraction/sdf/Main.trm similarity index 100% rename from topics/extraction/sdf2bgf/Main.trm rename to topics/extraction/sdf/Main.trm diff --git a/topics/extraction/sdf2bgf/Makefile b/topics/extraction/sdf/Makefile similarity index 100% rename from topics/extraction/sdf2bgf/Makefile rename to topics/extraction/sdf/Makefile diff --git a/topics/extraction/sdf2bgf/Tokens.asf b/topics/extraction/sdf/Tokens.asf similarity index 50% rename from topics/extraction/sdf2bgf/Tokens.asf rename to topics/extraction/sdf/Tokens.asf index 7b450894..110a8e6a 100644 --- a/topics/extraction/sdf2bgf/Tokens.asf +++ b/topics/extraction/sdf/Tokens.asf @@ -14,10 +14,25 @@ sort2chardata(sort(&Head1 &Middle1 &Middles1 &Last1)) = chardata(&Char1 &Middle1 equations +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%% StrCon -> CharData +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%[strcon-of-length-1] %% Not working! But needed for &, <, >, etc. %%strcon2chardata(strcon(\" strchar(\&) \")) = entityref(& name(letter(a) namechar(letter(m)) namechar(letter(p))) ;) +[strcon-of-length-1-lt] +strcon2chardata(strcon(\" strchar(\<) \")) = < + +[strcon-of-length-1-gt] +strcon2chardata(strcon(\" strchar(\>) \")) = > + +[strcon-of-length-1-amp] +strcon2chardata(strcon(\" strchar(\&) \")) = & + +%%[strcon-of-length-1-minus] +%%strcon2chardata(strcon(\" strchar(\-) \")) = "-" [default-strcon-of-length-1] strchar(&Chr1) := &StrChar1 @@ -30,6 +45,34 @@ chardata(&Char1 &Chars1) := strcon2chardata(strcon(\" &StrChar+2 \")) =========================================================== strcon2chardata(strcon(\" &StrChar1 &StrChar+2 \")) = chardata(&Chr1 &Char1 &Chars1) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%% SingleQuotedStrCon -> CharData +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +[sqstrcon-of-length-1-lt] +sqstrcon2chardata(singlequotedstrcon(\' singlequotedstrchar(\<) \')) = < + +[sqstrcon-of-length-1-gt] +sqstrcon2chardata(singlequotedstrcon(\' singlequotedstrchar(\>) \')) = > + +[sqstrcon-of-length-1-amp] +sqstrcon2chardata(singlequotedstrcon(\' singlequotedstrchar(\&) \')) = & + +[default-sqstrcon-of-length-1] +singlequotedstrchar(&Ch1) := &SQStrChar1 +======================================== +sqstrcon2chardata(singlequotedstrcon(\' &SQStrChar1 \')) = chardata(&Ch1) + +[sqstrcon-of-length-greater-than-1] +singlequotedstrchar(&Ch1) := &SQStrChar1, +chardata(&Char1 &Chars1) := sqstrcon2chardata(singlequotedstrcon(\' &SQStrChar+2 \')) +=========================================================== +sqstrcon2chardata(singlequotedstrcon(\' &SQStrChar1 &SQStrChar+2 \')) = chardata(&Ch1 &Char1 &Chars1) + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%% IdCon -> CharData +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + [idcon-of-length-1] idcon2chardata(idcon(&IdHead1)) = chardata(&IdHead1) diff --git a/topics/extraction/sdf/Tokens.sdf b/topics/extraction/sdf/Tokens.sdf new file mode 100644 index 00000000..ef5915ec --- /dev/null +++ b/topics/extraction/sdf/Tokens.sdf @@ -0,0 +1,56 @@ +module Tokens + +imports + languages/sdf2/syntax/Literals + languages/sdf2/syntax/Sorts + languages/xml/syntax/XML + basic/StrCon + basic/IdentifierCon + +exports + sorts + CharData + context-free syntax + sort2chardata(Sort) -> CharData + strcon2chardata(StrCon) -> Content + sqstrcon2chardata(SingleQuotedStrCon) -> Content + idcon2chardata(IdCon) -> CharData + strchar2strcon(StrChar) -> Content + +hiddens + lexical syntax + %% Let's remind ourselves of the relevant lexical syntax. + %% + %% 1. languages/sdf2/syntax/Sorts + %% head:[A-Z] -> Sort {cons("one-char")} + %% head:[A-Z] middle:[A-Za-z0-9\-]* last:[A-Za-z0-9] -> Sort {cons("more-chars")} + %% + %% 2. languages/xml/syntax/XML + %% ~[\<\&]+ -> CharData {avoid} + %% ~[\<\&]* "]]>" ~[\<\&]* -> CharData {reject} + %% + %% 3. basic/StrCon + %% "\\n" -> StrChar {cons("newline")} + %% "\\t" -> StrChar {cons("tab")} + %% "\\\"" -> StrChar {cons("quote")} + %% "\\\\" -> StrChar {cons("backslash")} + %% "\\" a:[0-9]b:[0-9]c:[0-9] -> StrChar {cons("decimal")} + %% ~[\0-\31\n\t\"\\] -> StrChar {cons("normal")} + %% [\"] chars:StrChar* [\"] -> StrCon {cons("default")} + + lexical variables + "&Head" [0-9]* -> [A-Z] %% Part of Sort + "&IdHead" [0-9]* -> [A-Za-z] %% Part of IdCon + "&Middle" [0-9]* -> [A-Za-z0-9\-] %% Part of Sort + "&Middles" [0-9]* -> [A-Za-z0-9\-]* %% Part of Sort + "&Last" [0-9]* -> [A-Za-z0-9] %% Part of Sort + "&Char" [0-9]* -> ~[\<\&] %% Part of CharData + "&Chars" [0-9]* -> ~[\<\&]* %% Part of CharData + "&StrChar" [0-9]* -> StrChar %% Part of StrCon + "&StrChar+" [0-9]* -> StrChar+ %% Part of StrCon + "&Chr" [0-9]* -> ~[\0-\31\n\t\"\\\<\&] + "&Ch" [0-9]* -> ~[\0-\31\n\t\'\\\<\&] + "&Both" -> ~[\0-\31\n\t\"\\\<\&] /\ ~[\<\&] + "&StrCon" [0-9]* -> StrCon + "&SQStrChar" [0-9]* -> SingleQuotedStrChar %% Part of SingleQuotedStrCon + "&SQStrChar+" [0-9]* -> SingleQuotedStrChar+ %% Part of SingleQuotedStrCon diff --git a/topics/extraction/sdf2bgf/sdflib.list b/topics/extraction/sdf/sdflib.list similarity index 100% rename from topics/extraction/sdf2bgf/sdflib.list rename to topics/extraction/sdf/sdflib.list diff --git a/topics/extraction/sdf2bgf/Tokens.sdf b/topics/extraction/sdf2bgf/Tokens.sdf deleted file mode 100644 index aec9c82f..00000000 --- a/topics/extraction/sdf2bgf/Tokens.sdf +++ /dev/null @@ -1,48 +0,0 @@ -module Tokens - -imports - languages/sdf2/syntax/Sorts - languages/xml/syntax/XML - basic/StrCon - basic/IdentifierCon - -exports - sorts - CharData - context-free syntax - sort2chardata(Sort) -> CharData - strcon2chardata(StrCon) -> Content - idcon2chardata(IdCon) -> CharData - -hiddens - lexical syntax - %% Let's remind ourselves of the relevant lexical syntax. - %% - %% 1. languages/sdf2/syntax/Sorts - %% head:[A-Z] -> Sort {cons("one-char")} - %% head:[A-Z] middle:[A-Za-z0-9\-]* last:[A-Za-z0-9] -> Sort {cons("more-chars")} - %% - %% 2. languages/xml/syntax/XML - %% ~[\<\&]+ -> CharData {avoid} - %% ~[\<\&]* "]]>" ~[\<\&]* -> CharData {reject} - %% - %% 3. basic/StrCon - %% "\\n" -> StrChar {cons("newline")} - %% "\\t" -> StrChar {cons("tab")} - %% "\\\"" -> StrChar {cons("quote")} - %% "\\\\" -> StrChar {cons("backslash")} - %% "\\" a:[0-9]b:[0-9]c:[0-9] -> StrChar {cons("decimal")} - %% ~[\0-\31\n\t\"\\] -> StrChar {cons("normal")} - %% [\"] chars:StrChar* [\"] -> StrCon {cons("default")} - - lexical variables - "&Head" [0-9]* -> [A-Z] %% Part of Sort - "&IdHead" [0-9]* -> [A-Za-z] %% Part of IdCon - "&Middle" [0-9]* -> [A-Za-z0-9\-] %% Part of Sort - "&Middles" [0-9]* -> [A-Za-z0-9\-]* %% Part of Sort - "&Last" [0-9]* -> [A-Za-z0-9] %% Part of Sort - "&Char" [0-9]* -> ~[\<\&] %% Part of CharData - "&Chars" [0-9]* -> ~[\<\&]* %% Part of CharData - "&StrChar" [0-9]* -> StrChar %% Part of StrCon - "&StrChar+" [0-9]* -> StrChar+ %% Part of StrCon - "&Chr" [0-9]* -> ~[\0-\31\n\t\"\\\<\&]