Skip to content

BCSL Syntax validator

Matej Troják edited this page May 1, 2020 · 5 revisions

The BCSL syntax validator is available online on BioDivine server through an API on URL: https://biodivine-vm.fi.muni.cz/BCSLparser/. There are two available endpoints: ping and parse.


ping

Used to check whether the BCSL syntax validator is running.

End point: ping
Request type: GET
Response: returns JSON containing {'online': True} if the parser is running.

parse

Used to validate syntax of given expression in BCSL. It is possible to specify starting point of Grammar, which enables to validate variety of objects such as model, rule, complex agents etc.

End point: parse
Request type: POST

    data: 'start': string,  // starting point in the grammar; determines what kind of objects is passed in expression
          'expression': string  // the expression to be parsed

Response: returns JSON containing of form:

    'success': bool,

if the success is true, the provided expression is correct
otherwise, expression contains an error defined in JSON by additional attributes:

    'line': int  // vertical position of error token
    'column': int  // horizontal position of error token
    'expected': set  // set of possibly correct token on this position
    'unexpected': string  // unexpected token

Example of usage in Python:

>>> import requests, json
>>> url = 'http://biodivine-vm.fi.muni.cz/BCSLparser/'
>>> headers = {'content-type': 'application/json'}
>>> rule = 'X(T{a}):XX::rep => X(T{o}):XX::rep @ k2*[X().X()::rep]'
>>> response = requests.post(url + 'parse', data=json.dumps({'start': 'rule', 'expression': rule}), headers=headers)
>>> print(response.json())
{'success': True}
>>> rule = 'X(T{a}:XX::rep => X(T{o}):XX::rep @ k2*[X().X()::rep]'
>>> response = requests.post(url + 'parse', data=json.dumps({'start': 'rule', 'expression': rule}), headers=headers)
>>> print(response.json())
{'expected': [')', ','], 'column': 7, 'line': 1, 'unexpected': ':', 'success': False}