summaryrefslogtreecommitdiff
path: root/src/lib/syntax.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/syntax.c')
-rw-r--r--src/lib/syntax.c48
1 files changed, 40 insertions, 8 deletions
diff --git a/src/lib/syntax.c b/src/lib/syntax.c
index c3452f2..f930973 100644
--- a/src/lib/syntax.c
+++ b/src/lib/syntax.c
@@ -59,6 +59,11 @@ single_sym(struct scan_state *state, struct token *token)
switch(peek(state)){
case 0x2190: token->tag = TOKEN_TAG_LEFT_ARROW; break;
case 0x22C4: token->tag = TOKEN_TAG_DIAMOND; break;
+ case 0x2207: token->tag = TOKEN_TAG_DEL; break;
+ case 0x2336: token->tag = TOKEN_TAG_IBEAM; break;
+ case '\n': token->tag = TOKEN_TAG_NEWLINE; break;
+ case '(': token->tag = TOKEN_TAG_LEFT_PAREN; break;
+ case ')': token->tag = TOKEN_TAG_RIGHT_PAREN; break;
default:
return 0;
}
@@ -83,6 +88,21 @@ identifier(struct scan_state *state, struct token *token)
return 1;
}
+static int
+keyword(struct scan_state *state, struct token *token)
+{
+ uint32_t c;
+ if(peek(state) != ':')
+ return 0;
+
+ do
+ c = advance(state);
+ while(is_letter(c));
+
+ token->tag = TOKEN_TAG_KEYWORD;
+ return 1;
+}
+
static int
number(struct scan_state *state, struct token *token)
{
@@ -125,14 +145,25 @@ number(struct scan_state *state, struct token *token)
return 1;
}
-static int
-newline(struct scan_state *state, struct token *token)
+static int
+text(struct scan_state *state, struct token *token)
{
- if(peek(state) != '\n')
+ uint32_t c;
+
+ c = peek(state);
+ if(c != '\'')
return 0;
- advance(state);
- token->tag = TOKEN_TAG_NEWLINE;
+ do
+ c = advance(state);
+ while((c != '\n') && (c != 0) && (c != '\''));
+
+ if(c == '\'')
+ advance(state);
+ else
+ return 0;
+
+ token->tag = TOKEN_TAG_TEXT;
return 1;
}
@@ -143,8 +174,9 @@ next_token(struct scan_state *state, struct token *token)
int (*scans[])(struct scan_state *, struct token *token) = {
single_sym,
identifier,
+ keyword,
number,
- newline
+ text,
};
skip_space(state);
@@ -198,7 +230,7 @@ scan(struct string *text, struct token_list *tokens)
}
struct token_list *
-scan_line(struct aplwc *aplwc, struct string *text)
+scan_string(struct aplwc *aplwc, struct string *text, int oneline)
{
enum aplwc_rc rc;
struct token_list *tokens;
@@ -218,7 +250,7 @@ scan_line(struct aplwc *aplwc, struct string *text)
tokens->length = n;
scan(text, tokens);
- for(i = 0; i < n; i++){
+ for(i = 0; oneline && (i < n); i++){
if(tokens->tokens[i].tag != TOKEN_TAG_NEWLINE)
continue;