1--[[**************************************************************************** 2* * 3* EBNF2 Syntax Definition * 4* * 5* v1.0.1 (2018/01/18) | Highlight v3.41 | Lua 5.3 * 6* * 7* by Tristano Ajmone * 8* * 9******************************************************************************** 10Associated file extensions: none 11Syntax type: EBNF (Extended Backus–Naur form) 12-------------------------------------------------------------------------------- 13I've created this EBNF syntax definition because I needed to syntax highlight 14the EBNF code of Polygen Manual, which wasn't being handled properly by the 15existing Highlight *BNF definitions ("ebnf", "abnf", and "bnf"). So I decided 16to create my own EBNF syntax by adapting the Polygen Grammars syntax I had 17just recently created. Some tweaks were required to make it parse properly 18the EBNF code found in the Polygen Manual (see changelog, at the end). 19 20Hopefully others might benefit from this new EBNF syntax too. Since there is 21no universal standard for EBNF notation (EBNF being a family of notations), 22this definition might be used as a starting point to tailor an ad hoc EBNF 23syntax matching your needs. 24-------------------------------------------------------------------------------- 25Written by Tristano Ajmone: 26 <tajmone@gmail.com> 27 https://github.com/tajmone 28Released into the public domain according to the Unlicense terms: 29 http://unlicense.org/ 30-------------------------------------------------------------------------------- 31--]] 32Description="EBNF2" 33 34Categories = {"protocol"} 35 36IgnoreCase=false 37EnableIndentation=false 38-------------------------------------------------------------------------------- 39-- DISABLE/OVERRIDE UNUSED SYNTAX ELEMENTS 40-------------------------------------------------------------------------------- 41NEVER_MATCH_RE=[=[ \A(?!x)x ]=] -- A Never-Matching RegEx! 42 43Digits=NEVER_MATCH_RE -- Numbers are just text in EBNF! 44 45Identifiers=NEVER_MATCH_RE -- Highlight's default Identifiers RegEx prevents 46-- capturing the Epsilon operator ('_'). Since in this syntax, all identifiers 47-- are defined as RegEx Keywords, and because we don't use any Keywords lists, 48-- we may as well disable Identifiers by defining them as a never-matching RegEx. 49-- NOTE: Defining Identifiers as a never-matching RegEx prevents using Kewyords 50-- lists (the parser will fail to capture them). 51 52-- ============================================================================= 53-- COMMENTS 54-- ============================================================================= 55-- OCaml style comments, no nesting: (* ...COMMENT BLOCK... *) 56Comments={ 57 { Block=true, 58 Nested=false, 59 Delimiter = { 60 [=[ \(\* ]=], -- Comment start: '(*' 61 [=[ \*\) ]=] -- Comment end: '*)' 62 } 63 }, 64} 65-- ============================================================================= 66-- STRINGS 67-- ============================================================================= 68Strings={ 69 ------------------------------------------------------------------------------ 70 -- STRING DELIMITERS 71 ------------------------------------------------------------------------------ 72 -- Only double quotes as string delimiter: "...STRING..." 73 Delimiter=[=[ " ]=], 74--[[---------------------------------------------------------------------------- 75 ESCAPE SEQUENCES 76 ---------------------------------------------------------------------------- 77 Suppress Escape sequences via Never-Matching RegEx --]] 78 Escape=NEVER_MATCH_RE 79} 80--[[============================================================================ 81 OPERATORS 82 ============================================================================ 83 ::= := : ; ^ . , _ | + - * > < \ 84 >> << ( ) [ ] { } 85 86--]] 87Operators=[=[ :|=|\^|\.|\*|\+|-|>|<|\(|\)|\[|]|\{|}|\||,|;|_|\\ ]=] 88-- ============================================================================= 89-- KEYWORDS 90-- ============================================================================= 91Keywords={ 92 ------------------------------------------------------------------------------ 93 -- Non-Terminal Symbol 94 ------------------------------------------------------------------------------ 95 -- Must beging with a capital letter; must not be preceded or followed by a "-" 96 -- (to prevent capturing RegEx ranges like "A-Z" ) 97 { Id=1, 98 Regex=[=[ (?<!-)([A-Z][A-Za-z0-9]*)\b(?!-) ]=], 99 Group=1 100 }, 101} 102--[[============================================================================ 103 CHANGELOG 104================================================================================ 105v1.0.1 (2018/01/18) | Highlight v3.41) 106 - Changed "PolyGen" to "Polygen" (the author has now officially adopted the 107 latter syntax). 108v1.0.0 (2018/01/14) | Highlight v3.41) 109 - First release. Created by modifying "polygen.lang" (v1.0.0): 110 - Suppressed Escape Sequences (via Never-Matching RegEx) 111 - Deleted custom OnStateChange() hook function to handle Escape Sequences. 112 - Operators: added "*", and tweaked RegEx. 113 - Keywords: 114 - Removed Keywords Group 2 ("Label Identifier") 115 - Removed Keywords Group 3 ( "Label Selector") 116 - Keywords Group 1 ("Non-Terminal Symbol"): tweaked RegEx to ensure that 117 keyword is not preceded or followed by "-", to avoid capturing RegEx 118 ranges like "A-Z" in EBNF source. 119--]] 120