parse

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 10 Imported by: 1

README

Grammar


rule ::= atom '.'
       | atom  ':-' rhs

rhs ::= litOrFml (',' litOrFml)* '.'
      | litOrFml (',' litOrFml)* '|>' transforms

transforms ::= stmts '.'
             | 'do' apply-expr ',' stmts '.'

stmts ::= stmt (',' stmt)*
stmt ::= 'let' var '=' expr

litOrFml ::= atom | '!' atom | cmp

atom ::= pred-ident '(' exprs? ')'

expr ::= apply-expr
       | constant
       | var

exprs ::= expr (',' expr)*

apply-expr ::= fn-ident '(' exprs? ')'
             | [ exprs? ]

cmp ::= expr op expr

op ::= '=' | '!=' | '<' | '>'

constant   ::= name, number or string constant
fn-ident   ::= ident (starting with 'fn:')
pred-ident ::= ident (not starting with 'fn:')

Documentation

Overview

Package parse provides methods to parse datalog programs and parts thereof.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Atom

func Atom(s string) (ast.Atom, error)

Atom parses an Atom from given string.

func BaseTerm

func BaseTerm(s string) (ast.BaseTerm, error)

BaseTerm parses a BaseTerm from given string.

func Clause

func Clause(s string) (ast.Clause, error)

Clause parses a single clause.

func LiteralOrFormula

func LiteralOrFormula(s string) (ast.Term, error)

LiteralOrFormula parses a single Term, an equality or inequality from a given string.

func PredicateName

func PredicateName(s string) (string, error)

PredicateName parses a predicate name.

func Term

func Term(s string) (ast.Term, error)

Term parses a Term from given string.

Types

type Error

type Error struct {
	Message string
	Line    int // 1-based line number within source.
	Column  int // 0-based line number within source.
}

Error represents a parser error messages, without location.

type Parser

type Parser struct {
	gen.BaseMangleVisitor
	// contains filtered or unexported fields
}

Parser represents an object that can be used for parsing.

func (*Parser) ReportAmbiguity

func (p *Parser) ReportAmbiguity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, exact bool, ambigAlts *antlr.BitSet, configs *antlr.ATNConfigSet)

ReportAmbiguity implements error listener interface.

func (*Parser) ReportAttemptingFullContext

func (p *Parser) ReportAttemptingFullContext(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, conflictingAlts *antlr.BitSet, configs *antlr.ATNConfigSet)

ReportAttemptingFullContext implements error listener interface.

func (*Parser) ReportContextSensitivity

func (p *Parser) ReportContextSensitivity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex, prediction int, configs *antlr.ATNConfigSet)

ReportContextSensitivity implements error listener interface.

func (*Parser) SyntaxError

func (p *Parser) SyntaxError(recognizer antlr.Recognizer, offendingSymbol any, line, column int, msg string, e antlr.RecognitionException)

SyntaxError is called by ANTLR generated code when a syntax error is encountered.

func (*Parser) Visit

func (p *Parser) Visit(tree antlr.ParseTree) any

Visit is the Visitor implementation.

func (Parser) VisitAppl

func (p Parser) VisitAppl(ctx *gen.ApplContext) any

VisitAppl visits a parse tree produced by MangleParser#Appl.

func (Parser) VisitAtom

func (p Parser) VisitAtom(ctx *gen.AtomContext) any

VisitAtom visits a parse tree produced by MangleParser#atoms.

func (Parser) VisitAtoms

func (p Parser) VisitAtoms(ctx *gen.AtomsContext) any

VisitAtoms visits a parse tree produced by MangleParser#atoms.

func (Parser) VisitBoundsBlock

func (p Parser) VisitBoundsBlock(ctx *gen.BoundsBlockContext) any

VisitBoundsBlock visits a parse tree produced by MangleParser#boundsBlock.

func (Parser) VisitClause

func (p Parser) VisitClause(ctx *gen.ClauseContext) any

VisitClause visits a parse tree produced by MangleParser#clause.

func (Parser) VisitClauseBody

func (p Parser) VisitClauseBody(ctx *gen.ClauseBodyContext) any

VisitClauseBody visits a parse tree produced by MangleParser#clauseBody.

func (Parser) VisitConst

func (p Parser) VisitConst(ctx *gen.ConstContext) any

VisitConst visits a parse tree produced by MangleParser#Const.

func (Parser) VisitConstraintsBlock

func (p Parser) VisitConstraintsBlock(ctx *gen.ConstraintsBlockContext) any

VisitConstraintsBlock visits a parse tree produced by MangleParser#constraintsBlock.

func (Parser) VisitDecl

func (p Parser) VisitDecl(ctx *gen.DeclContext) any

VisitDecl visits a parse tree produced by MangleParser#decl.

func (Parser) VisitDescrBlock

func (p Parser) VisitDescrBlock(ctx *gen.DescrBlockContext) any

VisitDescrBlock visits a parse tree produced by MangleParser#descrBlock.

func (Parser) VisitFloat

func (p Parser) VisitFloat(ctx *gen.FloatContext) any

VisitFloat visits a parse tree produced by MangleParser#Float.

func (Parser) VisitLetStmt

func (p Parser) VisitLetStmt(ctx *gen.LetStmtContext) any

VisitLetStmt visits a parse tree produced by MangleParser#letStmt.

func (Parser) VisitList

func (p Parser) VisitList(ctx *gen.ListContext) any

VisitList visits a parse tree produced by MangleParser#List.

func (Parser) VisitLiteralOrFml

func (p Parser) VisitLiteralOrFml(ctx *gen.LiteralOrFmlContext) any

VisitLiteralOrFml visits a parse tree produced by literalOrFml

func (Parser) VisitMap

func (p Parser) VisitMap(ctx *gen.MapContext) any

VisitMap visits a parse tree produced by MangleParser#Map.

func (Parser) VisitNum

func (p Parser) VisitNum(ctx *gen.NumContext) any

VisitNum visits a parse tree produced by MangleParser#Num.

func (Parser) VisitPackageDecl

func (p Parser) VisitPackageDecl(ctx *gen.PackageDeclContext) any

VisitPackageDecl visits a parse tree produced by MangleParser#packageDecl.

func (Parser) VisitProgram

func (p Parser) VisitProgram(ctx *gen.ProgramContext) any

VisitProgram visits a parse tree produced by MangleParser#program.

func (Parser) VisitStart

func (p Parser) VisitStart(ctx *gen.StartContext) any

VisitStart visits a parse tree produced by MangleParser#start.

func (Parser) VisitStr

func (p Parser) VisitStr(ctx *gen.StrContext) any

VisitStr visits a parse tree produced by MangleParser#Str.

func (Parser) VisitStruct

func (p Parser) VisitStruct(ctx *gen.StructContext) any

VisitStruct visits a parse tree produced by MangleParser#Struct.

func (Parser) VisitTransform

func (p Parser) VisitTransform(ctx *gen.TransformContext) any

VisitTransform visits a parse tree produced by MangleParser#transform.

func (Parser) VisitUseDecl

func (p Parser) VisitUseDecl(ctx *gen.UseDeclContext) any

VisitUseDecl visits a parse tree produced by MangleParser#useDecl.

func (Parser) VisitVar

func (p Parser) VisitVar(ctx *gen.VarContext) any

VisitVar visits a parse tree produced by MangleParser#Var.

type SourceUnit

type SourceUnit struct {
	Decls   []ast.Decl
	Clauses []ast.Clause
}

SourceUnit consists of decls and clauses.

func Unit

func Unit(reader io.Reader) (SourceUnit, error)

Unit parses a source unit (clauses and decls).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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