updated grammar.txt

This commit is contained in:
Araq 2014-01-20 08:35:09 +01:00
commit d18f40b4e2
3 changed files with 22 additions and 20 deletions

View file

@ -18,10 +18,10 @@
# In fact the grammar is generated from this file: # In fact the grammar is generated from this file:
when isMainModule: when isMainModule:
import pegs import pegs
var outp = open("compiler/grammar.txt", fmWrite) var outp = open("doc/grammar.txt", fmWrite)
for line in lines("compiler/parser.nim"): for line in lines("compiler/parser.nim"):
if line =~ peg" \s* '#| ' {.*}": if line =~ peg" \s* '#| ' {.*}":
outp.writeln matches[0] outp.write matches[0], "\L"
outp.close outp.close
import import

View file

@ -42,14 +42,14 @@ par = '(' optInd (&parKeyw complexOrSimpleStmt ^+ ';'
| simpleExpr ('=' expr (';' complexOrSimpleStmt ^+ ';' )? )? | simpleExpr ('=' expr (';' complexOrSimpleStmt ^+ ';' )? )?
| (':' expr)? (',' (exprColonEqExpr comma?)*)? )? | (':' expr)? (',' (exprColonEqExpr comma?)*)? )?
optPar ')' optPar ')'
generalizedLit = GENERALIZED_STR_LIT | GENERALIZED_TRIPLESTR_LIT literal = | INT_LIT | INT8_LIT | INT16_LIT | INT32_LIT | INT64_LIT
identOrLiteral = generalizedLit | symbol
| INT_LIT | INT8_LIT | INT16_LIT | INT32_LIT | INT64_LIT
| UINT_LIT | UINT8_LIT | UINT16_LIT | UINT32_LIT | UINT64_LIT | UINT_LIT | UINT8_LIT | UINT16_LIT | UINT32_LIT | UINT64_LIT
| FLOAT_LIT | FLOAT32_LIT | FLOAT64_LIT | FLOAT_LIT | FLOAT32_LIT | FLOAT64_LIT
| STR_LIT | RSTR_LIT | TRIPLESTR_LIT | STR_LIT | RSTR_LIT | TRIPLESTR_LIT
| CHAR_LIT | CHAR_LIT
| NIL | NIL
generalizedLit = GENERALIZED_STR_LIT | GENERALIZED_TRIPLESTR_LIT
identOrLiteral = generalizedLit | symbol | literal
| par | arrayConstr | setOrTableConstr | par | arrayConstr | setOrTableConstr
| castExpr | castExpr
tupleConstr = '(' optInd (exprColonEqExpr comma?)* optPar ')' tupleConstr = '(' optInd (exprColonEqExpr comma?)* optPar ')'
@ -59,6 +59,8 @@ primarySuffix = '(' (exprColonEqExpr comma?)* ')' doBlocks?
| '.' optInd ('type' | 'addr' | symbol) generalizedLit? | '.' optInd ('type' | 'addr' | symbol) generalizedLit?
| '[' optInd indexExprList optPar ']' | '[' optInd indexExprList optPar ']'
| '{' optInd indexExprList optPar '}' | '{' optInd indexExprList optPar '}'
| &( '`'|IDENT|literal|'cast') expr ^+ ',' # command syntax
(doBlock | macroColon)?
condExpr = expr colcom expr optInd condExpr = expr colcom expr optInd
('elif' expr colcom expr optInd)* ('elif' expr colcom expr optInd)*
'else' colcom expr 'else' colcom expr
@ -95,18 +97,18 @@ primary = typeKeyw typeDescK
/ 'bind' primary / 'bind' primary
typeDesc = simpleExpr typeDesc = simpleExpr
typeDefAux = simpleExpr typeDefAux = simpleExpr
macroColon = ':' stmt? ( IND{=} 'of' exprList ':' stmt
| IND{=} 'elif' expr ':' stmt
| IND{=} 'except' exprList ':' stmt
| IND{=} 'else' ':' stmt )*
exprStmt = simpleExpr exprStmt = simpleExpr
(( '=' optInd expr ) (( '=' optInd expr )
/ ( expr ^+ comma / ( expr ^+ comma
doBlocks doBlocks
/ ':' stmt? ( IND{=} 'of' exprList ':' stmt / macroColon
| IND{=} 'elif' expr ':' stmt
| IND{=} 'except' exprList ':' stmt
| IND{=} 'else' ':' stmt )*
))? ))?
moduleName = expr ('as' expr)? importStmt = 'import' optInd expr
importStmt = 'import' optInd moduleName ((comma expr)*
((comma moduleName)*
/ 'except' optInd (expr ^+ comma)) / 'except' optInd (expr ^+ comma))
includeStmt = 'include' optInd expr ^+ comma includeStmt = 'include' optInd expr ^+ comma
fromStmt = 'from' moduleName 'import' optInd expr (comma expr)* fromStmt = 'from' moduleName 'import' optInd expr (comma expr)*

View file

@ -306,7 +306,7 @@ proc backrefIgnoreStyle*(index: range[1..MaxSubPatterns]): TPeg {.
proc spaceCost(n: TPeg): int = proc spaceCost(n: TPeg): int =
case n.kind case n.kind
of pkEmpty: nil of pkEmpty: discard
of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle, pkChar, of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle, pkChar,
pkGreedyRepChar, pkCharChoice, pkGreedyRepSet, pkGreedyRepChar, pkCharChoice, pkGreedyRepSet,
pkAny..pkWhitespace, pkGreedyAny: pkAny..pkWhitespace, pkGreedyAny:
@ -1117,7 +1117,7 @@ proc handleHexChar(c: var TPegLexer, xi: var int) =
of 'A'..'F': of 'A'..'F':
xi = (xi shl 4) or (ord(c.buf[c.bufpos]) - ord('A') + 10) xi = (xi shl 4) or (ord(c.buf[c.bufpos]) - ord('A') + 10)
inc(c.bufpos) inc(c.bufpos)
else: nil else: discard
proc getEscapedChar(c: var TPegLexer, tok: var TToken) = proc getEscapedChar(c: var TPegLexer, tok: var TToken) =
inc(c.bufpos) inc(c.bufpos)
@ -1347,7 +1347,7 @@ proc getTok(c: var TPegLexer, tok: var TToken) =
of "i": tok.modifier = modIgnoreCase of "i": tok.modifier = modIgnoreCase
of "y": tok.modifier = modIgnoreStyle of "y": tok.modifier = modIgnoreStyle
of "v": tok.modifier = modVerbatim of "v": tok.modifier = modVerbatim
else: nil else: discard
setLen(tok.literal, 0) setLen(tok.literal, 0)
if c.buf[c.bufpos] == '$': if c.buf[c.bufpos] == '$':
getDollar(c, tok) getDollar(c, tok)
@ -1494,7 +1494,7 @@ proc primary(p: var TPegParser): TPeg =
of tkCurlyAt: of tkCurlyAt:
getTok(p) getTok(p)
return !*\primary(p).token(p) return !*\primary(p).token(p)
else: nil else: discard
case p.tok.kind case p.tok.kind
of tkIdentifier: of tkIdentifier:
if p.identIsVerbatim: if p.identIsVerbatim: