Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import strutils, parseutils, pegs, lists
- import npeg
- type
- Section = ref object
- Visible: bool
- Corrupted: bool
- Identified: bool
- ShaperItem: bool
- ElderItem: bool
- FracturedItem: bool
- SynthesisedItem: bool
- AnyEnchantment: bool
- DisableDropSound: bool
- BlightedMap: bool
- ElderMap: bool
- ShapedMap: bool
- BaseType: seq[string]
- Class: seq[string]
- HasExplicitMod: seq[string]
- Prophecy: seq[string]
- SocketGroup: string
- SetFontSize: int
- Rarity: OpAndRarity
- Width: OpAndInt
- Height: OpAndInt
- Quality: OpAndInt
- Sockets: OpAndInt
- MapTier: OpAndInt
- GemLevel: OpAndInt
- StackSize: OpAndInt
- ItemLevel: OpAndInt
- DropLevel: OpAndInt
- LinkedSockets: OpAndInt
- SetTextColor: Color
- SetBorderColor: Color
- SetBackgroundColor: Color
- PlayAlertSound: Sound
- PlayAlertSoundPositional: Sound
- PlayEffect: Effect
- MinimapIcon: Icon
- # Color = ref object
- # r, g, b, a: int
- RarityEnum = enum
- normal = (0, "Normal")
- magic = (1, "Magic")
- rare = (2, "Rare")
- unique = (3,"Unique")
- # ">=" | ">" | "<=" | "<" | "="
- OperatorEnum = enum
- equals = (0, "=")
- greaterOrEqual = (1, ">=")
- greaterThan = (2, ">")
- lessOrEqual = (3, "<=")
- lessThan = (4, "<")
- ColorEnum = enum
- red = (0, "Red")
- green = (1, "Green")
- blue = (2, "Blue")
- brown = (3, "Brown")
- white = (4, "White")
- yellow = (5, "Yellow")
- ShapeEnum = enum
- circle = (0, "Circle")
- diamond = (1, "Diamond")
- hexagon = (2, "Hexagon")
- square = (3, "Square")
- start = (4, "Star")
- triangle = (5, "Triangle")
- Color = ref object
- r, g, b, a: int
- Sound = ref object
- id: int
- volume: int
- Effect = ref object
- id: ColorEnum
- temporary: bool
- Icon = ref object
- size: int
- color: ColorEnum
- shape: ShapeEnum
- OpAndInt = ref object
- operator: OperatorEnum
- value: int
- OpAndRarity = ref object
- operator: OperatorEnum
- rarity: RarityEnum
- Sections = seq[Section]
- var sectionsSeq: Sections
- var curSection: Section
- let p = peg("doc"):
- doc <- S * *section * !1
- section <- ShowHide * S * +(field * S)
- ShowHide <- >("Show" | "Hide"):
- curSection = Section()
- sectionsSeq.add curSection
- if $1 == "Show": curSection.Visible = true else: curSection.Visible = false
- field <- AnyEnchantment |
- BaseType |
- BlightedMap |
- Class |
- Corrupted |
- DisableDropSound |
- DropLevel |
- ElderItem |
- ElderMap |
- FracturedItem |
- GemLevel |
- HasExplicitMod |
- Height |
- Identified |
- ItemLevel |
- LinkedSockets |
- MapTier |
- MinimapIcon |
- PlayAlertSound |
- PlayAlertSoundPositional |
- PlayEffect |
- Prophecy |
- Quality |
- Rarity |
- SetBackgroundColor |
- SetBorderColor |
- SetFontSize |
- SetTextColor |
- ShapedMap |
- ShaperItem |
- SocketGroup |
- Sockets |
- StackSize |
- SynthesisedItem |
- Width
- BaseType <- "BaseType" * S * +(BaseTypeString * S)
- BaseTypeString <- '"' * >*(1-'"') * '"':
- #TODO: split
- curSection.BaseType.add $1
- Class <- "Class" * S * +(ClassString * S)
- ClassString <- '"' * >*(1-'"') * '"':
- #TODO: split
- curSection.Class.add $1
- HasExplicitMod <- "HasExplicitMod" * S * +(HasExplicitModString * S)
- HasExplicitModString <- '"' * >*(1-'"') * '"':
- #TODO: split
- curSection.HasExplicitMod.add $1
- Prophecy <- "Prophecy" * S * +(ProphecyString * S)
- ProphecyString <- '"' * >*(1-'"') * '"':
- #TODO: split
- curSection.Prophecy.add $1
- SocketGroup <- "SocketGroup" * S * >+Graph:
- curSection.SocketGroup = $1
- SetFontSize <- "SetFontSize" * (S * >+Digit):
- curSection.SetFontSize = parseInt($1)
- MapTier <- "MapTier" * S * ?Operator * S * >+Digit:
- curSection.MapTier = OpAndInt(operator: parseEnum[OperatorEnum]($1), value: parseInt($2))
- ItemLevel <- "ItemLevel" * S * ?Operator * S * >+Digit:
- curSection.ItemLevel = OpAndInt(operator: parseEnum[OperatorEnum]($1), value: parseInt($2))
- DropLevel <- "DropLevel" * S * ?Operator * S * >+Digit:
- curSection.DropLevel = OpAndInt(operator: parseEnum[OperatorEnum]($1), value: parseInt($2))
- Width <- "Width" * S * ?Operator * S * >+Digit:
- curSection.Width = OpAndInt(operator: parseEnum[OperatorEnum]($1), value: parseInt($2))
- Height <- "Height" * S * ?Operator * S * >+Digit:
- curSection.Height = OpAndInt(operator: parseEnum[OperatorEnum]($1), value: parseInt($2))
- Quality <- "Quality" * S * ?Operator * S * >+Digit:
- curSection.Quality = OpAndInt(operator: parseEnum[OperatorEnum]($1), value: parseInt($2))
- GemLevel <- "GemLevel" * S * ?Operator * S * >+Digit:
- curSection.GemLevel = OpAndInt(operator: parseEnum[OperatorEnum]($1), value: parseInt($2))
- StackSize <- "StackSize" * S * ?Operator * S * >+Digit:
- curSection.StackSize = OpAndInt(operator: parseEnum[OperatorEnum]($1), value: parseInt($2))
- Sockets <- "Sockets" * S * ?Operator * S * >+Digit:
- curSection.Sockets = OpAndInt(operator: parseEnum[OperatorEnum]($1), value: parseInt($2))
- LinkedSockets <- "LinkedSockets" * S * ?Operator * S * >+Digit:
- curSection.LinkedSockets = OpAndInt(operator: parseEnum[OperatorEnum]($1), value: parseInt($2))
- PlayAlertSound <- "PlayAlertSound" * (S * >+Digit)[2]:
- curSection.PlayAlertSound = Sound(id: parseInt($1), volume: parseInt($2))
- PlayAlertSoundPositional <- "PlayAlertSoundPositional" * (S * >+Digit)[2]:
- curSection.PlayAlertSoundPositional = Sound(id: parseInt($1), volume: parseInt($2))
- SetTextColor <- "SetTextColor" * (S * >+Digit)[3..4]:
- #TODO: capture.len
- curSection.SetTextColor = Color(r: parseInt($1), g: parseInt($2), b: parseInt($3), a: parseInt($4))
- SetBorderColor <- "SetBorderColor" * (S * >+Digit)[3..4]:
- curSection.SetBorderColor = Color(r: parseInt($1), g: parseInt($2), b: parseInt($3), a: parseInt($4))
- SetBackgroundColor <- "SetBackgroundColor" * (S * >+Digit)[3..4]:
- curSection.SetBackgroundColor = Color(r: parseInt($1), g: parseInt($2), b: parseInt($3), a: parseInt($4))
- Corrupted <- "Corrupted" * S * >("True" | "False"):
- if $1 == "True": curSection.Corrupted = true else: curSection.Corrupted = false
- Identified <- "Identified" * S * >("True" | "False"):
- if $1 == "True": curSection.Identified = true else: curSection.Identified = false
- ShaperItem <- "ShaperItem" * S * >("True" | "False"):
- if $1 == "True": curSection.ShaperItem = true else: curSection.ShaperItem = false
- ElderItem <- "ElderItem" * S * >("True" | "False"):
- if $1 == "True": curSection.ElderItem = true else: curSection.ElderItem = false
- ElderMap <- "ElderMap" * S * >("True" | "False"):
- if $1 == "True": curSection.ElderMap = true else: curSection.ElderMap = false
- ShapedMap <- "ShapedMap" * S * >("True" | "False"):
- if $1 == "True": curSection.ShapedMap = true else: curSection.ShapedMap = false
- FracturedItem <- "FracturedItem" * S * >("True" | "False"):
- if $1 == "True": curSection.FracturedItem = true else: curSection.FracturedItem = false
- SynthesisedItem <- "SynthesisedItem" * S * >("True" | "False"):
- if $1 == "True": curSection.SynthesisedItem = true else: curSection.SynthesisedItem = false
- AnyEnchantment <- "AnyEnchantment" * S * >("True" | "False"):
- if $1 == "True": curSection.AnyEnchantment = true else: curSection.AnyEnchantment = false
- DisableDropSound <- "DisableDropSound" * S * >("True" | "False"):
- if $1 == "True": curSection.DisableDropSound = true else: curSection.DisableDropSound = false
- BlightedMap <- "BlightedMap" * S * >("True" | "False"):
- if $1 == "True": curSection.BlightedMap = true else: curSection.BlightedMap = false
- Rarity <- "Rarity" * S * ?Operator * S * >("Rare" | "Magic" | "Normal" | "Unique"):
- curSection.Rarity = OpAndRarity(operator: parseEnum[OperatorEnum]($1), rarity: parseEnum[RarityEnum]($2))
- PlayEffect <- "PlayEffect" * S * >("Red" | "Green" | "Blue" | "Brown" | "White" | "Yellow") * S * >("True" | "False"):
- var t = false
- if $2 == "True": t = true else: t = false
- curSection.PlayEffect = Effect(id: parseEnum[ColorEnum]($1), temporary: t)
- MinimapIcon <- "MinimapIcon" * S * >("Red" | "Green" | "Blue" | "Brown" | "White" | "Yellow") * S * >("Circle" | "Diamond" | "Hexagon" | "Square" | "Star" | "Triangle"):
- curSection.MinimapIcon = Icon(size: parseInt($1), color: parseEnum[ColorEnum]($2), shape: parseEnum[ShapeEnum]($3))
- Operator <- ">=" | ">" | "<=" | "<" | "=="
- NL <- {'\n','\r'}
- S <- *(Space | "#" * *(1 - NL) * ?NL)
- #end of grammar
- echo p.matchFile("C:/Users/krab/Documents/My Games/Path of Exile/2.txt").ok
- proc `$`(c: Color): string =
- "(" & $c.r & ", " & $c.g & ", " & $c.b & ", " & $c.a & ")"
- for section in sectionsSeq:
- echo section.Visible
- echo section.BaseType
- if section.SetTextColor != nil: echo section.SetTextColor
- if section.SetBorderColor != nil: echo section.SetBorderColor
- echo ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement