---
title: BVL grammar
summary: The Xtext grammar of BVL as shipped in this release.
order: 900
---

# BVL grammar

The Xtext grammar the BIM Visualization Language parser is generated from, exactly as shipped in this release. Rules read top-down; `=>` marks a syntactic predicate, `+=` collects a list, `?=` a boolean flag. Terminals not declared here (`ID`, `STRING`, `INT`, comments) come from the common Xtext terminals; the languages that build on BQL inherit every rule from it.

```text {#grammar}
grammar nl.bimbase.bimworks.Bvl with nl.bimbase.bimworks.Bql

import "http://www.bimbase.nl/bimworks/Bql" as bql

generate bvl "http://www.bimbase.nl/bimworks/Bvl"

Bvl:
	(transition=TransitionHeader)?
	root=BlockContent
;

// The animation from the current state to the script's (docs/viewer-state-transitions-design.md §8.3):
// TRANSITION 600ms; or TRANSITION 1s "ease-out"; easing "linear", "ease-in", "ease-out" or "ease-in-out" (default)
TransitionHeader:
	"TRANSITION" duration=DURATION (easing=STRING)? ";"
;

IfCondition:
	"if" "(" booleanExpression=MinimalBql ")" 
		block=Block
	("else" else=IfCondition)?
	(=>"else" elseBlock=Block)?
;

Block:
	{Block}
	"{"
	content=BlockContent
	"}"
;

BlockContent:
	{BlockContent}
	(groups+=Group)*
	(actionSets+=ActionSet)*
	(subConditions+=IfCondition)*
;

Group:
	"group" "(" feature=GetFeature ")" block=Block
;

ActionSet:
	{ActionSet} (
		(actions += Action)+
		(subject = Subject)?
		";"
	)
;

Action:
	Visibility | Color | WireframeVisibility | WireframeColor | View | Selection | Pickability | Sectionability | SectionEndcaps | SoftOccluding | OnTopDrawing | Label | Annotate | ClearAnnotations
;

// A geometric aggregate of the object as its subject (docs/bql-geometric-aggregates-design.md §8.3): the
// SLICE or PROJECTION a requirement measured, drawn as an overlay area on each result, in the result's
// colour, with the same text a BQL query writes - SHOW allChildren(PROJECTION(ABOVE 0 mm) WHERE ...);
// A separate feature, so geometry keeps its type for every other subject.
Subject:
	geometry = (Cylinder | Box | Sphere | Cone | Geometry | MaximumInscribedCylinderFeature | ClashesWith | Path
		| Outline | Footprint | Dimension | MaximumInscribedCircleFeature | Displacement)
	| shape = RelationAggregate
;

// Figures (docs/check-overlays-design.md §11.1): what a check measured, drawn as an overlay item
// on the object, coloured by the object's check result unless COLOR gives one. A label action on
// a figure becomes the figure's label: HOVER (the default) shows it only while the object or the
// figure is hovered, ANNOTATION always. SHOW draws the figure without a label.
//   label(calculated.quantity.floorArea, HOVER) OUTLINE;
//   SHOW MAXIMUM_INSCRIBED_CIRCLE(geometry2d);
//   label(aabb.height) DIMENSION(height);

// The horizontal section of the object at a height above its lowest point (default 5 mm: the
// floor outline), drawn on the floor.
Outline:
	{Outline}
	"OUTLINE" ("(" height=NumericLiteralWithUnit ")")?
;

// The footprint of the object's model: the plan projection of everything in it, computed at
// checkin, drawn under the object and on top of the model. Meant for a building or site, e.g.
//   label("Area under construction " + property."AR_Hoone"."045_Hoonealune-pindala", ANNOTATION) FOOTPRINT;
Footprint:
	{Footprint}
	"FOOTPRINT"
;

// An arrow from where a compared object was to where it is (docs/model-compare-design.md §5.10):
// from the left object's box centre to the right object's, in a compare outcome block. A label or
// annotate action on it becomes the arrow's label; SHOW DISPLACEMENT draws it without one. Outside
// a compare there is no pair, so nothing is drawn.
//   annotate(text("Moved " + change.geometry.translation.length) hover) DISPLACEMENT;
Displacement:
	{Displacement}
	"DISPLACEMENT"
;

// An arrow over one side of the object's bounding box.
Dimension:
	{Dimension}
	"DIMENSION" "(" axis=DimensionAxis ")"
;

enum DimensionAxis:
	HEIGHT="height" | WIDTH="width" | DEPTH="depth"
;

Geometry:
	{Geometry}
	"geometry"
;

// Walkable route from each matched object to the nearest `to` target
// (walkable-surfaces design par 6.3 channel b), drawn as a `path` overlay item, the snake
// (docs/check-result-interaction-design.md §7). THROUGH and AGENT mirror the nav: family in BQL;
// FROM is where the route starts in the object (NEAREST, the default, or CENTROID); LIFT raises the
// drawing above the floor; LIMIT draws the part beyond that length in the hazard colour.
//   SHOW PATH(type = IFCDOOR AND ..., FROM CENTROID, LIFT 1000 mm, LIMIT 45 m);
Path:
	{Path}
	"PATH" "(" to=BooleanExpressionOrQids
		("," "THROUGH" "(" through=BooleanExpression ")")?
		("," agent=AgentSpec)?
		("," "FROM" start=NavStart)?
		("," "LIFT" lift=NumericLengthLiteralWithUnit)?
		("," "LIMIT" limit=NumericLengthLiteralWithUnit)? ")"
;

View:
	ViewFit
;

// VIEWFIT [<duration>] [FROM "<side>"] [MARGIN <n>%]: the flight's length, the side it looks from ("top", "bottom",
// "front", "back", "left", "right") and the margin around the objects; all objects of a script's VIEWFITs are fitted
// together, with the options of the last one that gives any
ViewFit:
	{ViewFit}
	"VIEWFIT" (duration=DURATION)? ("FROM" side=STRING)? ("MARGIN" margin=LONG "%")?
;

Color returns Color:
	({ResetColor}("COLOR" "RESET" (transparency=LONG "%")?)) |
	// The colour of the object's own check result (the viewer's result palette), at a transparency
	// (docs/check-result-interaction-design.md §8.6): COLOR RESULT 50%
	({ResultColor}("COLOR" "RESULT" (transparency=LONG "%")?)) |
	({AutoColor}("COLOR" "auto" (transparency=LONG "%")?)) |
	// The transparency may be a parameter, 0-100 (docs/model-compare-design.md §5.10): COLOR "#EC4339" $ghost
	({Color}("COLOR" color=STRING ((transparency=LONG "%") | transparencyParameter=Parameter)?))
;

ColorLiteral:
	{ColorLiteral} (
		(color=STRING (transparency=LONG "%")?)
	)
;

Label:
	{Label} (
		// Predicated alternative instead of (key=STRING ",")? value=...: a leading
		// STRING is only treated as key if a valid LabelValue follows the comma;
		// otherwise the STRING is the value (e.g. label("v", HOVER)).
		"label" "(" (=>(key=STRING "," value=LabelValue) | value=LabelValue) ("," type=LabelType)? ")"
	)
;

// The representation, then the options in any order, each at most once (an unordered group: a second one is a
// syntax error, which BvlSyntaxErrorMessageProvider names), e.g.
//   annotate(text("Inspect") "maintenance" scale distance hover)
Annotate:
	{Annotate}
	"annotate" "("
		representation = AnnotationRepresentation
		(
			(visibility = AnnotationVisibility)?
			& (visibilityLimits = AnnotationVisibilityLimits)?
			// At most this many annotations of the group show, those nearest to the camera, e.g.
			//   annotate(svg("glyphicons-basic-316-wrench.svg") nearest 50)
			// A positive count; without a group name each annotate is a group of its own
			& ("nearest" nearest = LONG)?
			& ("occlusion" occlusion = AnnotationOcclusion)?
			& ("cluster" cluster = AnnotationCluster)?
			& ("scale" scale = AnnotationScale)?
			// When the expanded state shows (template annotations only, Viewer3D/docs/rich-annotations-design.md §12),
			// where on the object the annotation sits and which side of that point it is drawn on, e.g.
			//   annotate(template("checkResult", "rule" = "FireRating present", "outcome" = "fail") expand click anchor top)
			//   annotate(text(attribute.GlobalId) anchor top back left align right)
			& ("expand" expand = AnnotationExpand)?
			& ("anchor" anchor = AnnotationAnchor)?
			& ("align" align = AnnotationAlign)?
			& (group = AnnotationGroup)?
		)
	")"
;

ClearAnnotations:
	// The parens around the alternatives are load-bearing: | binds loosest, so without
	// them the "all" branch excluded the closing paren and clearAnnotations(all) could
	// never parse. Bare "all" is deliberately not captured — an empty groups list is
	// the clear-all case (BvlResolver).
	{ClearAnnotations} "clearAnnotations" "("
		("all" | (groups+=STRING ("," groups+=STRING)*))
	")"
;

// No {AnnotationGroup} action, nor one in AnnotationVisibilityLimits: a rule that starts with an action gives its node
// the action as grammar element, so the serializer could not match it to its option and wrote the options in grammar
// order with the source's whitespace ("hoverdistance")
AnnotationGroup:
	name = STRING
;

AnnotationRepresentation:
	AnnotateText | AnnotateSvg | AnnotateImage | AnnotateTemplate
;

AnnotationVisibility:
	"always" | "link" | "hover"
;

AnnotationVisibilityLimits:
	"distance" distance=NumericLengthLiteralWithUnit
;

// What the 3D viewer does with the annotation while its object is behind other geometry
// (Viewer3D/docs/annotation-occlusion-design.md §6.1): hide it (the viewer's default), dim it (drawn
// at 35 %) or none (keep showing it). Decided once the camera settles, e.g.
//   annotate(svg("glyphicons-basic-316-wrench.svg") occlusion dim)
AnnotationOcclusion:
	"hide" | "dim" | "none"
;

// Whether the 3D viewer may merge the annotation with nearby ones into a single marker with a count
// (Viewer3D/docs/annotation-placement-survey.md, "Declutter is split by annotation type"): on (the
// default) or off, which keeps it showing at its own anchor. svg icons and text labels cluster,
// images never do, e.g.
//   annotate(svg("glyphicons-basic-316-wrench.svg") cluster off)
AnnotationCluster:
	"on" | "off"
;

// When the card of a template annotation's expanded state shows: on hover (a click pins it), on a click, never
AnnotationExpand:
	"hover" | "click" | "none"
;

// Where the annotation sits on its object (docs/annotation-anchors-design.md §3.1): a point of the object's box in its
// model's own axes, the same whatever the view. Up to three words in this order: top | center | bottom (the model's
// +Z / -Z), front | back (-Y / +Y) and left | right (-X / +X), the middle along an axis left out: top is the middle of
// the top face, top back left a corner of it, left the middle of the left face. Without an anchor the centre (a
// template's own default for a template). BvlResolver writes the words joined with "-" ("top-back-left")
AnnotationAnchor:
	("top" | "center" | "bottom") ("front" | "back")? ("left" | "right")?
	| ("front" | "back") ("left" | "right")?
	| ("left" | "right")
;

// Which side of its anchor the annotation is drawn on, on screen (§3.4): centred on it, or beside it, the anchor on
// the middle of the annotation's bottom (above), top (below), right (left) or left (right) edge. Without one text and
// icons are centred, a template sits by its own origin
AnnotationAlign:
	"center" | "above" | "below" | "left" | "right"
;

// How the 3D viewer sizes the annotation: distance draws it smaller the further it is from the camera
// (its normal size up to 10 m, down to 40 %; its normal size while hovered), never larger than its
// normal size; fixed keeps its normal size at any distance. Left out, the viewer's setting decides, e.g.
//   annotate(svg("glyphicons-basic-316-wrench.svg") scale distance)
AnnotationScale:
	"distance" | "fixed"
;

AnnotateText returns AnnotationRepresentation:
	{AnnotateText}
	// Same predicated key/value disambiguation as Label. NOTE: text("a","b") is
	// inherently ambiguous (key+value vs value+color); the key interpretation wins
	// (unchanged policy) — a color for an un-keyed string value requires a key.
	"text" "(" (=>(key=STRING "," value=LabelValue) | value=LabelValue) ("," color=ColorLiteral ("," hoverColor=ColorLiteral "," backgroundColor=ColorLiteral "," backgroundHoverColor=ColorLiteral)?)? ")"
;

AnnotateSvg returns AnnotationRepresentation:
	{AnnotateSvg}
	"svg" "(" src=STRING ("," color=ColorLiteral ("," hoverColor=ColorLiteral "," backgroundColor=ColorLiteral "," backgroundHoverColor=ColorLiteral "," borderColor=ColorLiteral "," borderHoverColor=ColorLiteral)?)? ")"
;

AnnotateImage returns AnnotationRepresentation:
	{AnnotateImage}
	"image" "(" src=STRING ")"
;

// A template registered with the viewer, by name, with the data it shows (Viewer3D/docs/rich-annotations-design.md
// §12): "field" = value, evaluated per object as text() values are. Without bindings a built-in template uses the
// fields it declares. Built-in names are bare ("objectLabel"); an application's template has a dotted name, e.g.
//   annotate(template("objectLabel"))
//   annotate(template("properties", "Fire rating" = property.Pset_DoorCommon.FireRating) expand hover)
AnnotateTemplate returns AnnotationRepresentation:
	{AnnotateTemplate}
	"template" "(" name=STRING ("," fields+=TemplateField)* ")"
;

TemplateField:
	key=STRING "=" value=LabelValue
;

enum LabelType:
	HOVER | ANNOTATION
;

LabelValue:
	FeatureLabel | StringLabel | SequenceLabel | ImageLabel
;

ImageLabel:
	"image" "(" image=STRING ("," color=STRING)? ")"
;

SequenceLabel:
	{SequenceLabel}
	"SEQ"
;

StringLabel:
	value = STRING
;

// A feature, or an arithmetic expression over features as a GET column takes one (docs/bql-expressions-design.md
// §3.5), optionally in a UNIT, between an optional prefix and postfix, e.g.
//   label("Area " + calculated.quantity.floorArea UNIT m2)
//   annotate(template("properties", "Difference" = quantity.BaseQuantities.NetVolume - calculated.quantity.netVolume))
//   label(ROUND(100 * (quantity.BaseQuantities.NetVolume - calculated.quantity.netVolume) / calculated.quantity.netVolume, 0.1) + " %")
// A bare feature keeps its Feature node, so only the static type of feature widened
FeatureLabel:
	(prefix=STRING "+")? feature = LabelExpression (=>"UNIT" unit=Unit)? ("+" postfix=STRING)?
;

// Bql's GetAddSub, but an operator is only taken when its right operand parses (the predicate covers both): a "+"
// followed by a "string" is the postfix of the label, never an addition
LabelExpression returns bql::Expression:
	GetMulDiv (=>({bql::Addition.left=current} '+' right=GetMulDiv) | =>({bql::Subtraction.left=current} '-' right=GetMulDiv))*
;

Selection:
	SelectionSelect | Unselect
;

SelectionSelect:
	{Select}
	"SELECT"
;

Unselect:
	{Unselect}
	"UNSELECT"
;

Visibility:
	Show | Hide
;

Show:
	{Show}
	"SHOW"
;

Hide:
	{Hide}
	"HIDE"
;

Sectionability:
	Sectionable | Unsectionable
;

Sectionable:
	{Sectionable}
	"SECTIONABLE"
;

Unsectionable:
	{Unsectionable}
	"UNSECTIONABLE"
;

SectionEndcaps:
	Endcaps | NoEndcaps
;

Endcaps:
	{Endcaps}
	"ENDCAPS"
;

NoEndcaps:
	{NoEndcaps}
	"NO_ENDCAPS"
;

// Registers objects as "soft occluders" for the camera-proximity fade: they dither out (and become
// pick-through) as the camera approaches, so the interior can be inspected without hiding anything.
// Deliberately argument-free — the fade distances are a viewer property (Viewer3d.setProximityFadeConfig
// / settings.proximityFade), not an object property, and "auto" derives them from the model itself.
SoftOccluding:
	SoftOccluder | NoSoftOccluder
;

SoftOccluder:
	{SoftOccluder}
	"SOFT_OCCLUDER"
;

NoSoftOccluder:
	{NoSoftOccluder}
	"NO_SOFT_OCCLUDER"
;

// Draws objects in front of everything else: they stay visible (and are picked first) when other
// objects are in front of them, while keeping their own depth order among each other. Meant for
// the subjects of a check shown in their context, e.g.
//   select (type = IFCDOOR) { ON_TOP PICKABLE; }
OnTopDrawing:
	OnTop | NotOnTop
;

OnTop:
	{OnTop}
	"ON_TOP"
;

NotOnTop:
	{NotOnTop}
	"NOT_ON_TOP"
;

Pickability:
	Pickable | Unpickable
;

Pickable:
	{Pickable}
	"PICKABLE"
;

Unpickable:
	{Unpickable}
	"UNPICKABLE"
;

// Overrides apply to object edges; RESET restores the viewer defaults.
WireframeVisibility:
	{WireframeVisibility} "WIREFRAME" mode=WireframeVisibilityMode
;

enum WireframeVisibilityMode:
	SHOW="SHOW" | HIDE="HIDE" | RESET="RESET"
;

WireframeColor:
	{WireframeColor} "WIREFRAME" "COLOR" (reset?="RESET" | color=STRING (transparency=LONG "%")?)
;

// A duration: 500ms, 2s (TRANSITION, VIEWFIT). A terminal, so "ms" and "s" stay free as identifiers
terminal DURATION: ('0'..'9')+ ('ms' | 's');

```
