From ffdf5112bc6bc908dc0790e7c5d5aa4787a21988 Mon Sep 17 00:00:00 2001 From: "benoit.thomas" Date: Tue, 20 Jul 2021 00:29:17 +0900 Subject: [PATCH] added class with the array of bit --- parse.leg | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/parse.leg b/parse.leg index 2ba6838..28a2ee0 100644 --- a/parse.leg +++ b/parse.leg @@ -7,6 +7,7 @@ #include #include "inputBuffer.c" +#include "class.c" ; void fatal(char *fmt, ...) @@ -38,7 +39,7 @@ struct Star { enum op type; Node *children[1]; }; struct Plus { enum op type; Node *children[1]; }; struct Or { enum op type; Node *children[2]; }; struct And { enum op type; Node *children[2]; }; -struct Class { enum op type; char *stringValue; int len; }; +struct Class { enum op type; char *array; }; struct Dot { enum op type; }; struct Exc { enum op type; Node *children[1]; }; struct Et { enum op type; Node *children[1]; }; @@ -140,8 +141,7 @@ Node *mkStar(Node *n) Node *mkClass(char* str) { Node *node= new(Class); - node->Class.stringValue= str; - node->Class.len=strlen(str); + node->Class.array= str; return node; } @@ -211,7 +211,7 @@ void print(Node *node) return; case Class: printf("Class"); - printf("\"%s\"", node->Class.stringValue); + printf("\"%s\"", node->Class.array); return; case Dot: printf("Dot"); @@ -317,7 +317,7 @@ id = < [a-zA-z_][a-zA-z_0-9]* > - { $$ = mkId(intern(yytext)) } string = '"' < [^\"]* > '"' - { $$ = mkString(yytext) } -class = '['-<(!']'string)*> ']' - { $$=mkClass(yytext) } +class = '['-<(!']'string)*> ']' - { $$=mkClass(classify(yytext)) } dot = '.' - { $$=mkDot() } @@ -367,11 +367,8 @@ int execute(Node *node, InputBuffer *in) return 1; } case Class: { - if (!currentChar(in)) { - return 0; - } - if (strchr(get(node,Class,stringValue), currentChar(in))) { - advance(in, 1); + if (testBit(get(Node,Class,array),currentChar(in))) { + advance(in, 1); return 1; } return 0;