<commit_before>module ParserAndCompiler.Parser.Version0p0 where
{- Standard library imports -} 
import String
import List
import Either

{- Internal modules -}
import LevelizedGraphs.Graph as Graph
import State.EditorState as EditorState

version         = {major=0,minor=0}
header          = "{-GENERATED BY GRAPHICALELM0.0-}"
miscEntryMarker = "{-MISC_ENTRY-}"
eolMarker       = "{-*****-}"
codeQuoteOpen   = "#####$#"
codeQuoteClose  = "#$#####"

headerLength = String.length header

parseSavedGraph: String -> Either.Either String EditorState.EditorState
parseSavedGraph content' =
 let content = String.trim content' in
 if String.startsWith header content
 then
  (  String.split eolMarker (String.dropLeft headerLength content)
  |> foldl parseEntry (Either.Right EditorState.emptyEditorState))
 else Either.Left <| "Error loading file: Header does not match."

parseEntry: String -> Either.Either String EditorState.EditorState -> Either.Either String EditorState.EditorState
parseEntry entry gesE =
 let
  parseMisc' ges =
   case parseMisc entry of
    (Parsed m)  -> Either.Right {ges|misc<-m++"\n"++ges.misc}
    Drop        -> Either.Right ges
    (Error err) -> Either.Left  err
  parseSavedNode' ges =
   case parseSavedNode entry of
    (Parsed n)  -> Either.Right {ges|graph<-n::ges.graph}
    Drop        -> Either.Right ges
    (Error err) -> Either.Left  err
 in
 case gesE of
  (Either.Right ges) ->
   if | String.trim entry == "" -> Either.Right ges
      | String.contains miscEntryMarker entry -> parseMisc' ges
      | otherwise -> parseSavedNode' ges
  (Either.Left err) -> Either.Left err

data Parsed a = Parsed a | Drop | Error String

parseSavedNode: String -> Parsed Graph.Node
parseSavedNode raw =
 let
  headSplit = String.split "=" <| String.dropLeft 1 raw
  name = head headSplit
 in
 if raw == ""
 then Drop
 else
 case String.split "{-_language_" raw of
  (_::raw'::[]) ->
   let
    languageString = head <| String.split "_base_code_" raw'
    language =
     if | languageString == "ElmLang" -> Graph.ElmLang
        | languageString == "Ikcilpazc" -> Graph.Ikcilpazc
    code = inQuotes codeQuoteOpen codeQuoteClose raw'
    parents' =
     case String.split "_parents_-}" raw' of
      (_::raw''::[]) -> String.split "~" raw''
    parents =
     case parents' of
      (p::[]) -> if | p == "" -> []
                    | otherwise -> parents'
      _ -> parents'
   in Parsed {name=name,parents=parents,value={code=code,language=language,ntype=Nothing}}
  _ -> Error <| "Parse error, cannot parse:" ++ raw

parseMisc: String -> Parsed String
parseMisc miscEntry = Parsed <| String.dropRight (String.length miscEntryMarker) miscEntry

inQuotes: String -> String -> String -> String
inQuotes startQuote endQuote fullString =
 case String.split startQuote fullString of
  (_::afterQuote::[]) ->
   case String.split endQuote afterQuote of
    (inQuotes'::_) -> inQuotes'
{-
Graphical ELM - A program for editing graphs as graphs.
Visually, Architecturally

    Copyright (C) 2013  <NAME> <<EMAIL>> thobbs.cz

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-}
<commit_msg>We renamed ElmLang to LiftElm, kinda confusing... But the new model makes sense.<commit_after>module ParserAndCompiler.Parser.Version0p0 where
{- Standard library imports -} 
import String
import List
import Either

{- Internal modules -}
import LevelizedGraphs.Graph as Graph
import State.EditorState as EditorState

version         = {major=0,minor=0}
header          = "{-GENERATED BY GRAPHICALELM0.0-}"
miscEntryMarker = "{-MISC_ENTRY-}"
eolMarker       = "{-*****-}"
codeQuoteOpen   = "#####$#"
codeQuoteClose  = "#$#####"

headerLength = String.length header

parseSavedGraph: String -> Either.Either String EditorState.EditorState
parseSavedGraph content' =
 let content = String.trim content' in
 if String.startsWith header content
 then
  (  String.split eolMarker (String.dropLeft headerLength content)
  |> foldl parseEntry (Either.Right EditorState.emptyEditorState))
 else Either.Left <| "Error loading file: Header does not match."

parseEntry: String -> Either.Either String EditorState.EditorState -> Either.Either String EditorState.EditorState
parseEntry entry gesE =
 let
  parseMisc' ges =
   case parseMisc entry of
    (Parsed m)  -> Either.Right {ges|misc<-m++"\n"++ges.misc}
    Drop        -> Either.Right ges
    (Error err) -> Either.Left  err
  parseSavedNode' ges =
   case parseSavedNode entry of
    (Parsed n)  -> Either.Right {ges|graph<-n::ges.graph}
    Drop        -> Either.Right ges
    (Error err) -> Either.Left  err
 in
 case gesE of
  (Either.Right ges) ->
   if | String.trim entry == "" -> Either.Right ges
      | String.contains miscEntryMarker entry -> parseMisc' ges
      | otherwise -> parseSavedNode' ges
  (Either.Left err) -> Either.Left err

data Parsed a = Parsed a | Drop | Error String

parseSavedNode: String -> Parsed Graph.Node
parseSavedNode raw =
 let
  headSplit = String.split "=" <| String.dropLeft 1 raw
  name = head headSplit
 in
 if raw == ""
 then Drop
 else
 case String.split "{-_language_" raw of
  (_::raw'::[]) ->
   let
    languageString = head <| String.split "_base_code_" raw'
    language =
     if | languageString == "ElmLang" -> Graph.LiftElm
        | languageString == "Ikcilpazc" -> Graph.Ikcilpazc
    code = inQuotes codeQuoteOpen codeQuoteClose raw'
    parents' =
     case String.split "_parents_-}" raw' of
      (_::raw''::[]) -> String.split "~" raw''
    parents =
     case parents' of
      (p::[]) -> if | p == "" -> []
                    | otherwise -> parents'
      _ -> parents'
   in Parsed {name=name,parents=parents,value={code=code,language=language,ntype=Nothing}}
  _ -> Error <| "Parse error, cannot parse:" ++ raw

parseMisc: String -> Parsed String
parseMisc miscEntry = Parsed <| String.dropRight (String.length miscEntryMarker) miscEntry

inQuotes: String -> String -> String -> String
inQuotes startQuote endQuote fullString =
 case String.split startQuote fullString of
  (_::afterQuote::[]) ->
   case String.split endQuote afterQuote of
    (inQuotes'::_) -> inQuotes'
{-
Graphical ELM - A program for editing graphs as graphs.
Visually, Architecturally

    Copyright (C) 2013  <NAME> <<EMAIL>> thobbs.cz

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-}

{'fraction_non_alphanumeric': 0.10836981031967105, 'fraction_numerical': 0.0031834460803820135, 'mean_word_length': 3.3558636626227614, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '923058', 'n_tokens_mistral': 2269, 'n_tokens_neox': 2174, 'n_words': 762}