master
Sven Slootweg 3 years ago
parent ac2d6bfa8d
commit 344a75b7a1

@ -1,4 +1,6 @@
{ {
/* FIXME: `or` operator */
let operators = [{ let operators = [{
associativity: "left", associativity: "left",
operators: ["call"] operators: ["call"]
@ -101,7 +103,7 @@ escapableCharacter
/ "t" / "t"
/ "r" / "r"
commentCharacter inlineCommentCharacter
= [^\n\r] = [^\n\r]
// Literals // Literals
@ -129,14 +131,20 @@ homePath
storePath storePath
= "<" path:([a-zA-Z0-9\.\_\-\+]+ ("/" [a-zA-Z0-9\.\_\-\+]+)*) ">" { return {type: "path", pathType: "store", storePath: path}; } = "<" path:([a-zA-Z0-9\.\_\-\+]+ ("/" [a-zA-Z0-9\.\_\-\+]+)*) ">" { return {type: "path", pathType: "store", storePath: path}; }
uri
= [a-zA-Z][a-zA-Z0-9+\-.]* ":" [a-zA-Z0-9%/?:@&=+$,\-_.!~*']+
// Utilities // Utilities
_ _
= (whitespace / comment)* {} = (whitespace / inlineComment)* {}
__ __
= whitespace+ {} = whitespace+ {}
reservedWord // FIXME: Missing reserved words? reservedWord
= name:reservedWordName (& [^a-zA-Z0-9._-]) { return name; } // FIXME: Unify identifier character set definition
reservedWordName // FIXME: Missing reserved words?
= "if" = "if"
/ "then" / "then"
/ "else" / "else"
@ -171,11 +179,13 @@ nonOperatorExpression
/ withStatement / withStatement
/ conditional / conditional
/ path / path
/ identifier / uri
/ attributePathAlternate
comment inlineComment
= "#" chars:commentCharacter* _ { return {type: "comment", text: chars.join("")} } = "#" chars:inlineCommentCharacter* _ { return {type: "inlineComment", text: chars.join("")} }
/* FIXME: Where else to allow blockComments? Needs to be allowed everywhere, not just in expressions. */
blockComment blockComment
= "/*" segments:(! "*/" . [^*]*)* "*/" { return {type: "blockComment", text: joinBlockText(segments)} } = "/*" segments:(! "*/" . [^*]*)* "*/" { return {type: "blockComment", text: joinBlockText(segments)} }
@ -187,7 +197,7 @@ functionCallOperatorExpression
hasAttributeOperatorExpression hasAttributeOperatorExpression
= left:nonOperatorExpression = left:nonOperatorExpression
_ "?" _ "?"
_ right:identifier { return {type: "operatorExpression", operator: "?", left: left, right: right} } // FIXME: attribute path _ right:identifier { return {type: "operatorExpression", operator: "?", left: left, right: right} } /* FIXME: Is an attribute path allowed here? */
binaryOperatorExpression binaryOperatorExpression
= left:nonOperatorExpression = left:nonOperatorExpression
@ -197,22 +207,49 @@ binaryOperatorExpression
divisionOperatorExpression divisionOperatorExpression
= left:nonOperatorExpression = left:nonOperatorExpression
_ "/" _ "/"
_ right:expression { return {type: "operatorExpression", operator: "/", left: left, right: right} } _ right:expression {
return {type: "operatorExpression", operator: "/", left: left, right: right};
}
numericallyNegatedOperatorExpression numericallyNegatedOperatorExpression
= "-" = "-"
_ right:expression { return {type: "operatorExpression", operator: "numericalNegate", right: right} } _ right:expression {
return {type: "operatorExpression", operator: "numericalNegate", right: right};
}
booleanNegatedOperatorExpression booleanNegatedOperatorExpression
= "!" = "!"
_ right:expression { return {type: "operatorExpression", operator: "booleanNegate", right: right} } _ right:expression {
return {type: "operatorExpression", operator: "booleanNegate", right: right};
}
attributePathAlternate
= attributePath:attributePath alternate:(_ "or" _ attributePathAlternate)? {
if (alternate != null) {
return {type: "attributePathAlternate", path: attributePath, alternate: alternate};
} else {
return attributePath;
}
}
attributePath
= firstIdentifier:attributeItem nextIdentifiers:("." attributeItem)* {
return {type: "attributePath", items: [firstIdentifier].concat(nextIdentifiers.map(item => item[1]))};
}
attributeItem
= "\"" identifier:identifier "\"" { return identifier; } /* FIXME: What characters should be allowed here? */
/ identifier:identifier { return identifier; }
identifier identifier
= identifier:(! (reservedWord [^a-z0-9._-]) identifierValue) { return {type: "identifier", identifier: identifier[1]} } = identifier:(! reservedWord identifierValue) {
return {type: "identifier", identifier: identifier[1]};
}
/* FIXME: Quoted attributes? */
identifierValue identifierValue
= literal:stringLiteral { return literal.value; } = literal:stringLiteral { return literal.value; }
/ chars:[a-z_]i [a-z0-9._-]i+ { return text(); } / chars:[a-z_]i [a-z0-9_-]i+ { return text(); }
group group
= "(" = "("
@ -233,17 +270,18 @@ functionDefinitionArgument
= identifier = identifier
/ setPattern / setPattern
/* FIXME: Is `"foo" = "bar"` valid in an assignment list? */
assignment assignment
= identifier:identifier = attributePath:attributePath
_ "=" _ "="
_ expression:reorderedExpression _ expression:reorderedExpression
_ ";" { return {type: "assignment", identifier: identifier, expression: expression} } _ ";" { return {type: "assignment", attributePath: attributePath, expression: expression} }
assignmentList assignmentList
= _ items:((assignment / inheritStatement) _)* { return items.map(item => item[0]); } = _ items:((assignment / inheritStatement / blockComment) _)* { return items.map(item => item[0]); }
bindingList bindingList // FIXME: Allow inherit - point at assignmentList instead?
= items:(assignment _)* { return {type: "bindings", assignments: items.map(item => item[0])} } = items:((assignment / blockComment) _)* { return {type: "bindings", assignments: items.map(item => item[0])} }
set set
= "{" = "{"
@ -279,18 +317,20 @@ elseClause
= "else" = "else"
_ alternative:expression { return alternative; } _ alternative:expression { return alternative; }
/* FIXME: What to return here? */
withStatement withStatement
= "with" = "with"
_ identifier:identifier _ withExpression:expression
_ ";" _ ";"
_ expression _ expression
inheritStatement // FIXME: Distinguish between identifiers and attribute paths? inheritStatement /* FIXME: Distinguish between identifiers and attribute paths? */
= "inherit" = "inherit"
_ namespace:("(" identifier ")")? _ namespace:("(" reorderedExpression ")")?
_ identifiers:(identifier _)+ _ attributePaths:(attributePathAlternate _)+ /* FIXME: Is attributePathAlternate allowed here, or just attributePath? */
_ ";" { return {type: "inheritStatement", identifiers: identifiers.map(item => item[0]), namespace: maybe(namespace, 1)} } _ ";" { return {type: "inheritStatement", attributePaths: attributePaths.map(item => item[0]), namespace: maybe(namespace, 1)} }
/* FIXME: Are attribute paths allowed in set patterns? */
setPattern setPattern
= "{" = "{"
_ args:setPatternVariableList _ args:setPatternVariableList

@ -0,0 +1 @@
[if a then b else c]

@ -0,0 +1 @@
1 + if true then 1 else 2

@ -0,0 +1 @@
let inherit bar; in {}

@ -0,0 +1 @@
with if false then {} else {x = 2;}; x
Loading…
Cancel
Save