Changeset 1387


Ignore:
Timestamp:
Oct 29, 2011, 11:56:56 PM (6 years ago)
Author:
joerg
Message:

improved trees

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripting/haskell/Trees.hs

    r1377 r1387  
    4242        hPutStr stdout $ "\\begin{pgfonlayer}{background}"
    4343        hPutStrLn stdout $ concat $ map (\h ->
    44           -- "\n  " ++ intersections (nodes h) ++
    4544          "\n  " ++ renderHighlight term h) highlights
    4645        hPutStrLn stdout $ "\\end{pgfonlayer}"
     
    7170  | otherwise      = or $ map (nested n m) (subterms term)   
    7271
    73 {-
    74 hPath n = "h_" ++ n
    75 vPath n = "v_" ++ n
    76 iName n m = "i_" ++ n ++ "_" ++ m
    77 
    78 intersections (n:m:nodes) =
    79   let move p x y =  "($(" ++ p ++ ")+(" ++ show x ++ "cm," ++ show y ++ "cm)$)"
    80       hpath n = "\\path [draw=none,name path=" ++ hPath n ++ "] " ++ move n (-10) 0 ++ " -- " ++ move n 10 0 ++ ";\n"
    81       vpath n = "\\path [draw=none,name path=" ++ vPath n ++ "] " ++ move n 0 (-10) ++ " -- " ++ move n 0 10 ++ ";\n"
    82       intersect n m = "\\path [name intersections={of=" ++ hPath n ++ " and " ++ vPath m ++ "}];\n" ++
    83                       "\\coordinate ("++ iName n m ++ ") at (intersection-1);\n"
    84   in hpath n ++ vpath n ++ hpath m ++ vpath m ++ intersect n m ++ intersect m n ++ intersections (m:nodes)
    85 intersections _ = ""
    86 -}
     72data Direction = Up | Eq | Down
     73
     74directions :: [Int] -> [Direction]
     75directions (a:b:xs)
     76  | a < b = Down : directions (b:xs)
     77  | a > b = Up : directions (b:xs)
     78  | otherwise = Eq : directions (b:xs)
     79directions _ = []
     80
     81up_down :: Term -> [String] -> [(Direction,(String,(Direction,String)))]
     82up_down term nodes =
     83  let depths = map (\n -> depth n term) nodes
     84  in zip (directions $ (-1):depths) $ zip nodes $ zip (directions $ depths ++ [-1]) $ (tail nodes ++ [head nodes])
     85
     86north_east n = "($(" ++ n ++ ".north east) + (.7mm,-.7mm)$)"
     87north_west n = "($(" ++ n ++ ".north west) + (-.7mm,-.7mm)$)"
     88south_east n = "($(" ++ n ++ ".south east) + (.7mm,.7mm)$)"
     89south_west n = "($(" ++ n ++ ".south west) + (-.7mm,.7mm)$)"
     90south n = "($(" ++ n ++ ".south) + (0mm,-1mm)$)"
     91north n = "($(" ++ n ++ ".north) + (0mm,1mm)$)"
     92on_way_left p n = "($(" ++ p ++ ") !.15! 270:(" ++ n ++ ") !.4! (" ++ n ++ ")$)"
     93on_way_right p n = "($(" ++ p ++ ") !.15! 90:(" ++ n ++ ") !.4! (" ++ n ++ ")$)"
    8794
    8895renderHighlight :: Term -> Highlight -> String
    8996renderHighlight tree highlight =
    90   "\\draw [rounded corners=1.5mm] " ++ style highlight ++ " " ++ renderHighlight_ tree "" (nodes highlight)
    91 
    92 north_east y n = "($(" ++ n ++ ".north east) + (1mm," ++ show y ++ "mm)$)"
    93 north_west y n = "($(" ++ n ++ ".north west) + (-1mm," ++ show y ++ "mm)$)"
    94 south_east n = "($(" ++ n ++ ".south east) + (1mm,0mm)$)"
    95 south_west n = "($(" ++ n ++ ".south west) + (-1mm,0mm)$)"
    96 south n = "($(" ++ n ++ ".south) + (0mm,-1mm)$)"
    97 north n = "($(" ++ n ++ ".north) + (0mm,1mm)$)"
    98 
    99 renderHighlight_ tree p [] = south p ++ " -- " ++ south_east p ++ " -- " ++ north_east (-1) p ++ " -- cycle;"
    100 renderHighlight_ tree p (n:ns) =
    101   let nesting = nested p n tree
     97  let root = head $ nodes highlight
    10298  in
    103   -- root node
    104   (if p == ""
    105     then south_east n ++ " -- " ++ north_east (-1) n ++ " -- " ++ north n ++ " -- "
    106     else "")
    107   ++
    108   -- previous node deeper or equal depth
    109   (if depth p tree >= depth n tree || not (nested p n tree)
    110     then south p ++ " -- " ++ south_east p ++ " -- "
    111          ++ (if depth p tree > depth n tree then north_east (-1) p ++ " -- " else "")
    112          ++ (if not (nested p n tree) then south_west n ++ " -- " else "")
    113     else
    114     (if depth p tree < depth n tree
    115       then north_west (-1) n ++ " -- " ++ south_west n ++ " -- "
    116       else south n ++ " -- "))
    117   ++ renderHighlight_ tree n ns
     99  "\\draw [rounded corners=1.5mm] " ++ style highlight ++ " " ++
     100  -- root
     101  south_east root ++ " -- " ++ north_east root ++ " -- " ++ north root ++ " -- " ++
     102  -- remaining path
     103  renderHighlight_ tree (up_down tree $ nodes highlight)
     104
     105renderHighlight_ tree [] = "cycle;"
     106--south p ++ " -- " ++ south_east p ++ " -- " ++ north_east p ++ " -- cycle;"
     107renderHighlight_ tree ((d1,(n,(d2,nn))):ns) =
     108  (case d1 of
     109     Down -> north_west n ++ " -- " ++ south_west n ++ " -- " ++
     110             case d2 of
     111               Down -> ""
     112               Eq   -> south n ++ " -- " ++ south_east n ++ " -- "
     113               Up   -> south n ++ " -- " ++ south_east n ++ " -- " ++ north_east n ++ " -- "
     114             ++ on_way_left n nn ++ " -- " ++ on_way_right nn n ++ " -- "
     115     Eq   -> south_west n ++ " -- " ++
     116             case d2 of
     117               Down -> ""
     118               Eq   -> south n ++ " -- " ++ south_east n ++ " -- "
     119               Up   -> south n ++ " -- " ++ south_east n ++ " -- " ++ north_east n ++ " -- "
     120             ++ on_way_left n nn ++ " -- " ++ on_way_right nn n ++ " -- "
     121     Up   -> case d2 of
     122               Down -> ""
     123               Eq   -> south_east n ++ " -- "
     124               Up   -> south_east n ++ " -- " ++ north_east n ++ " -- "
     125             ++ on_way_left n nn ++ " -- " ++ on_way_right nn n ++ " -- "
     126  ) ++ renderHighlight_ tree ns
     127
     128-- || not (nested p n tree)
    118129
    119130--------------------------------------------------------------------------------
  • trunk/src/jlatexeditor/codehelper/ScriptingSupport.java

    r1385 r1387  
    1515import java.io.*;
    1616import java.util.ArrayList;
     17import java.util.Arrays;
     18import java.util.HashSet;
    1719import java.util.List;
    1820
     
    2123 */
    2224public class ScriptingSupport implements CodeAssistant {
    23   private String genericBegin = "%!begin{";
    24   private String[] languages = new String [] {"haskell", "tree"};
     25  public static final String genericBegin = "%!begin{";
     26  public static final String[] languages = new String [] {"haskell", "tree"};
     27  public static final HashSet<String> languagesSet = new HashSet<String>(Arrays.asList(languages));
    2528
    2629  public ScriptingSupport() {
  • trunk/src/jlatexeditor/syntaxhighlighting/LatexSyntaxHighlighting.java

    r1341 r1387  
    22
    33import jlatexeditor.codehelper.BackgroundParser;
     4import jlatexeditor.codehelper.ScriptingSupport;
    45import jlatexeditor.syntaxhighlighting.states.DontParse;
    56import jlatexeditor.syntaxhighlighting.states.Env;
    67import jlatexeditor.syntaxhighlighting.states.MathMode;
     8import jlatexeditor.syntaxhighlighting.states.ScriptMode;
    79import sce.codehelper.CHArgumentType;
    810import sce.codehelper.CHCommand;
     
    1214import sce.syntaxhighlighting.ParserStateStack;
    1315import sce.syntaxhighlighting.SyntaxHighlighting;
     16import sun.font.Script;
    1417import util.Function1;
    1518import util.SimpleTrie;
     
    4144  private BackgroundParser backgroundParser;
    4245
     46  private static final String scriptBegin = ScriptingSupport.genericBegin.substring(1);
     47
    4348  // do we need to parse
    4449  private boolean parseNeeded = false;
     
    171176      }
    172177    }
     178
     179    if (state instanceof ScriptMode) {
     180      byte styleText = state.getStyles()[LatexStyles.TEXT];
     181      byte styleComment = state.getStyles()[LatexStyles.COMMENT];
     182
     183      for(int nr = 0; nr < row.length; nr++) {
     184        SCEDocumentChar c = chars[nr];
     185
     186        if(c.character == ' ') { c.style = styleText; continue; }
     187        if(c.character == '%') { c.style = styleComment;
     188          for(nr++; nr < row.length; nr++) chars[nr].style = styleText;
     189          rowWasParsed = true;
     190          break;
     191        }
     192
     193        stateStack.pop();
     194        state = stateStack.peek();
     195        break;
     196      }
     197    }
    173198
    174199    if (!rowWasParsed) {
     
    369394              stateStack.push(state = new DontParse(state));
    370395            }
     396          } else
     397          if (restOfRow.startsWith(scriptBegin)) {
     398            int position = char_nr;
     399            while (char_nr < row.length) chars[char_nr++].style = commentStyle;
     400
     401            int offset = scriptBegin.length();
     402            int closing = restOfRow.indexOf('}', offset);
     403            if(closing >= 0) {
     404              String language = restOfRow.substring(offset, closing);
     405              if(ScriptingSupport.languagesSet.contains(language)) {
     406                byte todoStyle = stateStyles[LatexStyles.TODO];
     407                for(int nr = position+offset+1; nr <= position+closing; nr++) chars[nr].style = todoStyle;
     408              }
     409            }
     410
     411            stateStack.push(state = new ScriptMode());
    371412          } else {
    372413            Matcher matcher = TODO_PATTERN.matcher(restOfRow.toLowerCase());
Note: See TracChangeset for help on using the changeset viewer.