mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v2: the new parser can now parse the entire V compiler
This commit is contained in:
parent
4de8d3ae8c
commit
4e9bfa95ec
@ -7,6 +7,7 @@ import (
|
||||
benchmark
|
||||
os
|
||||
os.cmdline
|
||||
compiler
|
||||
)
|
||||
|
||||
fn compile(command string, args []string) {
|
||||
|
@ -396,5 +396,10 @@ fn (cflags []CFlag) msvc_string_flags() MsvcStringFlags {
|
||||
lpaths << '/LIBPATH:"' + os.realpath(l) + '"'
|
||||
}
|
||||
return MsvcStringFlags{
|
||||
real_libs,inc_paths,lpaths,other_flags}
|
||||
real_libs:real_libs
|
||||
inc_paths:inc_paths
|
||||
lib_paths:lpaths
|
||||
other_flags:other_flags
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -90,7 +90,9 @@ struct ScanRes {
|
||||
|
||||
fn scan_res(tok TokenKind, lit string) ScanRes {
|
||||
return ScanRes{
|
||||
tok,lit}
|
||||
tok:tok
|
||||
lit:lit
|
||||
}
|
||||
}
|
||||
|
||||
fn (s mut Scanner) ident_name() string {
|
||||
@ -127,7 +129,8 @@ fn filter_num_sep(txt byteptr, start int, end int) string {
|
||||
i++
|
||||
}
|
||||
b[i1]=0 // C string compatibility
|
||||
return string{b,i1}
|
||||
return string{str:b
|
||||
len:i1}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
pub type Expr = InfixExpr | IfExpr | StringLiteral | IntegerLiteral | CharLiteral |
|
||||
FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | SelectorExpr | PostfixExpr |
|
||||
AssignExpr | PrefixExpr | MethodCallExpr | IndexExpr | RangeExpr | MatchExpr |
|
||||
CastExpr | EnumVal
|
||||
CastExpr | EnumVal | Assoc
|
||||
|
||||
pub type Stmt = VarDecl | GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
|
||||
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
|
||||
@ -447,6 +447,11 @@ pub:
|
||||
expr Expr
|
||||
}
|
||||
|
||||
pub struct Assoc {
|
||||
pub:
|
||||
name string
|
||||
}
|
||||
|
||||
// string representaiton of expr
|
||||
pub fn (x Expr) str() string {
|
||||
match x {
|
||||
|
@ -55,6 +55,7 @@ fn foo(a int) {
|
||||
number := nums[0]
|
||||
bools := [true, false]
|
||||
users := [User{}]
|
||||
//ptr := &User{}
|
||||
b := bools[0]
|
||||
mystrings := ['a', 'b']
|
||||
s := mystrings[0]
|
||||
|
@ -327,6 +327,9 @@ pub fn (p mut Parser) assign_expr(left ast.Expr) ast.AssignExpr {
|
||||
|
||||
fn (p mut Parser) attr() ast.Attr {
|
||||
p.check(.lsbr)
|
||||
if p.tok.kind == .key_if {
|
||||
p.next()
|
||||
}
|
||||
name := p.check_name()
|
||||
p.check(.rsbr)
|
||||
return ast.Attr{
|
||||
@ -515,7 +518,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
|
||||
map_type := p.parse_map_type(0)
|
||||
return node
|
||||
}
|
||||
// p.warn('name expr $p.tok.lit')
|
||||
// p.warn('name expr $p.tok.lit $p.peek_tok.str()')
|
||||
// fn call or type cast
|
||||
if p.peek_tok.kind == .lpar {
|
||||
name := p.tok.lit
|
||||
@ -546,7 +549,13 @@ pub fn (p mut Parser) name_expr() ast.Expr {
|
||||
node = x
|
||||
}
|
||||
}
|
||||
else if p.peek_tok.kind == .lcbr && (p.tok.lit[0].is_capital() || is_c || p.tok.lit in ['array', 'string', 'ustring', 'mapnode', 'map']) && !p.tok.lit[p.tok.lit.len - 1].is_capital() {
|
||||
else if p.peek_tok.kind == .lcbr && (p.tok.lit[0].is_capital() || is_c ||
|
||||
//
|
||||
p.tok.lit in ['array', 'string', 'ustring', 'mapnode', 'map']) &&
|
||||
//
|
||||
(p.tok.lit.len == 1 || !p.tok.lit[p.tok.lit.len - 1].is_capital())
|
||||
//
|
||||
{
|
||||
// || p.table.known_type(p.tok.lit)) {
|
||||
return p.struct_init()
|
||||
}
|
||||
@ -638,7 +647,7 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.check_name()
|
||||
name := p.check_name()
|
||||
p.check(.pipe)
|
||||
for {
|
||||
p.check_name()
|
||||
@ -651,6 +660,9 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
|
||||
break
|
||||
}
|
||||
}
|
||||
node = ast.Assoc{
|
||||
name: name
|
||||
}
|
||||
}
|
||||
p.check(.rcbr)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user