parsers

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package parser defines parsers for OCL

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

And will match a logical and expression defined by the following rule, where P is the input parser:

S -> P ("&&" P)*

func Array

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

func Element(p parsley.Parser, index parsley.Parser) *combinator.Sequence

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

func ID() parser.Func

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 IDWithClassifier(classifier rune) parser.Func

func KeyValuePairs

func KeyValuePairs() *combinator.Sequence

func Map

func Map(p parsley.Parser) parser.Func

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

func MultilineText() parser.Func

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

func Not(p parsley.Parser) parser.Func

Not will match a logical not expression defined by the following rule, where P is the input parser:

S -> "!"? P

func Or

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 SepByOp

SepByOp applies the given value parser one or more times separated by the op parser

func Sum

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) ParseDir

func (m *Main) ParseDir(ctx *conflow.ParseContext, dir string) error

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

func (*Main) ParseText

func (m *Main) ParseText(ctx *conflow.ParseContext, input string) error

ParseText parses the string input as a main block

func (*Main) TransformNode

func (m *Main) TransformNode(userCtx interface{}, node parsley.Node) (parsley.Node, parsley.Error)

TransformNode will transform the parsley node into a conflow block node

Jump to

Keyboard shortcuts

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