"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/ragel.lm" between
ragel-7.0.0.10.tar.gz and ragel-7.0.0.11.tar.gz

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

ragel.lm  (ragel-7.0.0.10):ragel.lm  (ragel-7.0.0.11)
global GblActionParams: bool = false
global GblSectionPass: bool = false
struct machine
Name: str
ActionParams: map<str, str>
end
global GblActionParams: bool = false
global GblMachineMap: map<str, machine> = new map<str, machine>() global GblMachineMap: map<str, machine> = new map<str, machine>()
global GblCurMachine: machine global GblCurMachine: machine
global GblIncludeDepth: int = 0
global GblTargetMachine: str = "" global GblTargetMachine: str = ""
global GblSearchMachine: str = "" global GblSearchMachine: str = ""
global GblWantSection: bool = false global GblWantSection: bool = false
global GblIncludeDepth: int = 0
global GblImport: bool = false global GblImport: bool = false
global GblFileName: str = ""
global GblIncludePaths: list<str> = new list<str>()
struct saved_globals
FileName: str
TargetMachine: str
SearchMachine: str
WantSection: bool
IncludeDepth: int
Import: bool
end
bool action_params_find( Machine: str, Action: str ) global GblSavedGlobals: list<saved_globals> = new list<saved_globals>()
= cc_action_params_find
bool action_params_insert( Machine: str, Action: str ) void saveGlobals()
= cc_action_params_insert {
new SG: saved_globals()
SG->FileName = GblFileName
SG->TargetMachine = GblTargetMachine
SG->SearchMachine = GblSearchMachine
SG->WantSection = GblWantSection
SG->Import = GblImport
SG->IncludeDepth = GblIncludeDepth
GblSavedGlobals->push_tail( SG )
}
void restoreGlobals()
{
SG: saved_globals = GblSavedGlobals->pop_tail()
GblFileName = SG->FileName
GblTargetMachine = SG->TargetMachine
GblSearchMachine = SG->SearchMachine
GblWantSection = SG->WantSection
GblImport = SG->Import
GblIncludeDepth = SG->IncludeDepth
}
struct include_history_item
FileName: str
SectionName: str
end
bool isDuplicateInclude( From: machine, FileName: str, SectionName: str )
{
for Item: include_history_item in From->IncludeHistory {
if Item->FileName == FileName && Item->SectionName == SectionName
{
return true
}
}
return false
}
void addIncludeItem( From: machine, FileName: str, SectionName: str )
{
new Item: include_history_item()
Item->FileName = FileName
Item->SectionName = SectionName
From->IncludeHistory->push_tail( Item )
}
struct machine
Name: str
ActionParams: map<str, str>
IncludeHistory: list<include_history_item>
end
rl ident rl ident
/( alpha | '_' ) ( alpha | digit | '_' )*/ /( alpha | '_' ) ( alpha | digit | '_' )*/
rl number rl number
/ digit+ / / digit+ /
rl hex_number rl hex_number
/ '0x' [0-9a-fA-F]+ / / '0x' [0-9a-fA-F]+ /
skipping to change at line 57 skipping to change at line 113
/ "'" ([^'\\\n] | '\\' (any | NL))* "'" / / "'" ([^'\\\n] | '\\' (any | NL))* "'" /
rl d_literal rl d_literal
/ '"' ([^"\\] | NL | '\\' (any | NL))* '"' / / '"' ([^"\\] | NL | '\\' (any | NL))* '"' /
rl host_re_literal rl host_re_literal
/ '/' ([^/\\] | NL | '\\' (any | NL))* '/' / / '/' ([^/\\] | NL | '\\' (any | NL))* '/' /
# #
# Consuming ragel defintions without parsing. Used for included sections we # Consuming ragel defintions without parsing. Used for included sections we
# don't want and import (TODO). # don't want and for import (TODO).
# #
namespace consume namespace consume
lex lex
token h_word / [a-zA-Z_][a-zA-Z0-9_]* / token h_word / [a-zA-Z_][a-zA-Z0-9_]* /
token h_open /'{'/ token h_open /'{'/
token h_close /'}'/ token h_close /'}'/
token h_number /digit+/ token h_number /digit+/
token h_hex_number /'0x' [0-9a-fA-F]+/ token h_hex_number /'0x' [0-9a-fA-F]+/
skipping to change at line 146 skipping to change at line 202
def opt_name_sep def opt_name_sep
[`::] :ColonColon [`::] :ColonColon
| [] :Empty | [] :Empty
# List of names separated by :: # List of names separated by ::
def state_ref_names def state_ref_names
[state_ref_names `:: word] :Rec [state_ref_names `:: word] :Rec
| [word] :Base | [word] :Base
end end
namespace inline
def inline_expr
[expr_item_list] :List
def expr_item_list
[expr_item_list expr_item] :Rec
| [] :Empty
def expr_item
[expr_any] :ExprAny
| [expr_symbol] :ExprSymbol
| [expr_interpret] :ExprInterpret
def expr_any
[whitespace] :WS
| [comment] :Comment
| [string] :String
| [number] :Number
| [hex_number] :Hex
| [ident] :Ident
| [c_any] :Any
def expr_symbol
[`,] :Comma | [`(] :Open | [`)] :Close | [`*] :Star | [`::] :Doub
leColon
def expr_interpret
[`fpc] :Fpc
| [`fc] :Fc
| [`fcurs] :Fcurs
| [`ftargs] :Ftargs
| [`fentry `( state_ref::state_ref state_ref::`)] :Fentry
| [var_ref] :VarRef
def inline_block
[block_item_list] :List
def block_item_list
[block_item block_item_list] :Rec
| [] :Base
def block_item
[expr_any] :ExprAny
| [block_symbol] :BlockSymbol
| [block_interpret] :BlockInterpret
| [`{ inline_block `}] :RecBlock
def block_symbol
[`,] :B1 | [`;] :B2 | [`(] :B3 | [`)] :B4 | [`*] :B5 | [`::] :B6
def block_interpret
[expr_interpret] :ExprInterpret
| [`fhold whitespace? `;] :Fhold
| [`fgoto whitespace? `* inline_expr `;] :FgotoExpr
| [`fnext whitespace? `* inline_expr `;] :FnextExpr
| [`fcall whitespace? `* inline_expr `;] :FcallExpr
| [`fncall whitespace? `* inline_expr `;] :FncallExpr
| [`fexec inline_expr `;] :Fexec
| [`fgoto state_ref::state_ref state_ref::`;] :FgotoSr
| [`fnext state_ref::state_ref state_ref::`;] :FnextSr
| [`fcall state_ref::state_ref state_ref::`;] :FcallSr
| [`fncall state_ref::state_ref state_ref::`;] :FncallSr
| [`fret `;] :Fret
| [`fnret `;] :Fnret
| [`fbreak `;] :Fbreak
| [`fnbreak `;] :Fnbreak
end
namespace ragel namespace ragel
lex lex
literal `}%% -ni literal `}%% -ni
ignore /[\t\n ]+/ ignore /[\t\n ]+/
ignore /'#' any* :> '\n'/ ignore /'#' any* :> '\n'/
literal `^ `| `- `, `: `! `? `. literal `^ `| `- `, `: `! `? `.
literal `( `) `{ -ni ni- `} `* `& `+ literal `( `) `{ -ni ni- `} `* `& `+
skipping to change at line 173 skipping to change at line 297
literal `:= `|= `= `; `.. `../i `:: literal `:= `|= `= `; `.. `../i `::
literal `>~ `$~ `%~ `<~ `@~ `<>~ literal `>~ `$~ `%~ `<~ `@~ `<>~
literal `>* `$* `%* `<* `@* `<>* literal `>* `$* `%* `<* `@* `<>*
literal `>/ `$/ `%/ `</ `@/ `<>/ literal `>/ `$/ `%/ `</ `@/ `<>/
literal `>! `$! `%! `<! `@! `<>! literal `>! `$! `%! `<! `@! `<>!
literal `>^ `$^ `%^ `<^ `@^ `<>^ literal `>^ `$^ `%^ `<^ `@^ `<>^
literal `<> literal `<>
literal `%%--{ -ni `%%++{ -ni
token include_tok
/'include'/
{
# Take off the include token.
input->pull( match_length )
# Parse the include details, up to the the ';' an
d stop there.
parse_stop Spec: include_spec[input]
Fn: str
Machine: str
if Spec.string
Fn = $Spec.string
if Spec.word
Machine = $Spec.word
Stream: stream = ragelInclude( Fn, Machine )
if Stream {
input->push( "}--%%" )
input->push_stream( Stream )
input->push( "%%--{" )
}
}
token import_tok
/'import'/
{
# Take off the include token.
input->pull( match_length )
# Parse the import details, up to the the ';' and
stop there.
parse_stop Spec: import_spec[input]
Fn: str
if Spec.string
Fn = $Spec.string
Stream: stream = ragelImport( Fn )
if Stream {
input->push( "}++%%" )
input->push_stream( Stream )
input->push( "%%++{" )
}
}
literal `machine `action `variable `alphtype literal `machine `action `variable `alphtype
`access `write `getkey `export `import `access `write `getkey `export `prepush
`include `prepush `postpop `nfaprepush `nfapostpo `postpop `nfaprepush `nfapostpop
p
literal `:nfa `:cond `:condplus `:condstar `): literal `:nfa `:cond `:condplus `:condstar `):
token string / token string /
'"' ( [^"\\] | '\\' any )* '"' 'i'? | '"' ( [^"\\] | '\\' any )* '"' 'i'? |
"'" ( [^'\\] | '\\' any )* "'" 'i'? "'" ( [^'\\] | '\\' any )* "'" 'i'?
/ /
token lex_regex_open /'/'/ -ni token lex_regex_open /'/'/ -ni
token lex_sqopen_pos /'['/ -ni token lex_sqopen_pos /'['/ -ni
token lex_sqopen_neg /'[^'/ -ni token lex_sqopen_neg /'[^'/ -ni
token word / [a-zA-Z_][a-zA-Z0-9_]* / token word / [a-zA-Z_][a-zA-Z0-9_]* /
token uint / number / token uint / number /
token hex / hex_number / token hex / hex_number /
end end
def include_spec
[word `;]
| [string `;]
| [word string `;]
def import_spec
[string `;]
lex lex
token re_dot / '.' / token re_dot / '.' /
token re_star / '*' / token re_star / '*' /
token re_char / ^( '\\' | '.' | '*' | '[' | '/' ) | '\\' . any / token re_char / ^( '\\' | '.' | '*' | '[' | '/' ) | '\\' . any /
token re_close / '/' 'i'? / token re_close / '/' 'i'? /
token re_sqopen_pos /'['/ token re_sqopen_pos /'['/
token re_sqopen_neg /'[^'/ token re_sqopen_neg /'[^'/
end end
lex lex
skipping to change at line 258 skipping to change at line 439
GblWantSection = false GblWantSection = false
else if ( GblSearchMachine != "" ) { else if ( GblSearchMachine != "" ) {
if ( S != GblSearchMachine ) if ( S != GblSearchMachine )
GblWantSection = false GblWantSection = false
else else
GblWantSection = true GblWantSection = true
} }
else { else {
GblWantSection = true GblWantSection = true
} }
Name: str = S #$lhs.mn_word
if GblTargetMachine != ""
Name = GblTargetMachine
Machine: machine = GblMachineMap->find( Name )
if !Machine
{
Machine = new machine()
Machine->Name = Name
Machine->ActionParams = new map<str, str>()
Machine->IncludeHistory = new list<include_histor
y_item>()
GblMachineMap->insert( Machine->Name, Machine )
}
GblCurMachine = Machine
# print "want section: [GblWantSection]
} }
end end
def inline_expr_reparse def inline_expr_reparse
[_inline_expr_reparse] :Reparse [_inline_expr_reparse] :Reparse
| [action_expr] :ActionExpr | [action_expr] :ActionExpr
def join def join
[join `, expression] :Rec [join `, expression] :Rec
| [expression] :Base | [expression] :Base
skipping to change at line 332 skipping to change at line 532
[action_arg_list `, action_ref] :Rec [action_arg_list `, action_ref] :Rec
| [action_ref] :Base | [action_ref] :Base
def opt_action_arg_list def opt_action_arg_list
[action_arg_list] :List [action_arg_list] :List
| [] :Empty | [] :Empty
def named_action_ref def named_action_ref
[word] :Plain [word] :Plain
{ {
if ! GblSectionPass { if ( GblCurMachine->ActionParams->find( $lhs.word ) )
if action_params_find( GblCurMachine->Name, $lhs. reject
word )
reject
}
} }
| [word `( opt_action_arg_list `)] :Args | [word `( opt_action_arg_list `)] :Args
{ {
if ! GblSectionPass { if ( ! GblCurMachine->ActionParams->find( $lhs.word ) )
if ! action_params_find( GblCurMachine->Name, $lh reject
s.word )
reject
}
} }
def action_ref def action_ref
[named_action_ref] :NamedRef [named_action_ref] :NamedRef
| [`( named_action_ref `)] :ParenNamed | [`( named_action_ref `)] :ParenNamed
| [action_block] :Block | [action_block] :Block
def priority_name def priority_name
[word] :Word [word] :Word
skipping to change at line 544 skipping to change at line 740
def action_params def action_params
[`( opt_action_param_list `)] :List [`( opt_action_param_list `)] :List
{ {
GblActionParams = true GblActionParams = true
} }
def action_spec def action_spec
[`action word action_params action_block] :ActionSpecParams commi t [`action word action_params action_block] :ActionSpecParams commi t
{ {
if ! GblSectionPass { # Track that this action has params so we can parse appro
# Track that this action has params so we can par priately
se appropriately # when reducing.
# when reducing. GblCurMachine->ActionParams->insert( $lhs.word, $lhs.word
# CurMachine->ActionParams->insert( $lhs.word, $l )
hs.word )
action_params_insert( GblCurMachine->Name, $lhs.w
ord )
}
# Reset after parsing the block. # Reset after parsing the block.
GblActionParams = false GblActionParams = false
} }
| [`action word action_block] :ActionSpec commit | [`action word action_block] :ActionSpec commit
{ {
GblActionParams = false GblActionParams = false
} }
def def_name def def_name
skipping to change at line 592 skipping to change at line 785
def nfa_rounds def nfa_rounds
[`( nfa_round_list `)] :Rounds [`( nfa_round_list `)] :Rounds
def nfa_union def nfa_union
[def_name `|= nfa_rounds nfa_expr `;] :NfaUnion commit [def_name `|= nfa_rounds nfa_expr `;] :NfaUnion commit
def alphtype_type def alphtype_type
[W1: word] :One [W1: word] :One
| [W1: word W2: word] :Two | [W1: word W2: word] :Two
def include_spec
[word] :Machine
| [string] :File
| [word string] :MachineFile
def opt_export def opt_export
[`export] :Export [`export] :Export
| [] :Base | [] :Base
def write_arg def write_arg
[word] :Word [word] :Word
def machine_name def machine_name
[`machine mn_word `;] :MachineName [`machine mn_word `;] :MachineName
{
Name: str = $lhs.mn_word
if GblTargetMachine != ""
Name = GblTargetMachine
Machine: machine = GblMachineMap->find( Name ) def open_inc
[`%%--{] :OpenInc
if !Machine def close_inc
{ [host::close_inc] :CloseInc
Machine = new machine()
Machine->Name = Name
Machine->ActionParams = new map<str, str>()
GblMachineMap->insert( Machine->Name, Machine )
}
GblCurMachine = Machine def include_statement
} [open_inc host::section* close_inc] :IncPost commit
def open_imp
[`%%++{] :OpenImp
def close_imp
[host::close_imp] :CloseImp
def import_statement
[open_imp host::section* close_imp] :ImpPost commit
def statement def statement
[assignment] :Assignment [assignment] :Assignment
| [instantiation] :Instantiation | [instantiation] :Instantiation
| [nfa_union] :NfaUnion | [nfa_union] :NfaUnion
| [action_spec] :ActionSpec | [action_spec] :ActionSpec
| [`prepush action_block] :PrePush commit | [`prepush action_block] :PrePush commit
| [`postpop action_block] :PostPop commit | [`postpop action_block] :PostPop commit
| [`variable variable_name inline_expr_reparse] :Variable commit | [`variable variable_name inline_expr_reparse] :Variable commit
| [`alphtype alphtype_type `;] :AlphType commit | [`alphtype alphtype_type `;] :AlphType commit
| [`access inline_expr_reparse] :Access commit | [`access inline_expr_reparse] :Access commit
| [`write Cmd: word ArgList: write_arg* `;] :Write commit | [`write Cmd: word ArgList: write_arg* `;] :Write commit
| [`getkey inline_expr_reparse] :GetKey commit | [`getkey inline_expr_reparse] :GetKey commit
| [`import string `;] :Import commit | [import_statement] :Import commit
| [`include include_spec `;] :Include commit | [include_statement] :Include commit
| [`nfaprepush action_block] :NfaPrePush commit | [`nfaprepush action_block] :NfaPrePush commit
| [`nfapostpop action_block] :NfaPostPop commit | [`nfapostpop action_block] :NfaPostPop commit
def opt_machine_name def opt_machine_name
[machine_name] :MachineName [machine_name] :MachineName
| [] :Empty | [] :Empty
def ragel_start def ragel_start
[opt_machine_name ign_want statement*] [opt_machine_name ign_want statement*]
| [opt_machine_name ign_ignore consume::tok*] | [opt_machine_name ign_ignore consume::tok*]
end end
str prepareLitString( Str: str )
{
# TODO: escape sequences
return suffix( prefix( Str, Str.length - 1 ), 1 )
}
bool isAbsolutePath( Path: str )
{
# TODO: implement this
return false
}
namespace path
lex
token slash /'/'/
token chars /[^\/]+/
end
def path
[Abs: slash? DirList: dir* File: chars]
def dir
[chars slash]
dir *concat_dir( Dir1: dir*, Dir2: dir* )
{
for D: dir* in Dir1 {
if match D [] {
D = Dir2
break
}
}
return Dir1
}
end
namespace host
def section
[`%%{ ragel::opt_machine_name ragel::ign_want ragel::statement* r
agel::`}%%] :MultiLine
| [`%%{ ragel::opt_machine_name ragel::ign_ignore consume::tok* con
sume::`}%%] :Consume
| [tok] :Token
end
def start
[SectionList: host::section*]
list<str> makeIncludePathChecks( CurFileName: str, IncFileName: str )
{
new L: list<str>()
parse CurPath: path::path[ CurFileName ]
parse IncPath: path::path[ IncFileName ]
if match IncPath.Abs [slash] {
# Included file is absolute
L->push_tail( IncFileName )
}
else {
# First add the location of current file
if match CurPath.DirList []
L->push_tail( IncFileName )
else {
# Current file path + Include Path + Include File
cons NewPath: path::path [
CurPath.Abs
path::concat_dir( CurPath.DirList, IncPath.DirLis
t )
IncPath.File
]
L->push_tail( $NewPath )
}
# Next add include file locations.
for Path: str in GblIncludePaths {
parse IncPath: path::path[ CurFileName ]
L->push_tail( "[Path]/[IncFileName]" )
}
}
return L
}
stream ragelInclude( IncFileName: str, Machine: str )
{
if IncFileName
IncFileName = prepareLitString( IncFileName )
Checks: list<str>
if IncFileName
Checks = makeIncludePathChecks( GblFileName, IncFileName )
else {
Checks = new list<str>()
Checks->push_tail( GblFileName )
}
Stream: stream
OpenedName: str
for P: str in Checks {
Stream = open( P, "r" )
if Stream {
OpenedName = P
break
}
}
if !Stream {
print "error: could not open [IncFileName]
return nil
}
# Default to the current machine if none is specified.
if !Machine
Machine = GblCurMachine->Name
if isDuplicateInclude( GblCurMachine, IncFileName, Machine )
return nil
addIncludeItem( GblCurMachine, IncFileName, Machine )
saveGlobals()
GblIncludeDepth = GblIncludeDepth + 1
GblFileName = OpenedName
# Set up the search and target machine names. Search is the machine we wa
nt
# to include and target is the machine we include to.
GblSearchMachine = Machine
GblTargetMachine = GblCurMachine->Name
return Stream
}
stream ragelImport( IncFileName: str )
{
if IncFileName
IncFileName = prepareLitString( IncFileName )
Checks: list<str>
if IncFileName
Checks = makeIncludePathChecks( GblFileName, IncFileName )
else {
Checks = new list<str>()
Checks->push_tail( GblFileName )
}
Stream: stream
OpenedName: str
for P: str in Checks {
Stream = open( P, "r" )
if Stream {
OpenedName = P
break
}
}
if !Stream {
print "error: could not open [IncFileName]
return nil
}
saveGlobals()
GblFileName = OpenedName
GblImport = true
return Stream
}
 End of changes. 23 change blocks. 
56 lines changed or deleted 246 lines changed or added

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