Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- start
- = PrimaryExpression
- PrimaryExpression
- = ArithmeticExpression
- / CallExpression
- / Identifier
- / Literal
- LeftHandSideExpression
- = UnaryOperator expression:LeftHandSideExpression {
- return {
- type: "callExpression",
- id: "NOT",
- arguments: expression
- }
- }
- / LeftHandSidePart
- LeftHandSidePart
- = CallExpression
- / Identifier
- / Literal
- / "(" __ expression:ArithmeticExpression __ ")" { return expression; }
- CallExpression
- = FunctionExpression
- FunctionExpression
- = id:FunctionIdentifier __ args:Arguments {
- return {
- type: "callExpression",
- id: id,
- arguments: args !== null ? args[0] : []
- }
- }
- ArithmeticExpression
- = LogicalAndExpression
- LogicalAndExpression
- = head:(LogicalOrExpression) __ (LogicalOperatorAnd) __ tail:LogicalAndExpression
- {
- return {
- type: "callExpression",
- id: "AND",
- arguments: [head, tail]
- }
- }
- / LogicalOrExpression
- LogicalOrExpression
- = head:(LogicalCompareExpression) __ (LogicalOperatorOr) __ tail:LogicalOrExpression
- {
- return {
- type: "callExpression",
- id: "OR",
- arguments: [head, tail]
- }
- }
- / LogicalCompareExpression
- LogicalCompareExpression
- = head:(ConcatinationExpression) __ op:(LogicalCompareOperator) __ tail:LogicalCompareExpression
- {
- var name;
- switch(op) {
- case "<":
- name = "lessThan"
- break;
- case "<=":
- name = "lessThanOrEqual"
- break;
- case ">":
- name = "greaterThan"
- break;
- case ">=":
- name = "greaterThanOrEqual"
- break;
- case "==":
- case "=":
- name = "equal"
- break;
- case "!=":
- case "<>":
- name = "unequal"
- break;
- default:
- }
- return {
- type: "callExpression",
- id: name,
- arguments: [head, tail]
- }
- }
- / ConcatinationExpression
- ConcatinationExpression
- = head:(AdditiveExpression) __ op:(ConcatinationOperator) __ tail:ConcatinationExpression
- {
- return {
- type: "callExpression",
- id: "add",
- arguments: [head, tail]
- }
- }
- / AdditiveExpression
- AdditiveExpression
- = head:MultiplicativeExpression __ op:("+" / "-" ) __ tail:AdditiveExpression
- {
- return {
- type: "callExpression",
- id: op == "+" ? "add" : "negate",
- arguments: [head, tail]
- }
- }
- / MultiplicativeExpression
- MultiplicativeExpression
- = head:ExponentiateExpression __ op:("*" / "/" ) __ tail:MultiplicativeExpression
- {
- return {
- type: "callExpression",
- id: op == "*" ? "multiply" : "invert",
- arguments: [head, tail]
- }
- }
- / ExponentiateExpression
- ExponentiateExpression
- = head:(LeftHandSideExpression) __ "^" __ tail:ExponentiateExpression
- {
- return {
- type: "callExpression",
- id: "exponentiate",
- arguments: [head, tail]
- }
- }
- / LeftHandSideExpression
- LogicalCompareOperator
- = "<="
- / ">="
- / "<>"
- / "<"
- / ">"
- / "=="
- / "="
- / "!="
- ConcatinationOperator
- = "&"
- UnaryOperator
- = "!"
- Arguments
- = "(" __ args:(ArgumentList __)? ")" {
- return args;
- }
- ArgumentList
- = args:(
- arg:PrimaryExpression __ ","? __ {
- return arg;
- }
- )+ {
- return args;
- }
- FunctionIdentifier
- = id:[A-Za-z]+ { return id.join("").toLowerCase(); }
- Identifier
- = !ReservedKeyword name:IdentifierName { return name; }
- IdentifierName
- = IdentifierExpression
- IdentifierExpression
- = head:IdentifierStart tail:IdentifierPart* {
- return {
- type: "identifier",
- name: head + tail.join("")
- };
- }
- LogicalOperatorOr
- = "||"
- LogicalOperatorAnd
- = "&&"
- IdentifierStart
- = "_"
- / [$A-Za-z\.]
- IdentifierPart
- = IdentifierStart
- / DecimalDigit
- Literal
- = StringLiteral
- / NumericLiteral
- / BooleanLiteral
- / NullLiteral
- StringLiteral
- = chars:Character {
- return {
- type: "literal",
- value: chars,
- dataType: "text",
- options: {
- length: chars.length
- }
- };
- }
- NumericLiteral
- = DecimalLiteral
- DecimalLiteral
- = sign:(__ "+" / "-" __)? DecimalIntegerLiteral "." DecimalDigit* {
- var splitted = text().replace(/[\+\-]/g, "").split(".")
- return {
- type: "literal",
- value: parseFloat(text()),
- dataType: "number",
- options: {
- length: splitted[0].length,
- scale: splitted[1].length,
- }
- };
- }
- / sign:(__ "+" / "-" __)? DecimalIntegerLiteral {
- return {
- type: "literal",
- value: parseInt(text()),
- dataType: "number",
- options: {
- length: text().replace(/[\+\-]/g, "").length,
- scale: 0,
- }
- };
- }
- DecimalIntegerLiteral
- = "0"
- / NonZeroDigit DecimalDigit*
- DecimalDigit
- = [0-9]
- NonZeroDigit
- = [1-9]
- BooleanLiteral
- = "TRUE"i !(IdentifierStart) {
- return {
- type: "literal",
- value: true,
- dataType: "checkbox",
- options: {}
- }
- }
- / "FALSE"i !(IdentifierStart) {
- return {
- type: "literal",
- value: false,
- dataType: "checkbox",
- options: {}
- }
- }
- NullLiteral
- = "NULL"i !(IdentifierStart) {
- return {
- type: "literal",
- value: null,
- dataType: "null",
- options: {}
- }
- }
- Character
- = DoubleQuote chars:DoubleStringCharacter* DoubleQuote { return chars.join(''); }
- / SingleQuote chars:SingleStringCharacter* SingleQuote { return chars.join(''); }
- DoubleStringCharacter
- = !(DoubleQuote / Backslash) char:. { return char; }
- / Backslash sequence:EscapeSequence { return sequence; }
- SingleStringCharacter
- = !(SingleQuote / Backslash) char:. { return char; }
- / Backslash sequence:EscapeSequence { return sequence; }
- EscapeSequence
- = SingleQuote
- / DoubleQuote
- / Backslash
- / "b" { return "\b"; }
- / "f" { return "\f"; }
- / "n" { return "\n"; }
- / "r" { return "\r"; }
- / "t" { return "\t"; }
- / "v" { return "\x0B"; }
- SingleQuote
- = '\''
- DoubleQuote
- = '"'
- Backslash
- = '\\'
- LineTerminator
- = [\n\r\u2028\u2029]
- ReservedKeyword
- = BooleanLiteral / NullLiteral
- __
- = (WhiteSpace)*
- WhiteSpace
- = "\t"
- / "\v"
- / "\f"
- / " "
- / "\u00A0"
- / "\uFEFF"
- / "\r"
- / "\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement