Commit eba85acc authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Replace generated Vala scanner and parser by handwritten classes

2008-04-13  Juerg Billeter  <j@bitron.ch>

	* vala/Makefile.am, vala/valaassignment.vala,
	  vala/valabinaryexpression.vala, vala/valaclass.vala,
	  vala/valanamespace.vala, vala/valaparser.vala,
	  vala/valascanner.vala, vala/valascope.vala,
	  vala/valasourcefile.vala, vala/valasourcelocation.vala,
	  vala/valatokentype.vala, vala/valatuple.vala,
	  vala/valaunaryexpression.vala, vala/valaunresolvedtype.vala:

	  Replace generated Vala scanner and parser by handwritten classes

svn path=/trunk/; revision=1194
parent 20423931
2008-04-13 Jürg Billeter <j@bitron.ch>
* vala/Makefile.am, vala/valaassignment.vala,
vala/valabinaryexpression.vala, vala/valaclass.vala,
vala/valanamespace.vala, vala/valaparser.vala,
vala/valascanner.vala, vala/valascope.vala,
vala/valasourcefile.vala, vala/valasourcelocation.vala,
vala/valatokentype.vala, vala/valatuple.vala,
vala/valaunaryexpression.vala, vala/valaunresolvedtype.vala:
Replace generated Vala scanner and parser by handwritten classes
2008-04-13 Jürg Billeter <j@bitron.ch>
* vapi/glib-2.0.vapi: add GEnumClass and GEnumValue bindings
......
......@@ -7,8 +7,7 @@ AM_CPPFLAGS = \
-DPACKAGE_DATADIR=\"$(pkgdatadir)\" \
$(NULL)
BUILT_SOURCES = parser.h vala.vala.stamp
AM_YFLAGS = -d
BUILT_SOURCES = vala.vala.stamp
noinst_LTLIBRARIES = \
libvalacore.la
......@@ -106,6 +105,7 @@ libvalacore_la_VALASOURCES = \
valareferencetype.vala \
valareport.vala \
valareturnstatement.vala \
valascanner.vala \
valascope.vala \
valasemanticanalyzer.vala \
valasignal.vala \
......@@ -113,6 +113,7 @@ libvalacore_la_VALASOURCES = \
valasizeofexpression.vala \
valasourcefile.vala \
valasourcefilecycle.vala \
valasourcelocation.vala \
valasourcereference.vala \
valastatement.vala \
valastringliteral.vala \
......@@ -123,7 +124,9 @@ libvalacore_la_VALASOURCES = \
valasymbol.vala \
valasymbolresolver.vala \
valathrowstatement.vala \
valatokentype.vala \
valatrystatement.vala \
valatuple.vala \
valatypecheck.vala \
valatypeofexpression.vala \
valatypeparameter.vala \
......@@ -139,8 +142,6 @@ libvalacore_la_VALASOURCES = \
$(NULL)
libvalacore_la_SOURCES = \
parser.y \
scanner.l \
vala.h \
vala.vala.stamp \
$(libvalacore_la_VALASOURCES:.vala=.c) \
......
This diff is collapsed.
/* scanner.l
*
* Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Jürg Billeter <j@bitron.ch>
* Raffaele Sandrini <rasa@gmx.ch>
*/
%{
#include "vala.h"
#include "parser.h"
#define YY_DECL int yylex (YYSTYPE *yylval_param, YYLTYPE *yylloc_param, ValaParser *parser)
#define uploc { yylloc->first_column = yylloc->last_column + 1; yylloc->last_column += yyleng; }
static gboolean file_comment = FALSE;
%}
%option yylineno
%option bison-bridge
%option bison-locations
%option noyywrap
%option nounput
%x IN_COMMENT
space [ \t\n]*
ident [[:alnum:]_]+
decimal_integer_literal (0|[1-9][[:digit:]]*)
real_literal [[:digit:]]+"."[[:digit:]]*{exponent_part}?{real_suffix}?
hex_digit [[:digit:]A-Fa-f]
octal_digit [0-7]
octal_integer_literal 0{octal_digit}+
hexadecimal_integer_literal 0x{hex_digit}+
exponent_part (e|E){sign}?[[:digit:]]+
sign "+"|"-"
integer_suffix L|LL|U|UL|ULL
real_suffix F
single_character [^\'\\]
single_string_literal_character [^\"\\]
simple_escape_sequence \\[\'\"\?\\abfnrtv0]
hexadecimal_escape_sequence \\x{hex_digit}{hex_digit}?{hex_digit}?{hex_digit}?
character ({single_character}|{simple_escape_sequence})
string_literal_character ({single_string_literal_character}|{simple_escape_sequence})
character_literal \'{character}+\'
string_literal \"{string_literal_character}*\"
integer_literal ({decimal_integer_literal}|{hexadecimal_integer_literal}|{octal_integer_literal}){integer_suffix}?
literal ({integer_literal}|{real_literal}|{character_literal}|{string_literal})
type_name ("weak"{space})?({ident}".")?{ident}
generic_type {type_name}("<"{space}{type_name}("?"|"*"+)?(","{space}{type_name}("?"|"*"+)?)*">")?("?"|"*"+)?
%%
"/*" { uploc; file_comment = (yylineno == 1); BEGIN (IN_COMMENT); }
<IN_COMMENT>"*/" { uploc; BEGIN (INITIAL); yytext[yyleng - 2] = '\0'; vala_parser_push_comment (parser, yytext, file_comment); }
<IN_COMMENT>[^*\n]+ { uploc; yymore (); }
<IN_COMMENT>"*" { uploc; yymore (); }
<IN_COMMENT>\n { yylloc->first_line = yylloc->last_line = yylineno; yylloc->first_column = 1; yylloc->last_column = 0; yymore (); }
"//".* { uploc; vala_parser_push_comment (parser, g_strdup (yytext + 2), FALSE); }
"{" { uploc; return OPEN_BRACE; }
"}" { uploc; return CLOSE_BRACE; }
"("({space}"weak")?{space}{ident}("."{ident})?("<"({ident}".")?{ident}(","({ident}".")?{ident})*">")?("["{space}"]")*{space}")"{space}("("|{ident}|{literal}) { yyless (1); uploc; return OPEN_CAST_PARENS; }
"(" { uploc; return OPEN_PARENS; }
")" { uploc; return CLOSE_PARENS; }
"["{space}(","{space})*"]" { yyless (1); uploc; return OPEN_ARRAY_TYPE_BRACKET; }
"[" { uploc; return OPEN_BRACKET; }
"]" { uploc; return CLOSE_BRACKET; }
"..." { uploc; return ELLIPSIS; }
"." { uploc; return DOT; }
":" { uploc; return COLON; }
"," { uploc; return COMMA; }
";" { uploc; return SEMICOLON; }
"#" { uploc; return HASH; }
"?"{space}({ident}{space}("="|";")|"[") { yyless (1); uploc; return NULLABLE_INTERR; }
"?" { uploc; return INTERR; }
"|=" { uploc; return ASSIGN_BITWISE_OR; }
"&=" { uploc; return ASSIGN_BITWISE_AND; }
"^=" { uploc; return ASSIGN_BITWISE_XOR; }
"+=" { uploc; return ASSIGN_ADD; }
"-=" { uploc; return ASSIGN_SUB; }
"*=" { uploc; return ASSIGN_MUL; }
"/=" { uploc; return ASSIGN_DIV; }
"%=" { uploc; return ASSIGN_PERCENT; }
"<<=" { uploc; return ASSIGN_SHIFT_LEFT; }
">>=" { uploc; return ASSIGN_SHIFT_RIGHT; }
"++" { uploc; return OP_INC; }
"--" { uploc; return OP_DEC; }
"==" { uploc; return OP_EQ; }
"!=" { uploc; return OP_NE; }
"<<" { uploc; return OP_SHIFT_LEFT; }
">>" { uploc; return OP_SHIFT_RIGHT; }
"<=" { uploc; return OP_LE; }
">=" { uploc; return OP_GE; }
"=>" { uploc; return LAMBDA; }
"<"{space}{generic_type}{space}(","{space}{generic_type}{space})*">" { yyless (1); uploc; return GENERIC_LT; }
"<" { uploc; return OP_LT; }
">" { uploc; return OP_GT; }
"!" { uploc; return OP_NEG; }
"||" { uploc; return OP_OR; }
"|" { uploc; return BITWISE_OR; }
"&&" { uploc; return OP_AND; }
"&" { uploc; return BITWISE_AND; }
"^" { uploc; return CARRET; }
"~" { uploc; return TILDE; }
"->" { uploc; return OP_PTR; }
"=" { uploc; return ASSIGN; }
"+" { uploc; return PLUS; }
"-" { uploc; return MINUS; }
"*" { uploc; return STAR; }
"/" { uploc; return DIV; }
"%" { uploc; return PERCENT; }
"@"[[:alnum:]_]+ { uploc; yylval->str = g_strdup (yytext + 1); return IDENTIFIER; }
"abstract" { uploc; return ABSTRACT; }
"as" { uploc; return AS; }
"base" { uploc; return BASE; }
"break" { uploc; return BREAK; }
"case" { uploc; return CASE; }
"catch" { uploc; return CATCH; }
"class" { uploc; return CLASS; }
"const" { uploc; return CONST; }
"construct" { uploc; return CONSTRUCT; }
"continue" { uploc; return CONTINUE; }
"default" { uploc; return DEFAULT; }
"delegate" { uploc; return DELEGATE; }
"delete" { uploc; return DELETE; }
"do" { uploc; return DO; }
"else" { uploc; return ELSE; }
"ensures" { uploc; return ENSURES; }
"enum" { uploc; return ENUM; }
"errordomain" { uploc; return ERRORDOMAIN; }
"false" { uploc; return VALA_FALSE; }
"finally" { uploc; return FINALLY; }
"for" { uploc; return FOR; }
"foreach" { uploc; return FOREACH; }
"get" { uploc; return GET; }
"if" { uploc; return IF; }
"in" { uploc; return IN; }
"inline" { uploc; return INLINE; }
"interface" { uploc; return INTERFACE; }
"is" { uploc; return IS; }
"lock" { uploc; return LOCK; }
"namespace" { uploc; return NAMESPACE; }
"new" { uploc; return NEW; }
"null" { uploc; return VALA_NULL; }
"out" { uploc; return OUT; }
"override" { uploc; return OVERRIDE; }
"private" { uploc; return PRIVATE; }
"protected" { uploc; return PROTECTED; }
"public" { uploc; return PUBLIC; }
"ref" { uploc; return REF; }
"requires" { uploc; return REQUIRES; }
"set" { uploc; return SET; }
"signal" { uploc; return SIGNAL; }
"sizeof" { uploc; return SIZEOF; }
"static" { uploc; return STATIC; }
"struct" { uploc; return STRUCT; }
"switch" { uploc; return SWITCH; }
"return" { uploc; return RETURN; }
"this" { uploc; return THIS; }
"throw" { uploc; return THROW; }
"throws" { uploc; return THROWS; }
"true" { uploc; return VALA_TRUE; }
"try" { uploc; return TRY; }
"typeof" { uploc; return TYPEOF; }
"using" { uploc; return USING; }
"var" { uploc; return VAR; }
"virtual" { uploc; return VIRTUAL; }
"void" { uploc; return VOID; }
"volatile" { uploc; return VOLATILE; }
"weak" { uploc; return WEAK; }
"while" { uploc; return WHILE; }
{real_literal} { uploc; yylval->str = g_strdup (yytext); return REAL_LITERAL; }
{integer_literal} { uploc; yylval->str = g_strdup (yytext); return INTEGER_LITERAL; }
{character_literal} { uploc; yylval->str = g_strdup (yytext); return CHARACTER_LITERAL; }
{string_literal} { uploc; yylval->str = g_strdup (yytext); return STRING_LITERAL; }
{ident} { uploc; yylval->str = g_strdup (yytext); return IDENTIFIER; }
[ \t\r]+ { uploc; /* eat up whitespace */ }
[\n]+ { yylloc->first_line = yylloc->last_line = yylineno; yylloc->first_column = 1; yylloc->last_column = 0; }
. { uploc; fprintf (stderr, "%d: syntax error: unexpected character ´%s´\n", yylloc->first_line, yytext); }
......@@ -94,6 +94,7 @@ public class Vala.Assignment : Expression {
}
public enum Vala.AssignmentOperator {
NONE,
SIMPLE,
BITWISE_OR,
BITWISE_AND,
......
......@@ -130,6 +130,7 @@ public class Vala.BinaryExpression : Expression {
}
public enum Vala.BinaryOperator {
NONE,
PLUS,
MINUS,
MUL,
......
......@@ -193,10 +193,16 @@ public class Vala.Class : Typesymbol {
*/
public void add_method (Method! m) {
if (m.instance || m is CreationMethod) {
if (m.this_parameter != null) {
m.scope.remove (m.this_parameter.name);
}
m.this_parameter = new FormalParameter ("this", new ClassType (this));
m.scope.add (m.this_parameter.name, m.this_parameter);
}
if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
if (m.result_var != null) {
m.scope.remove (m.result_var.name);
}
m.result_var = new VariableDeclarator ("result");
m.result_var.type_reference = m.return_type.copy ();
m.scope.add (m.result_var.name, m.result_var);
......
......@@ -166,6 +166,60 @@ public class Vala.Namespace : Symbol {
return new ReadOnlyCollection<Interface> (interfaces);
}
/**
* Returns a copy of the list of enums.
*
* @return enum list
*/
public Collection<Enum> get_enums () {
return new ReadOnlyCollection<Enum> (enums);
}
/**
* Returns a copy of the list of error domains.
*
* @return error domain list
*/
public Collection<ErrorDomain> get_error_domains () {
return new ReadOnlyCollection<ErrorDomain> (error_domains);
}
/**
* Returns a copy of the list of fields.
*
* @return field list
*/
public Collection<Field> get_fields () {
return new ReadOnlyCollection<Field> (fields);
}
/**
* Returns a copy of the list of constants.
*
* @return constant list
*/
public Collection<Constant> get_constants () {
return new ReadOnlyCollection<Constant> (constants);
}
/**
* Returns a copy of the list of delegates.
*
* @return delegate list
*/
public Collection<Delegate> get_delegates () {
return new ReadOnlyCollection<Delegate> (delegates);
}
/**
* Returns a copy of the list of methods.
*
* @return method list
*/
public Collection<Method> get_methods () {
return new ReadOnlyCollection<Method> (methods);
}
/**
* Adds the specified constant to this namespace.
*
......
This diff is collapsed.
This diff is collapsed.
......@@ -60,7 +60,7 @@ public class Vala.Scope : Object {
symbol_table = new HashMap<string,Symbol> (str_hash, str_equal);
} else if (lookup (name) != null) {
owner.error = true;
Report.error (owner.source_reference, "`%s' already contains a definition for `%s'".printf (owner.get_full_name (), name));
Report.error (sym.source_reference, "`%s' already contains a definition for `%s'".printf (owner.get_full_name (), name));
return;
}
......@@ -68,7 +68,11 @@ public class Vala.Scope : Object {
}
sym.owner = this;
}
public void remove (string name) {
symbol_table.remove (name);
}
/**
* Returns the symbol stored in the symbol table with the specified
* name.
......
......@@ -87,6 +87,8 @@ public class Vala.SourceFile : Object {
private Gee.ArrayList<string> source_array = null;
private MappedFile mapped_file = null;
/**
* Creates a new source file.
*
......@@ -124,6 +126,10 @@ public class Vala.SourceFile : Object {
nodes.add (node);
}
public void remove_node (CodeNode! node) {
nodes.remove (node);
}
/**
* Returns a copy of the list of code nodes.
*
......@@ -396,6 +402,17 @@ public class Vala.SourceFile : Object {
}
}
public char* get_mapped_contents () {
if (mapped_file == null) {
mapped_file = new MappedFile (filename, false);
}
return mapped_file.get_contents ();
}
public size_t get_mapped_length () {
return mapped_file.get_length ();
}
}
public enum Vala.SourceFileDependencyType {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -103,6 +103,7 @@ public class Vala.UnaryExpression : Expression {
}
public enum Vala.UnaryOperator {
NONE,
PLUS,
MINUS,
LOGICAL_NEGATION,
......
......@@ -122,4 +122,8 @@ public class Vala.UnresolvedType : DataType {
return result;
}
public override string to_string () {
return unresolved_symbol.to_string ();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment