<commit_before>﻿module AST
    open System
    open System.Diagnostics
    open System.Collections.Generic
    open System.Text

    type IndirectAddressingNotSupportedException(expression: string) =
        inherit Exception(expression)

    // The Env object is threaded through grammar combinators (via UserState)
    // so that parsers always have the path, workbook name, and worksheet name
    // from the calling workbook environment in order to construct fully-
    // qualified AST nodes.
    [<Serializable>]
    type Env(path: string, wbname: string, wsname: string) =
        member self.Path = path
        member self.WorkbookName = wbname
        member self.WorksheetName = wsname
        override self.GetHashCode() : int =
            path.GetHashCode() |||
            wbname.GetHashCode() |||
            wsname.GetHashCode()
        override self.Equals(obj: obj) : bool =
            let d2 = obj :?> Env
            path = d2.Path &&
            wbname = d2.WorkbookName &&
            wsname = d2.WorksheetName

    [<Serializable>]
    type AddressMode =
    | Absolute
    | Relative

    [<Serializable>]
    type Address(R: int, C: int, Rmode: AddressMode, Cmode: AddressMode, env: Env) =
        let mutable _cachedHC : int option = None

        new(R: int, C: int, env: Env) = Address(R, C, Relative, Relative, env)

        interface IComparable with
            member self.CompareTo(obj) =
                let addr = obj :?> Address
                match env.WorksheetName.CompareTo(addr.WorksheetName) with
                | -1 -> -1
                | 1  -> 1
                | _  ->
                    // this guarantees a consistent total order, but if used in user-facing
                    // contexts, it might not be very intuitive to end-users.
                    let c = Hash.cantorPair (System.Convert.ToUInt32 R) (System.Convert.ToUInt32 R) System.UInt32.MaxValue
                    let c' = Hash.cantorPair (System.Convert.ToUInt32 addr.Row) (System.Convert.ToUInt32 addr.Col) System.UInt32.MaxValue
                    c.CompareTo c'

        static member fromR1C1withMode(R: int, C: int, Rmode: AddressMode, Cmode: AddressMode, wsname: string, wbname: string, path: string) : Address =
            Address(R, C, Rmode, Cmode, Env(path, wbname, wsname))
        static member fromA1withMode(row: int, col: string, Rmode: AddressMode, Cmode: AddressMode, wsname: string, wbname: string, path: string) : Address =
            Address(row, Address.CharColToInt(col), Rmode, Cmode, Env(path, wbname, wsname))
        member self.copyWithNewEnv(envnew: Env) =
            Address(R, C, Rmode, Cmode, envnew)
        member self.A1Local() : string = Address.IntToColChars(self.X) + self.Y.ToString()
        member self.A1Path() : string = env.Path
        member self.A1Worksheet() : string = env.WorksheetName
        member self.A1Workbook() : string = env.WorkbookName
        member self.A1FullyQualified() : string =
            "[" + self.A1Workbook() + "]" + self.A1Worksheet() + "!" + self.A1Local()
        member self.R1C1 =
            let wsstr = env.WorksheetName + "!"
            let wbstr = "[" + env.WorkbookName + "]"
            let pstr = env.Path
            pstr + wbstr + wsstr + "R" + R.ToString() + "C" + C.ToString()
        member self.XMode = Cmode
        member self.YMode = Rmode
        member self.X: int = C
        member self.Y: int = R
        member self.RowMode = Rmode
        member self.ColMode = Cmode
        member self.Row = R
        member self.Col = C
        member self.Path = env.Path
        member self.WorksheetName = env.WorksheetName
        member self.WorkbookName = env.WorkbookName<commit_msg>Print address mode.<commit_after>﻿module AST
    open System
    open System.Diagnostics
    open System.Collections.Generic
    open System.Text

    type IndirectAddressingNotSupportedException(expression: string) =
        inherit Exception(expression)

    // The Env object is threaded through grammar combinators (via UserState)
    // so that parsers always have the path, workbook name, and worksheet name
    // from the calling workbook environment in order to construct fully-
    // qualified AST nodes.
    [<Serializable>]
    type Env(path: string, wbname: string, wsname: string) =
        member self.Path = path
        member self.WorkbookName = wbname
        member self.WorksheetName = wsname
        override self.GetHashCode() : int =
            path.GetHashCode() |||
            wbname.GetHashCode() |||
            wsname.GetHashCode()
        override self.Equals(obj: obj) : bool =
            let d2 = obj :?> Env
            path = d2.Path &&
            wbname = d2.WorkbookName &&
            wsname = d2.WorksheetName

    [<Serializable>]
    type AddressMode =
    | Absolute
    | Relative

    [<Serializable>]
    type Address(R: int, C: int, Rmode: AddressMode, Cmode: AddressMode, env: Env) =
        let mutable _cachedHC : int option = None

        new(R: int, C: int, env: Env) = Address(R, C, Relative, Relative, env)

        interface IComparable with
            member self.CompareTo(obj) =
                let addr = obj :?> Address
                match env.WorksheetName.CompareTo(addr.WorksheetName) with
                | -1 -> -1
                | 1  -> 1
                | _  ->
                    // this guarantees a consistent total order, but if used in user-facing
                    // contexts, it might not be very intuitive to end-users.
                    let c = Hash.cantorPair (System.Convert.ToUInt32 R) (System.Convert.ToUInt32 R) System.UInt32.MaxValue
                    let c' = Hash.cantorPair (System.Convert.ToUInt32 addr.Row) (System.Convert.ToUInt32 addr.Col) System.UInt32.MaxValue
                    c.CompareTo c'

        static member fromR1C1withMode(R: int, C: int, Rmode: AddressMode, Cmode: AddressMode, wsname: string, wbname: string, path: string) : Address =
            Address(R, C, Rmode, Cmode, Env(path, wbname, wsname))
        static member fromA1withMode(row: int, col: string, Rmode: AddressMode, Cmode: AddressMode, wsname: string, wbname: string, path: string) : Address =
            Address(row, Address.CharColToInt(col), Rmode, Cmode, Env(path, wbname, wsname))
        member self.copyWithNewEnv(envnew: Env) =
            Address(R, C, Rmode, Cmode, envnew)
        member self.A1Local() : string =
            let cmode =
                match self.ColMode with
                | AddressMode.Absolute -> "$"
                | AddressMode.Relative -> ""
            let rmode =
                match self.RowMode with
                | AddressMode.Absolute -> "$"
                | AddressMode.Relative -> ""
            cmode + Address.IntToColChars(self.X) + rmode + self.Y.ToString()
        member self.A1Path() : string = env.Path
        member self.A1Worksheet() : string = env.WorksheetName
        member self.A1Workbook() : string = env.WorkbookName
        member self.A1FullyQualified() : string =
            "[" + self.A1Workbook() + "]" + self.A1Worksheet() + "!" + self.A1Local()
        member self.R1C1 =
            let wsstr = env.WorksheetName + "!"
            let wbstr = "[" + env.WorkbookName + "]"
            let pstr = env.Path
            pstr + wbstr + wsstr + "R" + R.ToString() + "C" + C.ToString()
        member self.XMode = Cmode
        member self.YMode = Rmode
        member self.X: int = C
        member self.Y: int = R
        member self.RowMode = Rmode
        member self.ColMode = Cmode
        member self.Row = R
        member self.Col = C
        member self.Path = env.Path
        member self.WorksheetName = env.WorksheetName
        member self.WorkbookName = env.WorkbookName
{'fraction_non_alphanumeric': 0.1018590240123935, 'fraction_numerical': 0.008520526723470178, 'mean_word_length': 2.0620553359683793, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2521082', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2224, 'n_words': 631}