package parser
import "github.com/purpleidea/mgmt/lang/parser"
Package parser contains the lexer and parser for the mcl language.
Index ¶
- Constants
- func DirectoryReader(fs engine.Fs, dir string) (io.Reader, map[uint64]string, error)
- func LexParse(input io.Reader) (interfaces.Stmt, error)
- func LexParseWithOffsets(input io.Reader, offsets map[uint64]string) (interfaces.Stmt, error)
- type LexParseErr
Constants ¶
const ( ErrLexerUnrecognized = util.Error("unrecognized") ErrLexerUnrecognizedCR = util.Error("unrecognized carriage return") ErrLexerStringBadEscaping = util.Error("string: bad escaping") ErrLexerIntegerOverflow = util.Error("integer: overflow") ErrLexerFloatOverflow = util.Error("float: overflow") ErrParseError = util.Error("parser") ErrParseSetType = util.Error("can't set return type in parser") ErrParseResFieldInvalid = util.Error("can't use unknown resource field") ErrParseAdditionalEquals = util.Error(errstrParseAdditionalEquals) ErrParseExpectingComma = util.Error(errstrParseExpectingComma) )
These constants represent the different possible lexer/parser errors.
Functions ¶
func DirectoryReader ¶
DirectoryReader takes a filesystem and an absolute directory path, and it returns a combined reader into that directory, and an offset map of the file contents. This is used to build a reader from a directory containing language source files, and as a result, this will skip over files that don't have the correct extension. The offsets are in units of file size (bytes) and not length (lines). TODO: Due to an implementation difficulty, offsets are currently in length! NOTE: This was used for an older deprecated form of lex/parse file combining.
func LexParse ¶
func LexParse(input io.Reader) (interfaces.Stmt, error)
LexParse runs the lexer/parser machinery and returns the AST.
func LexParseWithOffsets ¶
LexParseWithOffsets takes an io.Reader input and a list of corresponding offsets and runs LexParse on them. The input to this function is most commonly the output from DirectoryReader which returns a single io.Reader and the offsets map. It usually produces the combined io.Reader from an io.MultiReader grouper. If the offsets map is nil or empty, then it simply redirects directly to LexParse. This differs because when it errors it will also report the corresponding file the error occurred in based on some offset math. The offsets are in units of file size (bytes) and not length (lines). TODO: Due to an implementation difficulty, offsets are currently in length! NOTE: This was used for an older deprecated form of lex/parse file combining.
Types ¶
type LexParseErr ¶
type LexParseErr struct { Err util.Error Str string Row int // this is zero-indexed (the first line is 0) Col int // this is zero-indexed (the first char is 0) // Filename is the file that this error occurred in. If this is unknown, // then it will be empty. This is not set when run by the basic LexParse // function. Filename string }
LexParseErr is a permanent failure error to notify about borkage.
func (*LexParseErr) Error ¶
func (e *LexParseErr) Error() string
Error displays this error with all the relevant state information.
Source Files ¶
- Version
- v0.0.0-20250322185616-c50a578426f1 (latest)
- Published
- Mar 22, 2025
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 4 days ago –
Tools for package owners.