Permalink
Browse files

Add raw string support

  • Loading branch information...
1 parent 2fcb1c2 commit a62b930d8f506a5c6fd1e063e3d24856ae475d0b Amos Wenger committed May 4, 2012
Showing with 11 additions and 0 deletions.
  1. +6 −0 grammar/nagaqueen.leg
  2. +4 −0 source/nagaqueen/OocListener.ooc
  3. +1 −0 source/nagaqueen/callbacks.ooc
@@ -243,6 +243,7 @@ void *nq_onArrayLiteralEnd(void *this);
void nq_onTupleStart(void *this);
void *nq_onTupleEnd(void *this);
+void nq_onRawStringLiteral(void *this, void *object);
void *nq_onStringLiteral(void *this, char *text);
void *nq_onCharLiteral(void *this, char *value);
@@ -1344,6 +1345,7 @@ ValueCore =
| b:BIN_LIT - { tokenPos; $$=nq_onBinLiteral(core->this, yytext); }
| f:FLOAT_LIT - { tokenPos; $$=nq_onFloatLiteral(core->this, yytext); }
| d:DEC_LIT - { tokenPos; $$=nq_onDecLiteral(core->this, yytext); }
+ | r:RAW_STRING_LIT -
| s:STRING_LIT -
| c:CHAR_LIT -
| b:BOOL_LIT - { tokenPos; $$=nq_onBoolLiteral(core->this, $$); }
@@ -1502,12 +1504,16 @@ IDENT_CORE = !(KW ![A-Za-z0-9_]) # a keyword is not an ident
SINGLE_QUOTE = '\''
DOUBLE_QUOTE = '"'
+RAW_STRING_LIT = 'c' s:STRING_LIT { nq_onRawStringLiteral(core->this, s); }
+
STRING_LIT = '"' < (!'"' ("\\" ('x'[0-9A-Za-z][0-9A-Za-z]([0-9A-Za-z][0-9A-Za-z])? | [0-9][0-9]?[0-9]? | ["'abtnvfr0\\]) | EOL | .))* >
DOUBLE_QUOTE ~{ nq_error(core->this, NQE_MALFORMED_STRINGLIT , "Malformed string literal!\n", G->pos + G->offset); }
- { tokenPos; $$=nq_onStringLiteral(core->this, yytext); }
+
CHAR_LIT = '\'' < (!'\'' ("\\" ('x'[0-9A-Za-z][0-9A-Za-z]([0-9A-Za-z][0-9A-Za-z])? | [0-9][0-9]?[0-9]? | ["'abtnvfr0\\]) | .)) >
SINGLE_QUOTE ~{ nq_error(core->this, NQE_MALFORMED_CHARLIT , "Malformed char literal!\n", G->pos + G->offset); }
- { tokenPos; $$=nq_onCharLiteral(core->this, yytext); }
+
BOOL_LIT = (TRUE_KW &[^A-Za-z_] { $$=(void*) true; } | FALSE_KW &[^A-Za-z_] { $$=(void*) false; }) -
%%
@@ -426,6 +426,10 @@ OocListener: abstract class {
/* Various expressions/statements */
+ onRawStringLiteral: func (object: Object) {
+ UnsupportedAstElement new(class, "raw string") throw(); null
+ }
+
onStringLiteral: func (text: CString) -> Object {
UnsupportedAstElement new(class, "string") throw(); null
}
@@ -190,6 +190,7 @@ nq_onTupleEnd: unmangled func (l: OocListener) -> Object { l onTupleEnd() }
/* Various expressions/statements */
+nq_onRawStringLiteral: unmangled func (l: OocListener, object: Object) { l onRawStringLiteral(object) }
nq_onStringLiteral: unmangled func (l: OocListener, text: CString) -> Object { l onStringLiteral(text) }
nq_onCharLiteral: unmangled func (l: OocListener, value: CString) -> Object { l onCharLiteral(value) }

0 comments on commit a62b930

Please sign in to comment.