summaryrefslogtreecommitdiff
path: root/ragel/host-crack/rlparse.lm
diff options
context:
space:
mode:
Diffstat (limited to 'ragel/host-crack/rlparse.lm')
-rw-r--r--ragel/host-crack/rlparse.lm202
1 files changed, 202 insertions, 0 deletions
diff --git a/ragel/host-crack/rlparse.lm b/ragel/host-crack/rlparse.lm
new file mode 100644
index 00000000..db7851c7
--- /dev/null
+++ b/ragel/host-crack/rlparse.lm
@@ -0,0 +1,202 @@
+include 'ragel.lm'
+include 'rlreduce.lm'
+
+namespace inline
+ lex
+ literal `fpc `fc `fcurs `ftargs
+ `fentry `fhold `fexec `fgoto `fnext
+ `fcall `fret `fbreak `fncall `fnret `fnbreak
+
+ token ident /ident/
+ token number /digit+/
+ token hex_number /'0x' [0-9a-fA-F]+/
+ token dec_number /'0x' [0-9a-fA-F]+/
+
+ token comment
+ / c_comment | cpp_comment /
+
+ token string
+ / s_literal | d_literal /
+
+ token whitespace
+ / ( [ \t] | NL )+ /
+
+ literal
+ `{ `} `:: `* `, `( `) `;
+
+ token var_ref
+ / "$" [a-zA-Z_][a-zA-Z_0-9]* /
+ {
+ if GblActionParams
+ {
+ input->push( make_token(
+ typeid<var_ref>, input->pull( match_length ) ) )
+ }
+ else
+ {
+ # Just pull one char. Don't consume the word because it may
+ # be a keyword.
+ input->push( make_token(
+ typeid<c_any>, input->pull( 1 ) ) )
+ }
+ }
+
+ token c_any
+ / any /
+ end
+
+end
+
+namespace host
+ lex
+ literal `%%{
+
+ token close_inc /'}--%%'/
+ {
+ input->push( make_token( typeid<close_inc>, input->pull( match_length ) ) )
+ restoreGlobals()
+ }
+
+ token close_imp /'}++%%'/
+ {
+ input->push( make_token( typeid<close_imp>, input->pull( match_length ) ) )
+ restoreGlobals()
+ }
+
+ token slr / '%%' [^{] [^\n]* '\n' /
+ {
+ # Translates single line to multi-line
+ input->pull( 2 )
+ R: str = input->pull( match_length - 3 )
+ input->push( "\n}%%" )
+ input->push( R )
+ input->push( "%%{" )
+ }
+
+ rl NL / '\n' /
+
+ rl s_literal
+ / "'" ([^'\\\n] | '\\' (any | NL))* "'" /
+
+ rl d_literal
+ / '"' ([^"\\] | NL | '\\' (any | NL))* '"' /
+
+ literal `define `=
+
+ token ident /ident "'"?/
+ token number /digit+/
+ token hex_number /'0x' [0-9a-fA-F]+/
+
+ token comment
+ / c_comment | cpp_comment /
+
+ token string
+ / s_literal | d_literal /
+
+ token whitespace
+ / ( [ \t] | NL )+ /
+
+ token c_any / any /
+ end
+
+ def tok
+ [`define whitespace ident whitespace? number] :ImportDefNum
+ | [`define whitespace ident whitespace? string] :ImportDefStr
+ | [ident whitespace? `= whitespace? number] :ImportAssignNum
+ | [ident whitespace? `= whitespace? string] :ImportAssignStr
+ | [`define] :Def
+ | [`=] :Eq
+ | [ident] :Ident
+ | [number] :Number
+ | [hex_number] :HexNumber
+ | [comment] :Comment
+ | [string] :String
+ | [whitespace] :Whitespace
+ | [c_any] :Any
+end
+
+reduction TopLevel
+
+ # Pass Through.
+ # def tok
+ # [`define ident number] :Def1
+ # | [`define ident string] :Def2
+ # | [ident `= number] :Ass1
+ # | [ident `= string] :Ass2
+ # [`define whitespace ident whitespace? number] :ImportDefNum
+ # | [`define whitespace ident whitespace? string] :ImportDefStr
+ # | [ident whitespace? `= whitespace? number] :ImportAssignNum
+ # | [ident whitespace? `= whitespace? string] :ImportAssignStr
+ # | [`define] :Def
+ # | [`=] :Eq
+ # | [ident] :Ident
+ # | [number] :Number
+ # | [hex_number] :HexNumber
+ # | [comment] :Comment
+ # | [string] :String
+ # | [whitespace] :Whitespace
+ # | [c_any] :Any
+
+ host::tok :ImportDefNum
+ {
+ if ( isImport )
+ {
+ Literal *lit = new Literal( @number,
+ false /* $number->neg */, $number->data,
+ $number->length, Literal::Number );
+
+ string name( $ident->data, $ident->length );
+ import( @ident, name, lit );
+ }
+ }
+ host::tok :ImportDefStr
+ {
+ if ( isImport )
+ {
+ Literal *lit = new Literal( @string, false,
+ $string->data, $string->length, Literal::LitString );
+ string name( $ident->data, $ident->length );
+ import( @ident, name, lit );
+ }
+ }
+ host::tok :ImportAssignNum
+ {
+ if ( isImport )
+ {
+ Literal *lit = new Literal( @number,
+ false /*$number->neg */, $number->data,
+ $number->length, Literal::Number );
+ string name( $ident->data, $ident->length );
+ import( @ident, name, lit );
+ }
+ }
+ host::tok :ImportAssignStr
+ {
+ if ( isImport )
+ {
+ Literal *lit = new Literal( @string, false,
+ $string->data, $string->length, Literal::LitString );
+
+ string name( $ident->data, $ident->length );
+ import( @ident, name, lit );
+ }
+ }
+
+end
+
+export RagelError: str
+
+# File name. The open is expected to succeed. It is tested before the colm
+# program is called.
+A: list_el<str> = argv->pop_head_el()
+GblFileName = A->value
+
+# Remaining items are include paths.
+while ( argv->length > 0 ) {
+ A = argv->pop_head_el()
+ GblIncludePaths->push_tail_el( A )
+}
+
+Stream: stream = open( GblFileName, "r" )
+reduce TopLevel start[ Stream ]
+RagelError = error