nfp
packagemoduleThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
README¶
NFP (Number Format Parser)
Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression.
Installation
go get github.com/xuri/nfp
Example
package mainimport "github.com/xuri/nfp"func main() { ps := nfp.NumberFormatParser() tokens := ps.Parse("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)") println(p.PrettyPrint())}
Get AST
<Positive> <RepeatsChar> # <HashPlaceHolder> <ThousandsSeparator> ## <HashPlaceHolder> 0 <ZeroPlaceHolder> . <DecimalPoint> 00 <ZeroPlaceHolder><Negative> <RepeatsChar> ( <Literal> # <HashPlaceHolder> , <ThousandsSeparator> ## <HashPlaceHolder> 0 <ZeroPlaceHolder> . <DecimalPoint> 00 <ZeroPlaceHolder> ) <Literal><Zero> <RepeatsChar> - <Literal> ?? <DigitalPlaceHolder><Text> @ <TextPlaceHolder>
Contributing
Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.
Licenses
This program is under the terms of the BSD 3-Clause License. Seehttps://opensource.org/licenses/BSD-3-Clause.
Documentation¶
Index¶
Constants¶
const (// Character constantsAsterisk = "*"At = "@"BackSlash = "\\"BlockDelimiter = ";"BracketClose = "]"BracketOpen = "["Colon = ":"Comma = ","Dash = "-"Dollar = "$"Dot = "."Hash = "#"ParenClose = ")"ParenOpen = "("Percent = "%"Plus = "+"Question = "?"QuoteDouble = "\""QuoteSingle = "'"Slash = "/"Underscore = "_"Whitespace = " "Zero = "0"// DatesTimesCodeChars defined dates and times control codes in upper caseDatesTimesCodeChars = "AEYMDHSG"// NumCodeChars defined numeric code characterNumCodeChars = "0123456789"// Token section typesTokenSectionNegative = "Negative"TokenSectionPositive = "Positive"TokenSectionText = "Text"TokenSectionZero = "Zero"// Token subtypesTokenSubTypeCurrencyString = "CurrencyString"TokenSubTypeLanguageInfo = "LanguageInfo"TokenTypeColor = "Color"// Token typesTokenTypeAlignment = "Alignment"TokenTypeCondition = "Condition"TokenTypeCurrencyLanguage = "CurrencyLanguage"TokenTypeDateTimes = "DateTimes"TokenTypeDecimalPoint = "DecimalPoint"TokenTypeDenominator = "Denominator"TokenTypeDigitalPlaceHolder = "DigitalPlaceHolder"TokenTypeElapsedDateTimes = "ElapsedDateTimes"TokenTypeExponential = "Exponential"TokenTypeFraction = "Fraction"TokenTypeGeneral = "General"TokenTypeHashPlaceHolder = "HashPlaceHolder"TokenTypeLiteral = "Literal"TokenTypeOperand = "Operand"TokenTypeOperator = "Operator"TokenTypePercent = "Percent"TokenTypeRepeatsChar = "RepeatsChar"TokenTypeSwitchArgument = "SwitchArgument"TokenTypeTextPlaceHolder = "TextPlaceHolder"TokenTypeThousandsSeparator = "ThousandsSeparator"TokenTypeUnknown = "Unknown"TokenTypeZeroPlaceHolder = "ZeroPlaceHolder")
Asterisk, At and other's constants are token definitions.
Variables¶
var AmPm = []string{"AM/PM", "A/P", "上午/下午"}
AmPm defined the AM and PM with international considerations.
var ColorNames = []string{"black","blue","cyan","green","magenta","red","white","yellow",}
ColorNames defined colors name used in for a section of the format, use thename of one of the following eight colors in square brackets in thesection. The color code shall be the first item in the section.
var ConditionOperators = []string{"<", "<=", ">", ">=", "<>", "="}
ConditionOperators defined the condition operators.
var GeneralFormattingSwitchArguments = []string{"AIUEO","ALPHABETIC","alphabetic","Arabic","ARABICABJAD","ARABICALPHA","ArabicDash","BAHTTEXT","CardText","CHINESENUM1","CHINESENUM2","CHINESENUM3","CHOSUNG","CIRCLENUM","DBCHAR","DBNUM1","DBNUM2","DBNUM3","DBNUM4","DollarText","GANADA","GB1","GB2","GB3","GB4","HEBREW1","HEBREW2","Hex","HINDIARABIC","HINDICARDTEXT","HINDILETTER1","HINDILETTER2","IROHA","KANJINUM1","KANJINUM2","KANJINUM3","Ordinal","OrdText","Roman","roman","SBCHAR","THAIARABIC","THAICARDTEXT","THAILETTER","VIETCARDTEXT","ZODIAC1","ZODIAC2","ZODIAC3",}
GeneralFormattingSwitchArguments defined switch-arguments apply to fieldswhose field result is a numeric value. If the result type of the field isnot numeric, then these switches have no effect.
Functions¶
This section is empty.
Types¶
typeParser¶
type Parser struct {InBracketboolInStringboolInPlaceholderboolNumFmtstring// Runes is a copy of the number format string as a rune slice. It's stored here to avoid// allocating a new slice every time we need to access it.Runes []runeOffsetintTokensTokensTokenToken}
Parser inheritable container.
funcNumberFormatParser¶
func NumberFormatParser()Parser
NumberFormatParser provides function to parse an Excel number format into astream of tokens.
func (*Parser)PrettyPrint¶
PrettyPrint provides function to pretty the parsed result with the indentedformat.
typeSection¶
Section directly maps sections of the number format. Up to four sections offormat codes can be specified. The format codes, separated by semicolons,define the formats for positive numbers, negative numbers, zero values, andtext, in that order. If only two sections are specified, the first is usedfor positive numbers and zeros, and the second is used for negativenumbers. If only one section is specified, it is used for all numbers. Toskip a section, the ending semicolon for that section shall be written.