Documentation ¶
Overview ¶
Package parser defines parsers for OCL
Index ¶
- func And(p parsley.Parser) *combinator.Sequence
- func Array(p parsley.Parser) *combinator.Sequence
- func Block(expr parsley.Parser) *combinator.Sequence
- func Compare(p parsley.Parser) *combinator.Sequence
- func Directive(expr parsley.Parser) *combinator.Sequence
- func Element(p parsley.Parser, index parsley.Parser) *combinator.Sequence
- func Expression() *combinator.Sequence
- func Function(p parsley.Parser) *combinator.Sequence
- func ID() parser.Func
- func IDWithClassifier(classifier rune) parser.Func
- func KeyValuePairs() *combinator.Sequence
- func Map(p parsley.Parser) parser.Func
- func MultilineText() parser.Func
- func Name(sep rune) *combinator.Sequence
- func Not(p parsley.Parser) parser.Func
- func Or(p parsley.Parser) *combinator.Sequence
- func Parameter(expr parsley.Parser, allowNewAssignment bool, allowDirectives bool) *combinator.Sequence
- func ProdMod(p parsley.Parser) *combinator.Sequence
- func SepByComma(p parsley.Parser) *combinator.Sequence
- func SepByOp(p parsley.Parser, op parsley.Parser) *combinator.Sequence
- func Sum(p parsley.Parser) *combinator.Sequence
- func TernaryIf(p parsley.Parser) *combinator.Sequence
- func Variable() *combinator.Sequence
- type Main
- func (m *Main) Eval(userCtx interface{}, node parsley.NonTerminalNode) (interface{}, parsley.Error)
- func (m *Main) Parse(ctx *parsley.Context, leftRecCtx data.IntMap, pos parsley.Pos) (parsley.Node, data.IntSet, parsley.Error)
- func (m *Main) ParseDir(ctx *conflow.ParseContext, dir string) error
- func (m *Main) ParseFile(ctx *conflow.ParseContext, path string) error
- func (m *Main) ParseFiles(ctx *conflow.ParseContext, paths ...string) error
- func (m *Main) ParseText(ctx *conflow.ParseContext, input string) error
- func (m *Main) TransformNode(userCtx interface{}, node parsley.Node) (parsley.Node, parsley.Error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func And ¶
func And(p parsley.Parser) *combinator.Sequence
And will match a logical and expression defined by the following rule, where P is the input parser:
S -> P ("&&" P)*
func Array ¶
func Array(p parsley.Parser) *combinator.Sequence
Array will match an array expression defined by the following rule, where P is the input parser:
S -> "[" "]" S -> "[" P ("," P)* "]"
func Block ¶
func Block(expr parsley.Parser) *combinator.Sequence
Block returns a parser for parsing blocks
S -> ID? TYPE KEY? { (ATTR|S)* } -> ID? TYPE KEY? VALUE ID -> /[a-z][a-z0-9]*(?:_[a-z0-9]+)*/ TYPE -> /[a-z][a-z0-9]*(?:_[a-z0-9]+)*/ KEY -> STRING LITERAL ATTR -> ID ("="|":=") P VALUE -> EXPRESSION -> ARRAY -> MAP
func Compare ¶
func Compare(p parsley.Parser) *combinator.Sequence
Compare will match comparison expressions defined by the following rule, where P is the input parser:
S -> P (COMP_OP P)* COMP_OP -> "==" -> "!=" -> "<" -> "<=" -> ">" -> ">="
func Directive ¶
func Directive(expr parsley.Parser) *combinator.Sequence
Directive returns a parser for parsing directives
S -> "@" ID { (PARAMETER|BLOCK)* } -> ID VALUE VALUE -> EXPRESSION -> ARRAY -> MAP
func Element ¶
Element will match a variable expression defined by the following rule, where P is the input parser:
S -> P (VAR_INDEX)* VAR_INDEX -> "." ID -> "[" P "]" ID -> /[a-z][a-z0-9]*(?:_[a-z0-9]+)*/
func Expression ¶
func Expression() *combinator.Sequence
Expression returns with an expression parser
func Function ¶
func Function(p parsley.Parser) *combinator.Sequence
Function will match a function call defined by the following rule, where P is the input parser:
S -> ID "(" PARAMS ")" ID -> /[a-z][a-z0-9]*(?:_[a-z0-9]+)*/ PARAMS -> EMPTY -> P ("," P)*
func ID ¶
ID parses an identifier:
S -> /[a-z][a-z0-9]*(?:_[a-z0-9]+)*/
An identifier can only contain lowercase letters, numbers and underscore characters. It must start with a letter, must end with a letter or number, and no duplicate underscores are allowed.
func IDWithClassifier ¶
func KeyValuePairs ¶
func KeyValuePairs() *combinator.Sequence
func Map ¶
Map will match an map expression defined by the following rule, where P is the input parser:
S -> "map" "{" "}" S -> "map" "{" (STRING ":" P ",")* "}"
func MultilineText ¶
MultilineText parses a multiline text in the following format:
”'
first line second line
”'
This will result in "first line\nsecond line\n".
Also works with """ and ``` quotes, but the opening and closing quotes must be the same.
There must be a new line after the opening quotes and the closing quotes must be after a new line All text lines must be empty or start with the same whitespace characters as the first text line The common prefix whitespace characters will be stripped from all lines
func Name ¶
func Name(sep rune) *combinator.Sequence
Name parses a name expression:
S -> ID ID SEP ID ID -> /[a-z][a-z0-9]*(?:_[a-z0-9]+)*/
func Not ¶
Not will match a logical not expression defined by the following rule, where P is the input parser:
S -> "!"? P
func Or ¶
func Or(p parsley.Parser) *combinator.Sequence
Or will match a logical or expression defined by the following rule, where P is the input parser:
S -> P ("||" P)*
func Parameter ¶
func Parameter(expr parsley.Parser, allowNewAssignment bool, allowDirectives bool) *combinator.Sequence
Parameter returns with a parameter parser If allowNewAssignment is false then only "=" will be allowed
S -> ID ("="|":=") P ID -> /[a-z][a-z0-9]*(?:_[a-z0-9]+)*/
func ProdMod ¶
func ProdMod(p parsley.Parser) *combinator.Sequence
ProdMod will match *, /, % arithmetic operations defined by the following rule, where P is the input parser:
S -> P (PROD_MOD_OP P)* PROD_MOD_OP -> "*" -> "/" -> "%"
func SepByComma ¶
func SepByComma(p parsley.Parser) *combinator.Sequence
SepByComma applies the given value parser zero or more times separated by comma
func Sum ¶
func Sum(p parsley.Parser) *combinator.Sequence
Sum will match +, - arithmetic operations defined by the following rule, where P is the input parser:
S -> P (SUM_OP P)* SUM_OP -> "+" -> "-"
func TernaryIf ¶
func TernaryIf(p parsley.Parser) *combinator.Sequence
TernaryIf will match a ternary if expression defined by the following rule, where P is the input parser:
S -> P -> P "?" P ":" P
func Variable ¶
func Variable() *combinator.Sequence
Variable will match a variable expression defined by the following rule, where P is the input parser:
S -> ID "." ID ID -> /[a-z][a-z0-9]*(?:_[a-z0-9]+)*/
Variable refers to a named block's parameter, in the format of `<block ID>.<parameter ID>`.
Types ¶
type Main ¶
type Main struct {
// contains filtered or unexported fields
}
Main is the main block parser It will parse a block body (list of params and blocks) and will return with a block with the given id and the type "main"
func NewMain ¶
func NewMain(id conflow.ID, interpreter conflow.BlockInterpreter) *Main
NewMain returns a parser for parsing a main block (a block body)
S -> (PARAM|BLOCK)* ID -> /[a-z][a-z0-9]*(?:_[a-z0-9]+)*/ PARAM -> ID ("="|":=") P VALUE -> EXPRESSION -> ARRAY -> MAP
func (*Main) Eval ¶
func (m *Main) Eval(userCtx interface{}, node parsley.NonTerminalNode) (interface{}, parsley.Error)
Eval will panic as it should not be called on a raw block node
func (*Main) Parse ¶
func (m *Main) Parse(ctx *parsley.Context, leftRecCtx data.IntMap, pos parsley.Pos) (parsley.Node, data.IntSet, parsley.Error)
Parse will parse the input into a block
func (*Main) ParseFile ¶
func (m *Main) ParseFile(ctx *conflow.ParseContext, path string) error
ParseFile parses the given file as a main block
func (*Main) ParseFiles ¶
func (m *Main) ParseFiles(ctx *conflow.ParseContext, paths ...string) error
ParseFiles parses multiple files as one block