"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/host-go/rlhc-go.lm" between
ragel-7.0.0.11.tar.gz and ragel-7.0.0.12.tar.gz

About: Ragel compiles executable finite state machines from regular languages (C, C++, Obj-C, C#, D, Java, Go and Ruby). Development version.

rlhc-go.lm  (ragel-7.0.0.11):rlhc-go.lm  (ragel-7.0.0.12)
skipping to change at line 51 skipping to change at line 51
| [symbol] | [symbol]
| [string] | [string]
| [`{ _IN_ item* _EX_ `} ] | [`{ _IN_ item* _EX_ `} ]
def go_out def go_out
[_IN_ _EX_ item*] [_IN_ _EX_ item*]
end end
namespace go_gen namespace go_gen
global Parser: parser<go_out::go_out> global _: parser<go_out::go_out>
void tok_list( TL: host::tok* ) void tok_list( TL: host::tok* )
{ {
for Tok: host::tok in repeat(TL) { for Tok: host::tok in repeat(TL) {
switch Tok switch Tok
case [host::`${ StmtList: stmt* host::`}$] case Stmt {
send Parser "{[stmt_list( StmtList )]}" "{[stmt_list( StmtList )]}"
case [host::`={ Expr: expr host::`}=] }
send Parser "([expr( Expr )])" case Expr {
case [E: escape] { "([expr( Expr )])"
Str: str = $E }
send Parser case Escape {
"[Str.suffix( 1 )]" Str: str = $Tok
"[Str.suffix( 1 )]"
}
default {
[Tok]
} }
default
send Parser [Tok]
} }
} }
void embedded_host( EmbeddedHost: embedded_host ) void embedded_host( EmbeddedHost: embedded_host )
{ {
switch EmbeddedHost switch EmbeddedHost
case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] case Expr
{ {
send Parser ['(' tok_list( TL ) ')']
"([tok_list( TL )])"
} }
case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] case Stmt
{ {
send Parser ['{' tok_list( TL ) '}\n']
"{[tok_list( TL )]}
} }
case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] case Bare
{ {
send Parser [tok_list( TL )]
[tok_list( TL )]
} }
} }
void expr_factor( ExprFactor: expr_factor ) void expr_factor( ExprFactor: expr_factor )
{ {
switch ExprFactor switch ExprFactor
case [EH: embedded_host] case EmbeddedHost
{ {
send Parser [embedded_host(embedded_host)]
[embedded_host(EH)]
} }
case case Paren
[O:`( TL: expr C: `)]
{ {
send Parser [O] ['(' expr(expr) ')']
expr( TL )
send Parser [C]
} }
case case ArraySub
[ident O: `[ TL: expr C: `]]
{ {
send Parser [ExprFactor.ident O] [ident '[' expr( expr ) ']']
expr( TL )
send Parser [C]
} }
case case Offset
[`offset `( ident `, expr `)]
{ {
send Parser ['int('] "int([expr(expr )])
expr( ExprFactor.expr )
send Parser [')']
} }
case case Deref
['deref' '(' ident ',' expr ')']
{ {
send Parser [ ExprFactor.ident '['] [ident '[' expr( expr ) ']' ]
expr( ExprFactor.expr )
send Parser [']']
} }
case case True
[T: `TRUE]
{ {
T.data = 'true' "true"
send Parser [T]
} }
case case False
[F: `FALSE]
{ {
F.data = '0' "false"
send Parser [F]
} }
case case Nil
[N: `nil]
{ {
N.data = '0' "0"
send Parser [N]
} }
case [E1: embedded_host `-> E2: expr_factor] case Access
{ {
embedded_host( E1 ) embedded_host(embedded_host)
expr_factor( E2 ) expr_factor(_expr_factor)
} }
case [`cast '(' Type: type ')' expr_factor] case Cast
{ {
type( Type ) [type(type) '(' expr_factor(_expr_factor) ')' ]
send Parser ['(']
expr_factor( ExprFactor._expr_factor )
send Parser [')']
} }
default { default {
# Catches cases not specified # Catches cases not specified
send Parser [ExprFactor] [ExprFactor]
} }
} }
void lvalue( ExprFactor: lvalue ) void lvalue( ExprFactor: lvalue )
{ {
switch ExprFactor switch ExprFactor
case [EH: embedded_host] case [EH: embedded_host]
{ {
send Parser [embedded_host(EH)]
[embedded_host(EH)]
} }
case case [ident `[ TL: expr `]]
[ident O: `[ TL: expr C: `]]
{ {
send Parser [ExprFactor.ident O] [ident '[' expr( TL ) ']']
expr( TL )
send Parser [C]
} }
case [E1: embedded_host `-> E2: lvalue] case [E1: embedded_host `-> E2: lvalue]
{ {
embedded_host( E1 ) embedded_host( E1 )
lvalue( E2 ) lvalue( E2 )
} }
default { default {
# Catches cases not specified # Catches cases not specified
send Parser [ExprFactor] [ExprFactor]
} }
} }
void expr_factor_op( ExprFactorOp: expr_factor_op ) void expr_factor_op( ExprFactorOp: expr_factor_op )
{ {
switch ExprFactorOp switch ExprFactorOp
case [B: `! expr_factor_op] case [B: `! expr_factor_op]
{ {
send Parser [B] ['!' expr_factor_op( _expr_factor_op )]
expr_factor_op( ExprFactorOp._expr_factor_op )
} }
case [T: `~ expr_factor_op] case [T: `~ expr_factor_op]
{ {
send Parser ['^'] ['^' expr_factor_op( _expr_factor_op )]
expr_factor_op( ExprFactorOp._expr_factor_op )
} }
case [expr_factor] case [expr_factor]
{ {
expr_factor( ExprFactorOp.expr_factor ) [expr_factor( ExprFactorOp.expr_factor )]
} }
} }
void expr_bitwise( ExprBitwise: expr_bitwise ) void expr_bitwise( ExprBitwise: expr_bitwise )
{ {
switch ExprBitwise switch ExprBitwise
case [expr_bitwise A: `& expr_factor_op] case [expr_bitwise A: `& expr_factor_op]
{ {
expr_bitwise( ExprBitwise._expr_bitwise ) [expr_bitwise( _expr_bitwise ) '&' expr_factor_op( expr_f
send Parser [A] actor_op )]
expr_factor_op( ExprBitwise.expr_factor_op )
} }
case [expr_factor_op] case [expr_factor_op]
{ {
expr_factor_op( ExprBitwise.expr_factor_op ) [expr_factor_op( ExprBitwise.expr_factor_op )]
} }
} }
void expr_mult( ExprMult: expr_mult ) void expr_mult( ExprMult: expr_mult )
{ {
switch ExprMult switch ExprMult
case [expr_mult T: `* expr_bitwise] case [expr_mult T: `* expr_bitwise]
{ {
expr_mult( ExprMult._expr_mult ) [expr_mult( _expr_mult ) '*' expr_bitwise( expr_bitwise )
send Parser [T] ]
expr_bitwise( ExprMult.expr_bitwise )
} }
case [expr_bitwise] case [expr_bitwise]
{ {
expr_bitwise( ExprMult.expr_bitwise ) [expr_bitwise( expr_bitwise )]
} }
} }
void expr_add( ExprAdd: expr_add ) void expr_add( ExprAdd: expr_add )
{ {
switch ExprAdd switch ExprAdd
case [expr_add Op: add_op expr_mult] case [expr_add Op: add_op expr_mult]
{ {
expr_add( ExprAdd._expr_add ) [expr_add( _expr_add ) Op expr_mult( expr_mult )]
send Parser [Op]
expr_mult( ExprAdd.expr_mult )
} }
case [expr_mult] case [expr_mult]
{ {
expr_mult( ExprAdd.expr_mult ) [expr_mult( ExprAdd.expr_mult )]
} }
} }
void expr_shift( ExprShift: expr_shift ) void expr_shift( ExprShift: expr_shift )
{ {
switch ExprShift switch ExprShift
case [expr_shift Op: shift_op expr_add] case [expr_shift Op: shift_op expr_add]
{ {
expr_shift( ExprShift._expr_shift ) [expr_shift( _expr_shift ) Op expr_add( expr_add )]
send Parser [Op]
expr_add( ExprShift.expr_add )
} }
case [expr_add] case [expr_add]
{ {
expr_add( ExprShift.expr_add ) [expr_add( expr_add )]
} }
} }
void expr_test( ExprTest: expr_test ) void expr_test( ExprTest: expr_test )
{ {
switch ExprTest switch ExprTest
case [expr_test Op: test_op expr_shift] case [expr_test Op: test_op expr_shift]
{ {
expr_test( ExprTest._expr_test ) [expr_test( _expr_test ) Op expr_shift( expr_shift )]
send Parser [Op]
expr_shift( ExprTest.expr_shift )
} }
case [expr_shift] case [expr_shift]
{ {
expr_shift( ExprTest.expr_shift ) [expr_shift( ExprTest.expr_shift )]
} }
} }
void expr( Expr: expr ) void expr( Expr: expr )
{ {
expr_test( Expr.expr_test ) expr_test( Expr.expr_test )
} }
void type( Type: type ) void type( Type: type )
{ {
switch Type switch Type
case "s8" case S8
send Parser ['int8 '] ['int8 ']
case "s16" case S16
send Parser ['int16 '] ['int16 ']
case "s32" case S32
send Parser ['int32 '] ['int32 ']
case "s64" case S64
send Parser ['int64 '] ['int64 ']
case "s128" case S128
send Parser ['long long '] ['long long ']
default default
send Parser [Type] [Type]
} }
void number( Number: number ) void number( Number: number )
{ {
switch Number switch Number
case [`u `( uint `) ] case Unsigned
send Parser [Number.uint] [uint]
default default
send Parser [Number] [Number]
} }
void num_list( NumList: num_list ) void num_list( NumList: num_list )
{ {
number( NumList.number ) number( NumList.number )
for CommaNum: comma_num in NumList { for CommaNum: comma_num in NumList {
send Parser [', '] [', ' number( CommaNum.number )]
number( CommaNum.number )
} }
} }
void stmt( Stmt: stmt ) void stmt( Stmt: stmt )
{ {
switch Stmt switch Stmt
case [EH: embedded_host] case [EH: embedded_host]
{ {
send Parser [embedded_host(EH)]
[embedded_host(EH)]
} }
case [A: static_array] { case [A: static_array] {
send Parser "var [A.ident] = \[\] "
"var [A.ident] \[\] [type(A.type)] = \[\] " "[type(A.type)] { [num_list(A.num_list)] }
"[type(A.type)] { [num_list(A.num_list)]
}
} }
case [V: static_value] { case [V: static_value] {
send Parser "var [V.ident] [type(V.type)] = [V.number]
"var [V.ident] [type(V.type)] = [V.number] "var _ = [V.ident]
} }
case [ case [
'if' O: `( IfExpr: expr C: `) IfStmt: stmt 'if' O: `( IfExpr: expr C: `) IfStmt: stmt
] { ] {
# if-statements with only the if clause can go out as an if. # if-statements with only the if clause can go out as an if.
send Parser "if [expr(IfExpr)] {
"if [expr(IfExpr)] { " [stmt(IfStmt)]
" [stmt(IfStmt)] "}
"}
} }
case [ case [
'if' O: `( IfExpr: expr C: `) IfStmt: stmt 'if' O: `( IfExpr: expr C: `) IfStmt: stmt
ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause?
] { ] {
# If the if-statement has more than just an if clause it goes out as a switch. # If the if-statement has more than just an if clause it goes out as a switch.
send Parser "if [expr( IfExpr )] {
"switch { " [stmt( IfStmt )]
" case [expr( IfExpr )]:
" [stmt( IfStmt )]
for ElseIfClause: else_if_clause in repeat( ElseIfClauseL ist ) { for ElseIfClause: else_if_clause in repeat( ElseIfClauseL ist ) {
match ElseIfClause match ElseIfClause
['else if (' ElseIfExpr: expr ')' ElseIfS tmt: stmt] ['else if (' ElseIfExpr: expr ')' ElseIfS tmt: stmt]
send Parser "} else if [expr(ElseIfExpr)] {
"case [expr(ElseIfExpr)]: " [stmt(ElseIfStmt)]
" [stmt(ElseIfStmt)]
} }
if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) {
send Parser "} else {
"default: " [stmt(ElseStmt)]
" [stmt(ElseStmt)]
} }
send Parser
"} "}
} }
case ["while ( TRUE )" WhileStmt: stmt] { case ["while ( TRUE )" WhileStmt: stmt] {
send Parser "for {
"for { " [stmt(WhileStmt)]
" [stmt(WhileStmt)] "}
"}
} }
case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] {
send Parser "for [expr(WhileExpr)] {
"for [expr(WhileExpr)] { " [stmt(WhileStmt)]
" [stmt(WhileStmt)] "}
"}
} }
case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] {
send Parser "switch [expr(SwitchExpr)] {
"switch [expr(SwitchExpr)] { " [stmt_list(StmtList)]
" [stmt_list(StmtList)] "}
"} }
} case [ExprExpr: expr `;] {
case [ExprExpr: expr Semi: `;] { [expr(ExprExpr) ';']
send Parser }
[expr(ExprExpr) Semi] case [B: block] {
} ['{' stmt_list(B.StmtList) '}\n']
case [L: `{ TL: stmt* R: `}] {
send Parser
[L stmt_list(TL) R]
} }
case [D: declaration] case [D: declaration]
{ {
send Parser "var [D.ident] [type(D.type)]"
"var [D.ident] [type(D.type)]"
if match D.opt_init ['=' Expr: expr] { if match D.opt_init ['=' Expr: expr] {
send Parser " = [expr(Expr)]"
" = [expr(Expr)]"
} }
send Parser ['\n'] ['\n']
} }
case [export_stmt] case [ES: export_stmt]
{ {
send Parser "#define [ES.ident] [number(ES.number)]
"#define [Stmt.export_stmt.ident] [number(Stmt.e
xport_stmt.number)]
} }
case ['fallthrough' ';'] case [fallthrough]
{ {
send Parser "fallthrough
"fallthrough
} }
case [Index: index_stmt] case [Index: index_stmt]
{ {
send Parser "var [Index.ident] int"
"var [Index.ident] int"
if match Index.opt_init ['=' Expr: expr] { if match Index.opt_init ['=' Expr: expr] {
send Parser " = [expr(Expr)]"
" = [expr(Expr)]"
} }
send Parser ['\n'] ['\n']
}
case [case_block]
{
send Parser
"case [expr( Stmt.case_block.expr )]:
"[stmt_list( Stmt.case_block._repeat_stmt )]
"break;
} }
case [default_block] case [CB: case_block]
{ {
send Parser "case [expr( CB.expr )]:
"default: "[stmt_list( CB._repeat_stmt )]
"[stmt_list( Stmt.default_block._repeat_stmt )]
"break;
} }
case [case_label] case [DB: default_block]
{ {
send Parser "default:
"case [expr( Stmt.case_label.expr )]: "[stmt_list( DB._repeat_stmt )]
} }
case [label_stmt] case [CL: case_label]
{ {
send Parser "case [expr( CL.expr )]:
"[Stmt.label_stmt.ident]:
"[stmt_list( Stmt.label_stmt._repeat_stmt )]
}
case [entry_loop]
{
send Parser
[stmt_list( Stmt.entry_loop._repeat_stmt )]
} }
case [AS: assign_stmt] case [AS: assign_stmt]
{ {
send Parser "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)];
"[lvalue(AS.LValue) AS.assign_op expr(AS.expr)];
} }
default { default {
# catches unspecified cases # catches unspecified cases
send Parser [Stmt] [Stmt]
} }
} }
void stmt_list( StmtList: stmt* ) void stmt_list( StmtList: stmt* )
{ {
for Stmt: stmt in repeat( StmtList ) for Stmt: stmt in repeat( StmtList )
stmt( Stmt ) stmt( Stmt )
} }
void trans( Output: stream, Start: start ) void trans( Output: stream, Start: start )
{ {
Parser = new parser<go_out::go_out>() _ = new parser<go_out::go_out>()
stmt_list( Start._repeat_stmt ) stmt_list( Start._repeat_stmt )
GO: go_out::go_out = Parser->finish() GO: go_out::go_out = _->finish()
if GO { if GO {
send Output send Output
[GO] [GO]
} }
else { else {
send stderr send stderr
"failed to parse output: [Parser->error] "failed to parse output: [_->error]
} }
} }
end end
void trans( Output: stream, Start: start ) void trans( Output: stream, Start: start )
{ {
go_gen::trans( Output, Start ) go_gen::trans( Output, Start )
} }
include 'rlhc-main.lm' include 'rlhc-main.lm'
 End of changes. 85 change blocks. 
204 lines changed or deleted 130 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)