Skip to content

Commit a4b1ff5

Browse files
committed
docs: some improvements to the documentation
1 parent 0f7a232 commit a4b1ff5

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

go/compiler.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ type CompileError struct {
130130
type Label struct {
131131
// Label's level (e.g: "error", "warning", "info", "note", "help").
132132
Level string
133+
// Origin of the code where the error occurred.
133134
CodeOrigin string
134-
// The code span covered by the label.
135+
// The code span highlighted by this label.
135136
Span Span
136137
// Text associated to the label.
137138
Text string
@@ -204,7 +205,21 @@ func (c *Compiler) initialize() error {
204205

205206
// AddSource adds some YARA source code to be compiled.
206207
//
207-
// This function can be called multiple times.
208+
// This method may be invoked multiple times to add several sets of
209+
// YARA rules. If the rules provided in src contain errors that prevent
210+
// compilation, the first error encountered will be returned. Additionally,
211+
// the compiler will store this error, along with any others discovered
212+
// during compilation, which can be accessed using [Compiler.Errors].
213+
//
214+
// Even if a previous invocation resulted in a compilation error, you can
215+
// continue calling this method for adding more rules. In such cases, any
216+
// rules that failed to compile will not be included in the final compiled
217+
// [Rules].
218+
//
219+
// When adding rules to the compiler you can also provide a string containing
220+
// information about the origin of the rules using the [WithOrigin] option.
221+
// The origin is usually the path of the file containing the rules, but it can
222+
// be any string that conveys information about the origin of the rules.
208223
//
209224
// Examples:
210225
//
@@ -361,7 +376,7 @@ func (c *Compiler) Errors() []CompileError {
361376
// Build creates a [Rules] object containing a compiled version of all the
362377
// YARA rules previously added to the compiler.
363378
//
364-
// Once this function is called the compiler is reset to its initial state
379+
// Once this method is called the compiler is reset to its initial state
365380
// (i.e: the state it had after NewCompiler returned).
366381
func (c *Compiler) Build() *Rules {
367382
r := &Rules{cRules: C.yrx_compiler_build(c.cCompiler)}

go/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ func Deserialize(data []byte) (*Rules, error) {
6969
type Rules struct{ cRules *C.YRX_RULES }
7070

7171
// Scan some data with the compiled rules.
72-
//
73-
// Returns a slice with the rules that matched.
7472
func (r *Rules) Scan(data []byte) (*ScanResults, error) {
7573
scanner := NewScanner(r)
7674
return scanner.Scan(data)

go/scanner.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Scanner struct {
4646
}
4747

4848

49-
// ScanResults contains the results of a Scanner.Scan.
49+
// ScanResults contains the results of a call to [Scanner.Scan] or [Rules.Scan].
5050
type ScanResults struct{
5151
matchingRules []*Rule
5252
}
@@ -106,7 +106,7 @@ var ErrTimeout = errors.New("timeout")
106106
// value.
107107
//
108108
// The variable will retain the new value in subsequent scans, unless this
109-
// function is called again for setting a new value.
109+
// method is called again for setting a new value.
110110
func (s *Scanner) SetGlobal(ident string, value interface{}) error {
111111
cIdent := C.CString(ident)
112112
defer C.free(unsafe.Pointer(cIdent))
@@ -161,13 +161,13 @@ func (s *Scanner) SetGlobal(ident string, value interface{}) error {
161161
// Case 1) applies to certain modules lacking a main function, thus incapable of
162162
// producing any output on their own. For such modules, you must set the output
163163
// before scanning the associated data. Since the module's output typically varies
164-
// with each scanned file, you need to call this function prior to each invocation
164+
// with each scanned file, you need to call this method prior to each invocation
165165
// of [Scanner.Scan]. Once [Scanner.Scan] is executed, the module's output is
166166
// consumed and will be empty unless set again before the subsequent call.
167167
//
168168
// Case 2) applies when you have previously stored the module's output for certain
169169
// scanned data. In such cases, when rescanning the data, you can utilize this
170-
// function to supply the module's output, thereby preventing redundant computation
170+
// method to supply the module's output, thereby preventing redundant computation
171171
// by the module. This optimization enhances performance by eliminating the need
172172
// for the module to reparse the scanned data.
173173
//

lib/src/compiler/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl<'a> Compiler<'a> {
448448
}
449449
}
450450

451-
/// Adds YARA rules in source form for compilation.
451+
/// Adds some YARA source code to be compiled.
452452
///
453453
/// The `src` parameter accepts any type that implements [`Into<SourceCode>`],
454454
/// such as `&str`, `&[u8]`, and naturally, [`SourceCode`] itself. This input
@@ -462,8 +462,9 @@ impl<'a> Compiler<'a> {
462462
/// [`Compiler::errors`].
463463
///
464464
/// Even if a previous invocation resulted in a compilation error, you can
465-
/// continue calling this function. In such cases, any rules that failed to
466-
/// compile will not be included in the final compiled set.
465+
/// continue calling this function for adding more rules. In such cases, any
466+
/// rules that failed to compile will not be included in the final compiled
467+
/// set.
467468
pub fn add_source<'src, S>(
468469
&mut self,
469470
src: S,

0 commit comments

Comments
 (0)