@@grammar::BEL
@@parseinfo :: True

##############
#  METADATA  #
##############

# BEL VERSION: 2.0.0
# EBNF CREATION TIMESTAMP: March 25, 2018 - 09:00:18AM

#########################
#  GRAMMAR DEFINITIONS  #
#########################

start = bel_statement $ ;
bel_statement = subject:function ~ [relation:relation ~ object:obj] ;

obj = (function | enclosed_statement) ;
enclosed_statement = function_open bel_statement:bel_statement function_close ;

##### FUNCTIONS #####

function = function:funcs function_open function_args:f_args function_close ;
funcs =
    'cellSurfaceExpression' | 'compositeAbundance' | 'biologicalProcess' | 'microRNAAbundance' | 'complexAbundance' | 'proteinAbundance' | 'cellSecretion' | 'geneAbundance' | 'translocation' | 'rnaAbundance' | 'degradation' | 'abundance' | 'composite' | 'pathology' | 'activity' | 'reaction' | 'complex' | 'list' | 'list' | 'path' | 'surf' | 'tloc' | 'act' | 'deg' | 'rxn' | 'sec' | 'bp' | 'a' | 'g' | 'm' | 'p' | 'r' ;

f_args = ','.{(function | modifier_function | namespace_arg | string_arg)}* ;

##### MODIFIER FUNCTIONS #####

modifier_function = modifier:m_funcs function_open modifier_args:m_args function_close ;
m_funcs =
    'proteinModification' | 'molecularActivity' | 'reactants' | 'reactants' | 'fragment' | 'location' | 'products' | 'products' | 'fromLoc' | 'fromLoc' | 'variant' | 'fusion' | 'toLoc' | 'toLoc' | 'frag' | 'pmod' | 'fus' | 'loc' | 'var' | 'ma' ;

m_args = ','.{(function | namespace_arg | string_arg)}* ;

##### RELATIONSHIPS #####

relation = relations ;
relations =
    'prognosticBiomarkerFor' | 'prognosticBiomarkerFor' | 'negativeCorrelation' | 'positiveCorrelation' | 'rateLimitingStepOf' | 'rateLimitingStepOf' | 'directlyDecreases' | 'directlyIncreases' | 'causesNoChange' | 'hasComponents' | 'hasComponents' | 'transcribedTo' | 'biomarkerFor' | 'biomarkerFor' | 'hasComponent' | 'hasComponent' | 'subProcessOf' | 'subProcessOf' | 'translatedTo' | 'association' | 'orthologous' | 'orthologous' | 'hasMembers' | 'hasMembers' | 'analogous' | 'analogous' | 'decreases' | 'hasMember' | 'hasMember' | 'increases' | 'regulates' | 'cnc' | 'isA' | 'isA' | 'neg' | 'pos' | 'reg' | '--' | '-|' | '=|' | '=>' | '->' | ':>' | '>>' ;

##### MISCELLANEOUS #####

namespace_arg = ns_arg:full_nsv ;
full_nsv = ns:ns_string ':' ns_value:(quoted_string | string) ;

string_arg = str_arg:full_string ;
full_string = (quoted_string | string) ;



# quoted_string: Matches like any string but requires it to be in quotation marks.
quoted_string = /\"(?:[^"\\]|\\.)*\"/ ;

# string: Matches any char other than space, comma or ')'
string = /[^\s\),]+/ ;

# ns_string: Matches any capital letter or digit.
ns_string = /[A-Z0-9]+/ ;

function_open = '(' ;
function_close = ')' ;