Skip to content

Commit 6802ed9

Browse files
authored
Fixing most of the comment errors. (#152)
1 parent 56c3ec6 commit 6802ed9

24 files changed

+77
-63
lines changed

customfuncs/customFuncs.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/jf-tech/omniparser/transformctx"
99
)
1010

11-
// CustomFuncType is the type of a custom function. Has to use interface{} given we support
11+
// CustomFuncType is the type of custom function. Has to use interface{} given we support
1212
// non-variadic and variadic functions.
1313
type CustomFuncType = interface{}
1414

@@ -43,7 +43,7 @@ var CommonCustomFuncs = map[string]CustomFuncType{
4343
}
4444

4545
// Coalesce returns the first non-empty string of the input strings. If no input strings are given or
46-
// all of them are empty, then empty string is returned. Note: a blank string (with only whitespaces)
46+
// all of them are empty, then an empty string is returned. Note: a blank string (with only whitespaces)
4747
// is not considered as empty.
4848
func Coalesce(_ *transformctx.Ctx, strs ...string) (string, error) {
4949
for _, str := range strs {
@@ -54,7 +54,7 @@ func Coalesce(_ *transformctx.Ctx, strs ...string) (string, error) {
5454
return "", nil
5555
}
5656

57-
// Concat custom_func concatenates a number of strings together. If no strings specified, "" is returned.
57+
// Concat concatenates a number of strings together. If no strings specified, "" is returned.
5858
func Concat(_ *transformctx.Ctx, strs ...string) (string, error) {
5959
var w strings.Builder
6060
for _, s := range strs {

customfuncs/datetime.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const (
2323
// If layout is specific, then parseDateTime will parse datetime string using the supplied layout;
2424
// otherwise, it will default to times.SmartParse.
2525
//
26-
// If datetime string contains tz info in it (such as 'Z', or '-America/New_York' etc, or '-0700', etc)
26+
// If datetime string contains tz info in it (such as 'Z', or '-America/New_York' etc., or '-0700', etc.)
2727
// then fromTZ is IGNORED. Otherwise, then datetime string will be parsed in with its face value y/m/d/h/m/s
2828
// and bonded with the fromTZ, if fromTZ isn't "".
2929
//

extensions/omniv21/customfuncs/javascript.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const (
1515
argNameNode = "_node"
1616
)
1717

18-
// JSProgramCache caches *goja.Program. A *goja.Program is compiled javascript and it can be used
18+
// JSProgramCache caches *goja.Program. A *goja.Program is compiled javascript, and it can be used
1919
// across multiple goroutines and across different *goja.Runtime. If default loading cache capacity
2020
// is not desirable, change JSProgramCache to a loading cache with a different capacity at package
2121
// init time. Be mindful this will be shared across all use cases inside your process.
@@ -29,7 +29,7 @@ var jsRuntimePool sync.Pool
2929
// NodeToJSONCache caches *idr.Node to JSON translations.
3030
var NodeToJSONCache *caches.LoadingCache
3131

32-
// For debugging/testing purpose so we can easily disable all the caches. But not exported. We always
32+
// For debugging/testing purpose, so we can easily disable all the caches. But not exported. We always
3333
// want caching in production.
3434
var disableCaching = false
3535

extensions/omniv21/fileformat/csv/reader.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ErrInvalidHeader string
2020

2121
func (e ErrInvalidHeader) Error() string { return string(e) }
2222

23-
// IsErrInvalidHeader checks if an err is of ErrInvalidHeader type.
23+
// IsErrInvalidHeader checks if the `err` is of ErrInvalidHeader type.
2424
func IsErrInvalidHeader(err error) bool {
2525
switch err.(type) {
2626
case ErrInvalidHeader:
@@ -114,7 +114,7 @@ func (r *reader) recordToNode(record []string) *idr.Node {
114114
root := idr.CreateNode(idr.DocumentNode, "")
115115
// - If actual record has more columns than declared in schema, we'll only use up to
116116
// what's declared in the schema;
117-
// - conversely, if the actual record has less columns than declared in schema, we'll
117+
// - conversely, if the actual record has fewer columns than declared in schema, we'll
118118
// use all that are in the record.
119119
for i := 0; i < maths.MinInt(len(record), len(r.decl.Columns)); i++ {
120120
col := idr.CreateNode(idr.ElementNode, r.decl.Columns[i].name())

extensions/omniv21/fileformat/edi/reader.go

-6
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,6 @@ func (r *ediReader) Read() (*idr.Node, error) {
231231
if err != nil {
232232
return nil, err
233233
}
234-
if len(r.stack) <= 1 {
235-
// we have a raw segment waiting for processing but currently
236-
// the decl stack is effectively empty (with only the artificial
237-
// #root decl on it. We can get into this situation two ways:
238-
// 1.
239-
}
240234
cur := r.stackTop()
241235
if !cur.segDecl.matchSegName(rawSeg.Name) {
242236
if len(r.stack) <= 1 {

extensions/omniv21/fileformat/edi/reader2.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type ErrInvalidEDI string
1616

1717
func (e ErrInvalidEDI) Error() string { return string(e) }
1818

19-
// IsErrInvalidEDI checks if an err is of ErrInvalidEDI type.
19+
// IsErrInvalidEDI checks if the `err` is of ErrInvalidEDI type.
2020
func IsErrInvalidEDI(err error) bool {
2121
switch err.(type) {
2222
case ErrInvalidEDI:
@@ -139,9 +139,9 @@ func (r *NonValidatingReader) Read() (RawSeg, error) {
139139
r.segCount++
140140
// We are here because:
141141
// 1. we find next token (i.e. segment), great, let's process it, OR
142-
// 2. r.scanner.Scan() returns false and it's EOF (note scanner never returns EOF, it just returns false
142+
// 2. r.scanner.Scan() returns false, and it's EOF (note scanner never returns EOF, it just returns false
143143
// on Scan() and Err() returns nil). We need to return EOF, OR
144-
// 3. r.scanner.Scan() returns false Err() returns err, need to return the err wrapped.
144+
// 3. r.scanner.Scan() returns false Err() returns err, need to return the `err` wrapped.
145145
err := r.scanner.Err()
146146
if err != nil {
147147
return RawSeg{}, ErrInvalidEDI(fmt.Sprintf("cannot read segment, err: %s", err.Error()))
@@ -167,7 +167,7 @@ func (r *NonValidatingReader) Read() (RawSeg, error) {
167167
r.rawSeg.Elems,
168168
RawSegElem{
169169
// while (element) index in schema starts with 1, it actually refers to the first element
170-
// AFTER the seg name element, thus we use can i as ElemIndex directly.
170+
// AFTER the seg name element, thus we can use i as ElemIndex directly.
171171
ElemIndex: i,
172172
// comp_index always starts with 1
173173
CompIndex: 1,

extensions/omniv21/fileformat/edi/seg.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (d *SegDecl) maxOccurs() int {
7777
// for majority cases, segments have min=1, max=1, so default nil to 1
7878
return 1
7979
case *d.Max < 0:
80-
// typically schema writer uses -1 to indicate infinite; practically max int is good enough :)
80+
// typically, schema writer uses -1 to indicate infinite; practically max int is good enough :)
8181
return maths.MaxIntValue
8282
default:
8383
return *d.Max
@@ -87,7 +87,7 @@ func (d *SegDecl) maxOccurs() int {
8787
func (d *SegDecl) matchSegName(segName string) bool {
8888
switch d.isGroup() {
8989
case true:
90-
// Group (or so called loop) itself doesn't have a segment name in EDI file (we do assign a
90+
// Group (or so-called loop) itself doesn't have a segment name in EDI file (we do assign a
9191
// name to it for xpath query reference, but that name isn't a segment name per se). A
9292
// group/loop's first non-group child, recursively if necessary, can be used as the group's
9393
// identifying segment name, per EDI standard. Meaning if a group's first non-group child's

extensions/omniv21/fileformat/fileformat.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type FormatReader interface {
3535
// For certain errors (like EOF or corruption) there is no point to keep on trying; while others
3636
// can be safely ignored.
3737
IsContinuableError(err error) bool
38-
// FormatReader must be able to format an error by providing context information (such as input
38+
// CtxAwareErr allows FormatReader to format an error by providing context information (such as input
3939
// file name and (approx.) error location, such as line number)
4040
errs.CtxAwareErr
4141
}

extensions/omniv21/fileformat/fixedlength/reader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (r *reader) readByHeaderFooterEnvelope() (*idr.Node, error) {
9898
return nil, ErrInvalidEnvelope(r.fmtErrStr("incomplete envelope: %s", err.Error()))
9999
}
100100
for ; r.envelopeIndex < len(r.decl.Envelopes); r.envelopeIndex++ {
101-
// regex's are already validated
101+
// regex is already validated
102102
headerRegex, _ := caches.GetRegex(r.decl.Envelopes[r.envelopeIndex].ByHeaderFooter.Header)
103103
if headerRegex.Match(line) {
104104
break

extensions/omniv21/fileformat/json/reader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type ErrNodeReadingFailed string
1414

1515
func (e ErrNodeReadingFailed) Error() string { return string(e) }
1616

17-
// IsErrNodeReadingFailed checks if an err is of ErrNodeReadingFailed type.
17+
// IsErrNodeReadingFailed checks if the `err` is of ErrNodeReadingFailed type.
1818
func IsErrNodeReadingFailed(err error) bool {
1919
switch err.(type) {
2020
case ErrNodeReadingFailed:

extensions/omniv21/fileformat/xml/reader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type ErrNodeReadingFailed string
1414

1515
func (e ErrNodeReadingFailed) Error() string { return string(e) }
1616

17-
// IsErrNodeReadingFailed checks if an err is of ErrNodeReadingFailed type.
17+
// IsErrNodeReadingFailed checks if the `err` is of ErrNodeReadingFailed type.
1818
func IsErrNodeReadingFailed(err error) bool {
1919
switch err.(type) {
2020
case ErrNodeReadingFailed:

extensions/omniv21/transform/decl.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ type Decl struct {
9191
Object map[string]*Decl `json:"object,omitempty"`
9292
// Array specifies the input element is an array.
9393
Array []*Decl `json:"array,omitempty"`
94-
// ResultType specifies the desired output type of an element.
94+
// ResultType specifies the desired output type of element.
9595
ResultType *resultType `json:"type,omitempty"`
9696
// NoTrim specifies space trimming in string value of the output element.
9797
NoTrim bool `json:"no_trim,omitempty"`
98-
// KeepEmptyOrNull specifies whether or not keep an empty/null output or not.
98+
// KeepEmptyOrNull specifies whether to keep an empty/null output or not.
9999
KeepEmptyOrNull bool `json:"keep_empty_or_null,omitempty"`
100100

101101
// Internal fields are computed at schema loading time.

extensions/omniv21/transform/parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type parseCtx struct {
1616
transformCtx *transformctx.Ctx
1717
customFuncs customfuncs.CustomFuncs
1818
customParseFuncs CustomParseFuncs // Deprecated.
19-
disableTransformCache bool // by default we have caching on. only in some tests we turn caching off.
19+
disableTransformCache bool // by default, we have caching on. only in some tests we turn caching off.
2020
transformCache map[string]interface{}
2121
}
2222

extensions/omniv21/transform/validate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (ctx *validateCtx) validateXPath(fqdn string, decl *Decl, templateRefStack
8888
return fmt.Errorf("'%s' cannot set both 'xpath' and 'xpath_dynamic' at the same time", fqdn)
8989
}
9090
// unlike `xpath` which is a constant string, `xpath_dynamic` value comes from the computation of
91-
// regular decl and it can be of a const/field/custom_func/template/external, so we need to parse
91+
// regular decl, and it can be of a const/field/custom_func/template/external, so we need to parse
9292
// and validate the decl as well.
9393
if decl.XPathDynamic != nil {
9494
var err error

header/header.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
// ParserSettings defines the common header (and its JSON format) for all schemas across all schema handlers.
1111
// It contains vital information about which handler a schema wants to use, and what file format the input
12-
// stream is of (e.g. fixed-length txt, CSV/TSV, XML, JSON, EDI, etc). Also optionally, it specifies the
13-
// expected the encoding scheme for the input streams this schema is used for.
12+
// stream is of (e.g. fixed-length txt, CSV/TSV, XML, JSON, EDI, etc). Optionally, it specifies the expected
13+
// encoding scheme for the input streams this schema is used for.
1414
type ParserSettings struct {
1515
Version string `json:"version,omitempty"`
1616
FileFormatType string `json:"file_format_type,omitempty"`

idr/jsonnode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
)
66

7-
// JSONType is the type of a JSON-specific Node.
7+
// JSONType is the type of JSON-specific Node.
88
// Note multiple JSONType can be bit-wise OR'ed together.
99
type JSONType uint
1010

idr/jsonreader.go

+23-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ type JSONStreamReader struct {
2121
}
2222

2323
// streamCandidateCheck checks if sp.cur is a potential stream candidate.
24+
// Note even if sp.cur is marked, it only means it could potentially be the
25+
// stream candidate, not guaranteed. E.g., say have a JSON doc looks like this:
26+
// {
27+
// "x": {
28+
// "a": 5
29+
// },
30+
// "y": {
31+
// "a": 2
32+
// }
33+
// }
34+
// And our stream xpath is "/*/a[. < 4]".
35+
// When the reader first encounters "x/a" node, it has the potential to be the
36+
// stream candidate since it matches "/*/a". But we haven't finished processing
37+
// the entire node, thus no way we know if the value of "a" would match the filter
38+
// or not. So we have to mark it as a potential stream candidate and will let
39+
// wrapUpCurAndTargetCheck to do the final check when the entire node of "/x/a"
40+
// is ingested and processed, in which case, "/x/a" will be not be considered
41+
// as stream target, but later "/x/b" will be.
2442
func (sp *JSONStreamReader) streamCandidateCheck() {
2543
if sp.xpathExpr != nil && sp.stream == nil && MatchAny(sp.root, sp.xpathExpr) {
2644
sp.stream = sp.cur
@@ -33,7 +51,7 @@ func (sp *JSONStreamReader) streamCandidateCheck() {
3351
// - Either we don't have a stream filter xpath or the stream filter xpath matches.
3452
func (sp *JSONStreamReader) wrapUpCurAndTargetCheck() *Node {
3553
cur := sp.cur
36-
// No matter what outcome the wrapUpCurAndTargetCheck() is, the current node is done and
54+
// No matter what outcome the wrapUpCurAndTargetCheck() is, the current node is done, and
3755
// we need to adjust sp.cur to its parent.
3856
sp.cur = sp.cur.Parent
3957
// Only do stream target check if the finished cur node is the stream candidate
@@ -78,7 +96,7 @@ func (sp *JSONStreamReader) addTextChild(tok interface{}) {
7896
}
7997
child := CreateJSONNode(TextNode, data, jtype)
8098
AddChild(sp.cur, child)
81-
// If the child being added is a value node, there won't be anything else
99+
// Since the child being added is a value node, there won't be anything else
82100
// added below it, so no need to advance sp.cur to child.
83101
}
84102

@@ -100,7 +118,7 @@ func (sp *JSONStreamReader) parseDelim(tok json.Delim) *Node {
100118
// already done the check when the property itself is processed.
101119
sp.cur.FormatSpecific = JSONTypeOf(sp.cur) | JSONObj
102120
case IsJSONRoot(sp.cur):
103-
// if we see "{" directly on root, make the root node a obj type container
121+
// if we see "{" directly on root, make the root node an obj type container
104122
// and do stream candidate check.
105123
sp.cur.FormatSpecific = JSONTypeOf(sp.cur) | JSONObj
106124
sp.streamCandidateCheck()
@@ -138,7 +156,7 @@ func (sp *JSONStreamReader) parseVal(tok json.Token) *Node {
138156
case IsJSONObj(sp.cur):
139157
sp.addElementChild(tok.(string), JSONProp)
140158
sp.streamCandidateCheck()
141-
// similarly we want arr check before prop check.
159+
// Similarly, we want arr check before prop check.
142160
case IsJSONArr(sp.cur):
143161
// if parent is an array or root, so we're adding a value directly to
144162
// the array or root, by creating an anonymous element node, then the
@@ -158,7 +176,7 @@ func (sp *JSONStreamReader) parseVal(tok json.Token) *Node {
158176
}
159177
case IsJSONRoot(sp.cur):
160178
// A value is directly setting on root. We need to do both stream candidate check
161-
// as well as target check.
179+
// and target check.
162180
sp.streamCandidateCheck()
163181
sp.addTextChild(tok)
164182
ret := sp.wrapUpCurAndTargetCheck()

idr/marshal2.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (ctx *ctx) isChildText(n *Node) bool {
2727
// <efg/>
2828
// </abc>
2929
// If isChildText is called upon node <abc>, it should ideally return false due to the sub
30-
// element node <efg> presence. However due to the way XML nodes are constructed, there will
30+
// element node <efg> presence. However, due to the way XML nodes are constructed, there will
3131
// be "dummy" text nodes hanging around:
3232
// ElementNode ("abc")
3333
// TextNode ("\n")
@@ -56,7 +56,7 @@ func (ctx *ctx) isChildText(n *Node) bool {
5656
// We've found text child node, but we need to continue probing.
5757
} else if n.Type == ElementNode {
5858
elemNodeFound = true
59-
// We've found an unwanted element child node, don't probing.
59+
// We've found an unwanted element child node, don't probe.
6060
break
6161
}
6262
// attribute child node is ignored.
@@ -75,12 +75,12 @@ func (ctx *ctx) isChildArray(n *Node) bool {
7575
// empty string.
7676
//
7777
// XML/EDI are a bit more complicated:
78-
// There is not concept of array in XML, neither in EDI. XML, however, can simulate
78+
// There is no concept of array in XML, neither in EDI. XML, however, can simulate
7979
// array by having a number of child elements with the same element name. EDI has
8080
// segment loop. So the primary idea is to check child element nodes' names and use
8181
// their similarity to determine whether the children represent an array or not.
8282
// Throwing a wrench here is that fact in XML, there are dummy text nodes sprinkled
83-
// around, in between XML elements, so we need to ignore them. Also there could be
83+
// around, in between XML elements, so we need to ignore them. There could also be
8484
// attribute nodes in XML, need to ignore them too.
8585
//
8686
// One ambiguous case in XML (and similarly in EDI):

idr/node.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import (
77
"sync/atomic"
88
)
99

10-
// NodeType is the type of a Node in an IDR.
10+
// NodeType is the type of Node in an IDR.
1111
type NodeType uint
1212

1313
const (
1414
// DocumentNode is the type of the root Node in an IDR tree.
1515
DocumentNode NodeType = iota
16-
// ElementNode is the type of an element Node in an IDR tree.
16+
// ElementNode is the type of element Node in an IDR tree.
1717
ElementNode
18-
// TextNode is the type of an text/data Node in an IDR tree.
18+
// TextNode is the type of text/data Node in an IDR tree.
1919
TextNode
20-
// AttributeNode is the type of an attribute Node in an IDR tree.
20+
// AttributeNode is the type of attribute Node in an IDR tree.
2121
AttributeNode
2222
)
2323

@@ -41,14 +41,14 @@ func (nt NodeType) String() string {
4141
// by the omniparser.
4242
// Credit: this is by and large a copy and some adaptation from
4343
// https://github.com/antchfx/xmlquery/blob/master/node.go. The reasons we want to have our own struct:
44-
// - more stability
4544
// - one struct to represent XML/JSON/EDI/CSV/txt/etc. Vs antchfx's work have one struct (in each repo)
4645
// for each format.
4746
// - Node allocation recycling.
47+
// - more stability
4848
type Node struct {
4949
// ID uniquely identifies a Node, whether it's newly created or recycled and reused from
5050
// the node allocation cache. Previously we sometimes used a *Node's pointer address as a
51-
// unique ID which isn't sufficiently unique anymore given the introduction of using
51+
// unique ID which isn't sufficiently unique any more given the introduction of using
5252
// sync.Pool for node allocation caching.
5353
ID int64
5454

idr/query.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var (
1818
const (
1919
// DisableXPathCache disables caching xpath compilation when MatchAll/MatchSingle
2020
// are called. Useful when caller knows the xpath string isn't cache-able (such as
21-
// containing unique IDs, timestamps, etc) which would otherwise cause the xpath
21+
// containing unique IDs, timestamps, etc.) which would otherwise cause the xpath
2222
// compilation cache grow unbounded.
2323
DisableXPathCache = uint(1) << iota
2424
)

idr/xmlreader.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type XMLStreamReader struct {
2222
}
2323

2424
// streamCandidateCheck checks if sp.cur is a potential stream candidate.
25+
// See more details/explanation in JSONStreamReader.streamCandidateCheck.
2526
func (sp *XMLStreamReader) streamCandidateCheck() {
2627
if sp.xpathExpr != nil && sp.stream == nil && MatchAny(sp.root, sp.xpathExpr) {
2728
sp.stream = sp.cur
@@ -34,7 +35,7 @@ func (sp *XMLStreamReader) streamCandidateCheck() {
3435
// - Either we don't have a stream filter xpath or the stream filter xpath matches.
3536
func (sp *XMLStreamReader) wrapUpCurAndTargetCheck() *Node {
3637
cur := sp.cur
37-
// No matter what outcome the wrapUpCurAndTargetCheck() is, the current node is done and
38+
// No matter what outcome the wrapUpCurAndTargetCheck() is, the current node is done, and
3839
// we need to adjust sp.cur to its parent.
3940
sp.cur = sp.cur.Parent
4041
// Only do stream target check if the finished cur node is the stream candidate

0 commit comments

Comments
 (0)