parser

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package parser implements an error-tolerant, declaration-grade recursive-descent parser for SystemVerilog, producing an svparse/ast tree from a token stream. Error-tolerant means what it does throughout svparse: a malformed declaration is recorded and skipped (see recover.go), never fatal -- a language server has to make sense of source that's broken mid-edit far more often than a batch tool does.

Declaration-grade means ports, nets/variables, parameters, typedef/ struct/enum, function/task signatures, class members, package imports, containers, and instantiations are parsed for real; procedural block bodies (inside always, function/task bodies, constraint blocks) are recognized and skipped via balanced-token matching, never parsed -- expression and statement grammar is entirely out of scope. See each unparsed field's doc comment in package ast for exactly what's kept as a raw token span instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	File      string
	Line      int
	Character int
	Message   string
}

Error is a non-fatal problem noticed while parsing. Parse never stops or panics because of one.

func Parse

func Parse(path string, toks []preprocessor.Token) (*ast.File, []Error)

Parse parses toks. preprocessor.Token is the canonical input -- not token.Token -- so AST node positions can carry real file attribution (an included declaration's true file) without the parser needing to know anything about how the tokens got there.

toks need not end with a token.KindEOF sentinel: lexer.Lex's own output always does, but preprocessor.Preprocess's does not (its EOF sentinels are internal boundary markers between pushed sources -- files, macro expansions, includes -- stripped from the merged output by design, not a producer bug). peekAt synthesizes an EOF token past the end of whatever toks it's given rather than trusting an invariant that only sometimes holds -- past a genuine end of input should always look the same to the parser regardless of which producer built toks.

func ParseTokens

func ParseTokens(path string, toks []token.Token) (*ast.File, []Error)

ParseTokens is a convenience entry point for callers that skip preprocessing entirely: it wraps each token with File set and no macro attribution, then delegates to Parse.

Jump to

Keyboard shortcuts

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