Giter Club home page Giter Club logo

marpax-languages-sql2003-ast's Introduction

NAME

MarpaX::Languages::SQL2003::AST - Translate SQL-2003 source to an AST

VERSION

version 0.005

SYNOPSIS

use strict;
use warnings FATAL => 'all';
use MarpaX::Languages::SQL2003::AST;
#
# Parse SQL
#
my $input = 'select * from myTable;';
my $obj = MarpaX::Languages::SQL2003::AST->new(host => 'C');
my $ast = $obj->parse($input);
my $xml = $obj->parse($input, xml => 1);

DESCRIPTION

This module translates SQL-2003 to an AST.

SUBROUTINES/METHODS

new($class, %opts)

Instantiate a new object. %opts supported keys are:

host

Target host language. Supported values are: Ada, C, Cobol, Fortran, Mumps, Pascal, PLI. Default value C.

parse($self, $input, %opts)

Parse $input and return $self. Accept an optional %opts hash whose keys can be:

xml

If $opts{xml} is a true value, produces the AST as an XML::LibXML::Document object. Default is a false value, meaning that the AST is a composite structure of blessed hash references and array references.

Any other key will be passed as-is to the Marpa's parse() method, i.e. it has to have a meaning to Marpa's recognizer. Typical examples are: trace_terminals => 1, trace_values => 1.

asXML($self, $input, %opts)

Alias to $self->parse($input, xml => 1, %opts).

Please refer to MarpaX::Languages::SQL2003::AST::Actions for the semantic actions.

asBlessed($self, $input, %opts)

Alias to $self->parse($input, xml => 0, %opts).

Please refer to MarpaX::Languages::SQL2003::AST::Actions for the semantic actions.

NOTES

This module is using a generated Marpa::R2's BNF grammar, based on a manipulation of http://savage.net.au/SQL/sql-2003-2.bnf, the later being in EBNF format. That is, some rules or lexemes in the output may appear as Genxxx or GenLexyyy, showing unfortunately some of the internals of the EBNF to BNF transformation.

SEE ALSO

MarpaX::Languages::SQL2003::AST::Actions, Marpa::R2

SUPPORT

Bugs / Feature Requests

Please report any bugs or feature requests through the issue tracker at https://rt.cpan.org/Public/Dist/Display.html?Name=MarpaX-Languages-SQL2003-AST. You will be notified automatically of any progress on your issue.

Source Code

This is open source software. The code repository is available for public review and contribution under the terms of the license.

https://github.com/jddurand/marpax-languages-sql2003-ast

git clone git://github.com/jddurand/marpax-languages-sql2003-ast.git

AUTHOR

Jean-Damien Durand <[email protected]>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Jean-Damien Durand.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

marpax-languages-sql2003-ast's People

Contributors

jddurand avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

marpax-languages-sql2003-ast's Issues

Modify grammar to ignore unknown words

I'm trying to parse the following "sql" and can't seem to get the appropriate modification to the grammar.

diggle select wee.bar as quxx from tilde

I've added an UNKNOWN_STUFF rule, and allowed it as an option in SQL_Start_Sequence but the Marpa parses diggle and select as identifiers.

<UNKNOWN_STUFF> ::= <Token>

<SQL_Start_Sequence> ::= <SQL_Start_Many> rank => 0
              | <UNKNOWN_STUFF> rank => -1

I'm getting this output from turning on tracing in Marpa:

Setting trace_terminals option
Setting trace_values option
Lexer "L0" accepted lexeme L1c1-6 e1: Identifier; value="diggle"
Lexer "L0" accepted lexeme L1c1-6 e1: Local_Or_Schema_Qualified_Name; value="diggle"
Lexer "L0" accepted lexeme L1c1-6 e1: Regular_Identifier; value="diggle"
Lexer "L0" discarded lexeme L1c7: discard
Lexer "L0" accepted lexeme L1c8-13 e2: Identifier; value="select"
Lexer "L0" discarded lexeme L1c14: discard
Parse failed.
Error in SLIF parse: No lexeme found at line 1, column 15
* String before error: diggle select\s
* The error was at line 1, column 15, and at character 0x0077 'w', ...
* here: whee.bar as quzz from pill\n
Marpa::R2 exception at /Users/srathbun/git/squealer/../MarpaX-Languages-SQL2003-AST/lib/MarpaX/Languages/SQL2003/AST.pm line 154.

F601 @1-2 L1c1-13 Correlation_Name -> Identifier .
P1297 @2-2 L1c8-13 Sample_Clause_Maybe -> . Sample_Clause
R1299:1 @0-2 L1c1-13 Table_Reference -> Table_Primary_Or_Joined_Table . Sample_Clause_Maybe
F1299 @0-2 L1c1-13 Table_Reference -> Table_Primary_Or_Joined_Table Sample_Clause_Maybe .
F1300 @0-2 L1c1-13 Table_Primary_Or_Joined_Table -> Table_Primary .
P1304 @2-2 L1c8-13 Sample_Clause -> . TABLESAMPLE Sample_Method Left_Paren Sample_Percentage Right_Paren Repeatable_Clause_Maybe
P1312 @2-2 L1c8-13 Gen1647 -> . Left_Paren Derived_Column_List Right_Paren
P1313 @2-2 L1c8-13 Gen1647_Maybe -> . Gen1647
R1315:2 @1-2 L1c1-13 Gen1650 -> As_Maybe Correlation_Name . Gen1647_Maybe
F1315 @1-2 L1c1-13 Gen1650 -> As_Maybe Correlation_Name Gen1647_Maybe .
F1316 @1-2 L1c1-13 Gen1650_Maybe -> Gen1650 .
F1336 @0-2 L1c1-13 Table_Primary -> Table_Or_Query_Name Gen1650_Maybe .
R1361:1 @0-2 L1c1-13 Cross_Join -> Table_Reference . CROSS JOIN Table_Primary
P1362 @2-2 L1c8-13 Join_Type_Maybe -> . Join_Type
R1364:1 @0-2 L1c1-13 Qualified_Join -> Table_Reference . Join_Type_Maybe JOIN Table_Reference Join_Specification
R1364:2 @0-2 L1c1-13 Qualified_Join -> Table_Reference Join_Type_Maybe . JOIN Table_Reference Join_Specification
R1365:1 @0-2 L1c1-13 Natural_Join -> Table_Reference . NATURAL Join_Type_Maybe JOIN Table_Primary
R1366:1 @0-2 L1c1-13 Union_Join -> Table_Reference . UNION JOIN Table_Primary
P1373 @2-2 L1c8-13 Join_Type -> . INNER
P1374 @2-2 L1c8-13 Join_Type -> . Outer_Join_Type Outer_Maybe
P1375 @2-2 L1c8-13 Outer_Join_Type -> . LEFT
P1376 @2-2 L1c8-13 Outer_Join_Type -> . RIGHT
P1377 @2-2 L1c8-13 Outer_Join_Type -> . FULL

Terminals expected: TABLESAMPLE CROSS FULL INNER JOIN LEFT NATURAL RIGHT UNION Left_Paren

I've tried adjusting the rank of my new rule, but it does not seem to help. The string still gets evaluated the same way. Am I missing something obvious?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.