parsing

package
v0.0.0-...-c4af43d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Analyze

func Analyze(ctx context.Context, parserConfig ParserConfig, input externalcmd.Input, printDebug bool) (map[string]SingleResult, error)

Analyze (parsing.Analyze) parses the specified list of files using all supported parsers and returns a map of filename to slice of parsing.SingleResult. Each slice holds information about source code tokens found for that file for each supported langauge parser.

Currently, the only supported language is JavaScript, however more language parsers will be added in the future.

Input can be specified either by file path or by passing the source code string directly. To parse a file, specify its path using sourceFile; the value of sourceString is ignored. If sourceFile is empty, then sourceString is parsed directly as code.

If parsing is attempted in a given langauge and fails due to syntax errors, the value for that language in the returned map is nil, with no other error.

If an internal error occurs during parsing, parsing is interrupted and the error returned.

Note: In JavaScript, there is no distinction between integer and floating point literals; they are normally both parsed as floating point. This function records a numeric literal as an integer if it can be converted using strconv.Atoi(), otherwise it is recorded as floating point.

func RunExampleParsing

func RunExampleParsing(ctx context.Context, config ParserConfig, input externalcmd.Input)

Types

type ExtractedStrings

type ExtractedStrings struct {
	RawLiterals []string
	Strings     []string
}

func FindStringsInCode

func FindStringsInCode(source string, stringRegexp *regexp.Regexp) (*ExtractedStrings, error)

func FindStringsInFile

func FindStringsInFile(filePath string, stringRegexp *regexp.Regexp) (*ExtractedStrings, error)

type Language

type Language string

Language represents a programming language used for parsing.

const (
	NoLanguage Language = ""
	JavaScript Language = "JavaScript"
)

func SupportedLanguages

func SupportedLanguages() []Language

type ParserConfig

type ParserConfig struct {
	InstallDir string
	ParserPath string
}

func InitParser

func InitParser(ctx context.Context, installDir string) (ParserConfig, error)

type SingleResult

type SingleResult struct {
	Language       Language           `json:"language"`
	Identifiers    []token.Identifier `json:"identifiers"`
	StringLiterals []token.String     `json:"string_literals"`
	IntLiterals    []token.Int        `json:"int_literals"`
	FloatLiterals  []token.Float      `json:"float_literals"`
	Comments       []token.Comment    `json:"comments"`
}

SingleResult holds processed information about source code tokens found in a single file by a single language parser

func (SingleResult) String

func (r SingleResult) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL