Skip to content

Commit

Permalink
Fix missing literal token in some cases (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvso authored Sep 19, 2023
1 parent e5a3f5b commit d98342a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 9 additions & 14 deletions nfp.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,6 @@ func (ps *Parser) getTokens() Tokens {
ps.Tokens.add(ps.Token.TValue, ps.Token.TType, ps.Token.Parts)
ps.Token = Token{}
}
if ps.Token.TValue != "" && !strings.ContainsAny(NumCodeChars, ps.Token.TValue) {
ps.Tokens.add(ps.Token.TValue, TokenTypeLiteral, ps.Token.Parts)
ps.Token = Token{}
}
ps.Token.TType = TokenTypeZeroPlaceHolder
if ps.currentChar() != Zero {
ps.Token.TType = TokenTypeLiteral
Expand Down Expand Up @@ -516,13 +512,6 @@ func (ps *Parser) getTokens() Tokens {
}

if ps.currentChar() == Whitespace {
if inStrSlice(AmPm, ps.Token.TValue, false) != -1 {
ps.Token.TType = TokenTypeDateTimes
ps.Tokens.add(ps.Token.TValue, ps.Token.TType, ps.Token.Parts)
ps.Token = Token{}
ps.Offset++
continue
}
if ps.Token.TType != "" && ps.Token.TType != TokenTypeLiteral {
ps.Tokens.add(ps.Token.TValue, ps.Token.TType, ps.Token.Parts)
}
Expand Down Expand Up @@ -587,9 +576,6 @@ func (ps *Parser) getTokens() Tokens {
}

if ps.currentChar() == BracketOpen {
if ps.Token.TType == "" && ps.Token.TValue != "" {
ps.Token.TType = TokenTypeLiteral
}
if ps.Token.TType != "" && !ps.InBracket {
ps.Tokens.add(ps.Token.TValue, ps.Token.TType, ps.Token.Parts)
ps.Token = Token{}
Expand Down Expand Up @@ -707,9 +693,18 @@ func (ps *Parser) getTokens() Tokens {
if !strings.ContainsAny(NumCodeChars, ps.currentChar()) && ps.Token.TType == TokenTypeZeroPlaceHolder {
ps.Tokens.add(ps.Token.TValue, ps.Token.TType, ps.Token.Parts)
ps.Token = Token{}
continue
}
ps.Token.TType = TokenTypeLiteral
}
ps.Token.TValue += ps.currentChar()
if inStrSlice(AmPm, ps.Token.TValue, false) != -1 {
ps.Token.TType = TokenTypeDateTimes
ps.Tokens.add(ps.Token.TValue, ps.Token.TType, ps.Token.Parts)
ps.Token = Token{}
ps.Offset++
continue
}
ps.Offset++
}

Expand Down
4 changes: 2 additions & 2 deletions nfp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var testStrings [][]string = [][]string{
{`abcdefghijklmnopqrstuvwxyz`, "[{Positive [{a DateTimes []} {bc Literal []} {d DateTimes []} {e DateTimes []} {f Literal []} {g DateTimes []} {h DateTimes []} {ijkl Literal []} {m DateTimes []} {nopqr Literal []} {s DateTimes []} {tuvwx Literal []} {y DateTimes []} {z Literal []}]}]"},
{`oeopwierop`, "[{Positive [{o Literal []} {e DateTimes []} {opwi Literal []} {e DateTimes []} {rop Literal []}]}]"},
{`[DBNum1][$US-111]yyyy"年"m"月"d"日";@`, "[{Positive [{[DBNum1] SwitchArgument []} {[$US-111] CurrencyLanguage [{{US CurrencyString []} } {{111 LanguageInfo []} }]} {yyyy DateTimes []} {年 Literal []} {m DateTimes []} {月 Literal []} {d DateTimes []} {日 Literal []}]} {Text [{@ TextPlaceHolder []}]}]"},
{`上午/下午 hh"時"mm"分"ss"秒"`, "[{Positive [{上午/下午 DateTimes []} {hh DateTimes []} {時 Literal []} {mm DateTimes []} {分 Literal []} {ss DateTimes []} {秒 Literal []}]}]"},
{`上午/下午 hh"時"mm"分"ss"秒"`, "[{Positive [{上午/下午 DateTimes []} { Literal []} {hh DateTimes []} {時 Literal []} {mm DateTimes []} {分 Literal []} {ss DateTimes []} {秒 Literal []}]}]"},
{`am/pm hh"時"mm"分"ss"秒"`, "[{Positive [{am/pm DateTimes []} { Literal []} {hh DateTimes []} {時 Literal []} {mm DateTimes []} {分 Literal []} {ss DateTimes []} {秒 Literal []}]}]"},
{`[$-404]e/m/d`, "[{Positive [{[$-404] CurrencyLanguage [{{404 LanguageInfo []} }]} {e DateTimes []} {/ Literal []} {m DateTimes []} {/ Literal []} {d DateTimes []}]}]"},
{`[$$-409]0#,##0`, "[{Positive [{[$$-409] CurrencyLanguage [{{$ CurrencyString []} } {{409 LanguageInfo []} }]} {0 ZeroPlaceHolder []} {# HashPlaceHolder []} {, ThousandsSeparator []} {## HashPlaceHolder []} {0 ZeroPlaceHolder []}]}]"},
Expand Down Expand Up @@ -105,7 +105,7 @@ var testStrings [][]string = [][]string{
{"\"£\"#,##0;[Red]\\-\"£\"#,##0", "[{Positive [{£ Literal []} {# HashPlaceHolder []} {, ThousandsSeparator []} {## HashPlaceHolder []} {0 ZeroPlaceHolder []}]} {Negative [{Red Color []} {- Literal []} {£ Literal []} {# HashPlaceHolder []} {, ThousandsSeparator []} {## HashPlaceHolder []} {0 ZeroPlaceHolder []}]}]"},
{"\"\"#,##0.00", "[{Positive [{€ Literal []} {# HashPlaceHolder []} {, ThousandsSeparator []} {## HashPlaceHolder []} {0 ZeroPlaceHolder []} {. DecimalPoint []} {00 ZeroPlaceHolder []}]}]"},
{"\"\"\\ #,##0.00_-", "[{Positive [{€ Literal []} { Literal []} {# HashPlaceHolder []} {, ThousandsSeparator []} {## HashPlaceHolder []} {0 ZeroPlaceHolder []} {. DecimalPoint []} {00 ZeroPlaceHolder []}]}]"},
{"\"上午/下午 \"hh\"\"mm\"\"ss\"\"", "[{Positive [{上午/下午 Literal []} {hh DateTimes []} {時 Literal []} {mm DateTimes []} {分 Literal []} {ss DateTimes []} {秒 Literal []}]}]"},
{"\"上午/下午 \"hh\"\"mm\"\"ss\"\"", "[{Positive [{上午/下午 DateTimes []} { Literal []} {hh DateTimes []} {時 Literal []} {mm DateTimes []} {分 Literal []} {ss DateTimes []} {秒 Literal []}]}]"},
{"\"\"#,##0.00;\"\"\\-#,##0.00", "[{Positive [{¥ Literal []} {# HashPlaceHolder []} {, ThousandsSeparator []} {## HashPlaceHolder []} {0 ZeroPlaceHolder []} {. DecimalPoint []} {00 ZeroPlaceHolder []}]} {Negative [{¥ Literal []} {- Literal []} {# HashPlaceHolder []} {, ThousandsSeparator []} {## HashPlaceHolder []} {0 ZeroPlaceHolder []} {. DecimalPoint []} {00 ZeroPlaceHolder []}]}]"},
{"#", "[{Positive [{# HashPlaceHolder []}]}]"},
{"# ?/?", "[{Positive [{# HashPlaceHolder []} { Literal []} {? DigitalPlaceHolder []} {/ Fraction []} {? DigitalPlaceHolder []}]}]"},
Expand Down

0 comments on commit d98342a

Please sign in to comment.