summaryrefslogtreecommitdiff
path: root/test/trans.d/ragel-c.lm
diff options
context:
space:
mode:
Diffstat (limited to 'test/trans.d/ragel-c.lm')
-rw-r--r--test/trans.d/ragel-c.lm175
1 files changed, 175 insertions, 0 deletions
diff --git a/test/trans.d/ragel-c.lm b/test/trans.d/ragel-c.lm
new file mode 100644
index 00000000..ccc2dc93
--- /dev/null
+++ b/test/trans.d/ragel-c.lm
@@ -0,0 +1,175 @@
+namespace c_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 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
+
+ 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 | [`::] :DoubleColon
+
+ def expr_interpret
+ [`fpc] :Fpc
+ | [`fc] :Fc
+ | [`fcurs] :Fcurs
+ | [`ftargs] :Ftargs
+ | [`fentry `( state_ref srlex::`)] :Fentry
+ | [var_ref] :VarRef
+
+ def state_ref
+ [opt_name_sep state_ref_names] :Ref
+
+ def opt_name_sep
+ [srlex::`::] :ColonColon
+ | [] :Empty
+
+ # List of names separated by ::
+ def state_ref_names
+ [state_ref_names srlex::`:: srlex::word] :Rec
+ | [srlex::word] :Base
+
+ 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 srlex::`;] :FgotoSr
+ | [`fnext state_ref srlex::`;] :FnextSr
+ | [`fcall state_ref srlex::`;] :FcallSr
+ | [`fncall state_ref srlex::`;] :FncallSr
+ | [`fret `;] :Fret
+ | [`fnret `;] :Fnret
+ | [`fbreak `;] :Fbreak
+ | [`fnbreak `;] :Fnbreak
+end
+
+
+namespace c_host
+ lex
+ literal `%%{
+
+ 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))* '"' /
+
+ 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
+ [ident] :Ident
+ | [number] :Number
+ | [hex_number] :HexNumber
+ | [comment] :Comment
+ | [string] :String
+ | [whitespace] :Whitespace
+ | [c_any] :Any
+
+ def section
+ [`%%{ ragel::ragel_start ragel::`}%%] :MultiLine
+ | [tok] :Tok
+end
+
+