attic: ebnf/ moved to attic/ebnf
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Package ebmf implements an ISO/IEC 14977
|
||||
Extended Backus–Naur Form parser, verifiers,
|
||||
and additional related helpers for AsciiGoat
|
||||
|
||||
A syntax highlighter for vim and a copy of the final draft of the standard
|
||||
are included in the doc/ directory. The official standard can be downloaded from
|
||||
http://standards.iso.org/ittf/PubliclyAvailableStandards/s026153_ISO_IEC_14977_1996(E).zip
|
||||
|
||||
An uberly simplified version of the EBNF grammar looks like:
|
||||
|
||||
letter = "A" | "B" | "C" | "D" | "E" | "F" | "G"
|
||||
| "H" | "I" | "J" | "K" | "L" | "M" | "N"
|
||||
| "O" | "P" | "Q" | "R" | "S" | "T" | "U"
|
||||
| "V" | "W" | "X" | "Y" | "Z" ;
|
||||
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
|
||||
symbol = "[" | "]" | "{" | "}" | "(" | ")" | "<" | ">"
|
||||
| "'" | '"' | "=" | "|" | "." | "," | ";" ;
|
||||
character = letter | digit | symbol | "_" ;
|
||||
|
||||
identifier = letter , { letter | digit | "_" } ;
|
||||
terminal = "'" , character , { character } , "'"
|
||||
| '"' , character , { character } , '"' ;
|
||||
|
||||
lhs = identifier ;
|
||||
rhs = identifier
|
||||
| terminal
|
||||
| "[" , rhs , "]"
|
||||
| "{" , rhs , "}"
|
||||
| "(" , rhs , ")"
|
||||
| rhs , "|" , rhs
|
||||
| rhs , "," , rhs ;
|
||||
|
||||
rule = lhs , "=" , rhs , ";" ;
|
||||
grammar = { rule } ;
|
||||
*/
|
||||
package ebnf
|
||||
@@ -0,0 +1,36 @@
|
||||
" Vim syntax file
|
||||
" Language: EBNF
|
||||
" Maintainer: Hans Fugal
|
||||
" Last Change: $Date: 2003/01/28 14:42:09 $
|
||||
" Version: $Id: ebnf.vim,v 1.1 2003/01/28 14:42:09 fugalh Exp $
|
||||
" With thanks to Michael Brailsford for the BNF syntax file.
|
||||
|
||||
" Quit when a syntax file was already loaded
|
||||
if version < 600
|
||||
syntax clear
|
||||
elseif exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
syn match ebnfMetaIdentifier /[A-Za-z]/ skipwhite skipempty nextgroup=ebnfSeperator
|
||||
|
||||
syn match ebnfSeperator "=" contained nextgroup=ebnfProduction skipwhite skipempty
|
||||
|
||||
syn region ebnfProduction start=/\zs[^\.;]/ end=/[\.;]/me=e-1 contained contains=ebnfSpecial,ebnfDelimiter,ebnfTerminal,ebnfSpecialSequence,ebnfComment nextgroup=ebnfEndProduction skipwhite skipempty
|
||||
syn match ebnfDelimiter #[,(|)\]}\[{/!]\|\(\*)\)\|\((\*\)\|\(/)\)\|\(:)\)\|\((/\)\|\((:\)# contained
|
||||
syn match ebnfSpecial /[\-\*]/ contained
|
||||
syn region ebnfSpecialSequence matchgroup=Delimiter start=/?/ end=/?/ contained
|
||||
syn match ebnfEndProduction /[\.;]/ contained
|
||||
syn region ebnfTerminal matchgroup=delimiter start=/"/ end=/"/ contained
|
||||
syn region ebnfTerminal matchgroup=delimiter start=/'/ end=/'/ contained
|
||||
syn region ebnfComment start="(\*" end="\*)"
|
||||
|
||||
|
||||
hi link ebnfComment Comment
|
||||
hi link ebnfMetaIdentifier Identifier
|
||||
hi link ebnfSeperator ebnfSpecial
|
||||
hi link ebnfEndProduction ebnfDelimiter
|
||||
hi link ebnfDelimiter Delimiter
|
||||
hi link ebnfSpecial Special
|
||||
hi link ebnfSpecialSequence Statement
|
||||
hi link ebnfTerminal Constant
|
||||
Binary file not shown.
@@ -0,0 +1,230 @@
|
||||
(* vim: set ft=ebnf: *)
|
||||
|
||||
(*
|
||||
The syntax of Extended BNF can be defined using
|
||||
itself. There are four parts in this example,
|
||||
the first part names the characters, the second
|
||||
part defines the removal of unnecessary non-
|
||||
printing characters, the third part defines the
|
||||
removal of textual comments, and the final part
|
||||
defines the structure of Extended BNF itself.
|
||||
|
||||
Each syntax rule in this example starts with a
|
||||
comment that identifies the corresponding clause
|
||||
in the standard.
|
||||
|
||||
The meaning of special-sequences is not defined
|
||||
in the standard. In this example (see the
|
||||
reference to 7.6) they represent control
|
||||
functions defined by ISO/IEC 6429:1992.
|
||||
Another special-sequence defines a
|
||||
syntactic-exception (see the reference to 4.7).
|
||||
*)
|
||||
|
||||
(*
|
||||
The first part of the lexical syntax defines the
|
||||
characters in the 7-bit character set (ISO/IEC
|
||||
646:1991) that represent each terminal-character
|
||||
and gap-separator in Extended BNF.
|
||||
*)
|
||||
|
||||
(* see 7.2 *) letter
|
||||
= 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h'
|
||||
| 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p'
|
||||
| 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x'
|
||||
| 'y' | 'z'
|
||||
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H'
|
||||
| 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P'
|
||||
| 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X'
|
||||
| 'Y' | 'Z';
|
||||
(* see 7.2 *) decimal digit
|
||||
= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7'
|
||||
| '8' | '9';
|
||||
|
||||
(*
|
||||
The representation of the following
|
||||
terminal-characters is defined in clauses 7.3,
|
||||
7.4 and tables 1, 2.
|
||||
*)
|
||||
|
||||
concatenate symbol = ',';
|
||||
defining symbol = '=';
|
||||
definition separator symbol = '|' | '/' | '!';
|
||||
end comment symbol = '*)';
|
||||
end group symbol = ')';
|
||||
end option symbol = ']' | '/)';
|
||||
end repeat symbol = '}' | ':)';
|
||||
except symbol = '-';
|
||||
first quote symbol = "'";
|
||||
repetition symbol = '*';
|
||||
second quote symbol = '"';
|
||||
special sequence symbol = '?';
|
||||
start comment symbol = '(*';
|
||||
start group symbol = '(';
|
||||
start option symbol = '[' | '(/';
|
||||
start repeat symbol = '{' | '(:';
|
||||
terminator symbol = ';' | '.';
|
||||
(* see 7.5 *) other character
|
||||
= ' ' | ':' | '+' | '_' | '%' | 'Q'
|
||||
| '&' | '#' | '$' | '<' | '>' | '\'
|
||||
| 'ˆ' | '‘' | ' ̃';
|
||||
(* see 7.6 *) space character = ' ';
|
||||
horizontal tabulation character
|
||||
= ? ISO 6429 character Horizontal Tabulation ? ;
|
||||
new line
|
||||
= { ? ISO 6429 character Carriage Return ? },
|
||||
? ISO 6429 character Line Feed ?,
|
||||
{ ? ISO 6429 character Carriage Return ? };
|
||||
vertical tabulation character
|
||||
= ? ISO 6429 character Vertical Tabulation ? ;
|
||||
form feed
|
||||
= ? ISO 6429 character Form Feed ? ;
|
||||
|
||||
(*
|
||||
The second part of the syntax defines the
|
||||
removal of unnecessary non-printing characters
|
||||
from a syntax.
|
||||
*)
|
||||
|
||||
(* see 6.2 *) terminal character
|
||||
= letter
|
||||
| decimal digit
|
||||
| concatenate symbol
|
||||
| defining symbol
|
||||
| definition separator symbol
|
||||
| end comment symbol
|
||||
| end group symbol
|
||||
| end option symbol
|
||||
| end repeat symbol
|
||||
| except symbol
|
||||
| first quote symbol
|
||||
| repetition symbol
|
||||
| second quote symbol
|
||||
| special sequence symbol
|
||||
| start comment symbol
|
||||
| start group symbol
|
||||
| start option symbol
|
||||
| start repeat symbol
|
||||
| terminator symbol
|
||||
| other character;
|
||||
(* see 6.3 *) gap free symbol
|
||||
= terminal character
|
||||
- (first quote symbol | second quote symbol)
|
||||
| terminal string;
|
||||
(* see 4.16 *) terminal string
|
||||
= first quote symbol, first terminal character,
|
||||
{first terminal character},
|
||||
first quote symbol
|
||||
| second quote symbol, second terminal character,
|
||||
{second terminal character},
|
||||
second quote symbol;
|
||||
(* see 4.17 *) first terminal character
|
||||
= terminal character - first quote symbol;
|
||||
(* see 4.18 *) second terminal character
|
||||
= terminal character - second quote symbol;
|
||||
(* see 6.4 *) gap separator
|
||||
= space character
|
||||
| horizontal tabulation character
|
||||
| new line
|
||||
| vertical tabulation character
|
||||
| form feed;
|
||||
(* see 6.5 *) syntax
|
||||
= {gap separator},
|
||||
gap free symbol, {gap separator},
|
||||
{gap free symbol, {gap separator}};
|
||||
|
||||
(*
|
||||
The third part of the syntax defines the
|
||||
removal of bracketed-textual-comments from
|
||||
gap-free-symbols that form a syntax.
|
||||
*)
|
||||
|
||||
(* see 6.6 *) commentless symbol
|
||||
= terminal character
|
||||
- (letter
|
||||
| decimal digit
|
||||
| first quote symbol
|
||||
| second quote symbol
|
||||
| start comment symbol
|
||||
| end comment symbol
|
||||
| special sequence symbol
|
||||
| other character)
|
||||
| meta identifier
|
||||
| integer
|
||||
| terminal string
|
||||
| special sequence;
|
||||
(* see 4.9 *) integer
|
||||
= decimal digit, {decimal digit};
|
||||
(* see 4.14 *) meta identifier
|
||||
= letter, {meta identifier character};
|
||||
(* see 4.15 *) meta identifier character
|
||||
= letter
|
||||
| decimal digit;
|
||||
(* see 4.19 *) special sequence
|
||||
= special sequence symbol,
|
||||
{special sequence character},
|
||||
special sequence symbol;
|
||||
(* see 4.20 *) special sequence character
|
||||
= terminal character - special sequence symbol;
|
||||
(* see 6.7 *) comment symbol
|
||||
= bracketed textual comment
|
||||
| other character
|
||||
| commentless symbol;
|
||||
(* see 6.8 *) bracketed textual comment
|
||||
= start comment symbol, {comment symbol},
|
||||
end comment symbol;
|
||||
(* see 6.9 *) syntax
|
||||
= {bracketed textual comment},
|
||||
commentless symbol,
|
||||
{bracketed textual comment},
|
||||
{commentless symbol,
|
||||
{bracketed textual comment}};
|
||||
|
||||
(*
|
||||
The final part of the syntax defines the
|
||||
abstract syntax of Extended BNF, i.e. the
|
||||
structure in terms of the commentless symbols.
|
||||
*)
|
||||
|
||||
(* see 4.2 *) syntax
|
||||
= syntax rule, {syntax rule};
|
||||
(* see 4.3 *) syntax rule
|
||||
= meta identifier, defining symbol,
|
||||
definitions list, terminator symbol;
|
||||
(* see 4.4 *) definitions list
|
||||
= single definition,
|
||||
{definition separator symbol,
|
||||
single definition};
|
||||
(* see 4.5 *) single definition
|
||||
= syntactic term,
|
||||
{concatenate symbol, syntactic term};
|
||||
(* see 4.6 *) syntactic term
|
||||
= syntactic factor,
|
||||
[except symbol, syntactic exception];
|
||||
(* see 4.7 *) syntactic exception
|
||||
= ? a syntactic-factor that could be replaced
|
||||
by a syntactic-factor containing no
|
||||
meta-identifiers
|
||||
? ;
|
||||
(* see 4.8 *) syntactic factor
|
||||
= [integer, repetition symbol],
|
||||
syntactic primary;
|
||||
(* see 4.10 *) syntactic primary
|
||||
= optional sequence
|
||||
| repeated sequence
|
||||
| grouped sequence
|
||||
| meta identifier
|
||||
| terminal string
|
||||
| special sequence
|
||||
| empty sequence;
|
||||
(* see 4.11 *) optional sequence
|
||||
= start option symbol, definitions list,
|
||||
end option symbol;
|
||||
(* see 4.12 *) repeated sequence
|
||||
= start repeat symbol, definitions list,
|
||||
end repeat symbol;
|
||||
(* see 4.13 *) grouped sequence
|
||||
= start group symbol, definitions list,
|
||||
end group symbol;
|
||||
(* see 4.21 *) empty sequence
|
||||
= ;
|
||||
@@ -0,0 +1 @@
|
||||
package ebnf
|
||||
@@ -0,0 +1,20 @@
|
||||
package token
|
||||
|
||||
// types of Token
|
||||
type TokenType int
|
||||
|
||||
const (
|
||||
TokenError TokenType = iota + 1
|
||||
TokenEOF
|
||||
)
|
||||
|
||||
func (typ TokenType) String() string {
|
||||
switch typ {
|
||||
case TokenError:
|
||||
return "ERROR"
|
||||
case TokenEOF:
|
||||
return "EOF"
|
||||
default:
|
||||
return "UNDEFINED"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package token
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTokenTypeToString(t *testing.T) {
|
||||
var foo TokenType
|
||||
|
||||
for _, o := range []struct {
|
||||
typ TokenType
|
||||
str string
|
||||
}{
|
||||
{foo, "UNDEFINED"},
|
||||
{TokenError, "ERROR"},
|
||||
{TokenEOF, "EOF"},
|
||||
{1234, "UNDEFINED"},
|
||||
} {
|
||||
str := fmt.Sprintf("%s", o.typ)
|
||||
if str != o.str {
|
||||
t.Errorf("TokenType:%v stringified as %s instead of %s.", int(o.typ), str, o.str)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user